id
stringlengths
10
13
content
stringlengths
424
1.17M
app_data_2600
You are given a matrix with $n$ rows (numbered from $1$ to $n$) and $m$ columns (numbered from $1$ to $m$). A number $a_{i, j}$ is written in the cell belonging to the $i$-th row and the $j$-th column, each number is either $0$ or $1$. A chip is initially in the cell $(1, 1)$, and it will be moved to the cell $(n, m)$...
app_data_2601
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got ...
app_data_2602
Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has $a$ vanilla cookies and $b$ chocolate cookies for the party. She invited $n$ guests of the first type and $m$ guests of the second type to the party. They will come...
app_data_2603
You are given an array $a_1, a_2, \dots, a_n$ where all $a_i$ are integers and greater than $0$. In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$). If $gcd(a_i, a_j)$ is equal to the minimum element of the whole array $a$, you can swap $a_i$ and $a_j$. $gcd(x, y)$ denotes the gre...
app_data_2604
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust. The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, an...
app_data_2605
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: XXX consists of n cities, k of whose (just imagine!) are capital cities. All of cities in the cou...
app_data_2606
Chef Monocarp has just put $n$ dishes into an oven. He knows that the $i$-th dish has its optimal cooking time equal to $t_i$ minutes. At any positive integer minute $T$ Monocarp can put no more than one dish out of the oven. If the $i$-th dish is put out at some minute $T$, then its unpleasant value is $|T - t_i|$ — ...
app_data_2607
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not. Ahcl wants to construct a beautiful string. He has a string $s$, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each...
app_data_2608
Recently, Masha was presented with a chessboard with a height of $n$ and a width of $m$. The rows on the chessboard are numbered from $1$ to $n$ from bottom to top. The columns are numbered from $1$ to $m$ from left to right. Therefore, each cell can be specified with the coordinates $(x,y)$, where $x$ is the column n...
app_data_2609
There are $n$ segments on a $Ox$ axis $[l_1, r_1]$, $[l_2, r_2]$, ..., $[l_n, r_n]$. Segment $[l, r]$ covers all points from $l$ to $r$ inclusive, so all $x$ such that $l \le x \le r$. Segments can be placed arbitrarily  — be inside each other, coincide and so on. Segments can degenerate into points, that is $l_i=r_i$...
app_data_2610
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$. Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ...
app_data_2611
Vova decided to clean his room. The room can be represented as the coordinate axis $OX$. There are $n$ piles of trash in the room, coordinate of the $i$-th pile is the integer $p_i$. All piles have different coordinates. Let's define a total cleanup as the following process. The goal of this process is to collect all ...
app_data_2612
There are $n$ models in the shop numbered from $1$ to $n$, with sizes $s_1, s_2, \ldots, s_n$. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices $i_...
app_data_2613
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x...
app_data_2614
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling. Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat t...
app_data_2615
Consider some positive integer $x$. Its prime factorization will be of form $x = 2^{k_1} \cdot 3^{k_2} \cdot 5^{k_3} \cdot \dots$ Let's call $x$ elegant if the greatest common divisor of the sequence $k_1, k_2, \dots$ is equal to $1$. For example, numbers $5 = 5^1$, $12 = 2^2 \cdot 3$, $72 = 2^3 \cdot 3^2$ are elegant...
app_data_2616
There are $n$ piles of stones, where the $i$-th pile has $a_i$ stones. Two people play a game, where they take alternating turns removing stones. In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first player who...
app_data_2617
Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria. Initially, on day $1$, there is one bacterium with mass $1$. Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass $m$ splits, it becomes two bacteria of mass $\frac{m}{2}$ each. F...
app_data_2618
You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something! You have $n$ tickets to sell. The price of the $i$-th ticket is $p_i$. As a teller, you have a possibility to select the order in which the tickets will be sold (i.e. a permutatio...
app_data_2619
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (x_{i}, y_{i}), a maximum brightness c, equal for all stars, and an initial brightness s_{i} (0 ≤ s_{i} ≤ c). Over time the stars twinkle. At moment 0 the i-th star has brightness s_{i}. Let at moment t some star has...
app_data_2620
A permutation is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ — are permutations, and $[1, 1]$, $[4, 3, 1]$, $[2, 3, 4]$ — no. Permutation $a$ is lexicographically smaller than permutation $b$ (they have the same length $n$...
app_data_2621
Gildong is playing a video game called Block Adventure. In Block Adventure, there are $n$ columns of blocks in a row, and the columns are numbered from $1$ to $n$. All blocks have equal heights. The height of the $i$-th column is represented as $h_i$, which is the number of blocks stacked in the $i$-th column. Gildong...
app_data_2622
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so...
app_data_2623
Phoenix has a string $s$ consisting of lowercase Latin letters. He wants to distribute all the letters of his string into $k$ non-empty strings $a_1, a_2, \dots, a_k$ such that every letter of $s$ goes to exactly one of the strings $a_i$. The strings $a_i$ do not need to be substrings of $s$. Phoenix can distribute let...
app_data_2624
You are given an array of $n$ integers $a_1, a_2, \ldots, a_n$. You will perform $q$ operations. In the $i$-th operation, you have a symbol $s_i$ which is either "<" or ">" and a number $x_i$. You make a new array $b$ such that $b_j = -a_j$ if $a_j s_i x_i$ and $b_j = a_j$ otherwise (i.e. if $s_i$ is '>', then all $a...
app_data_2625
Today at the lesson of mathematics, Petya learns about the digital root. The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-d...
app_data_2626
You have integer $n$. Calculate how many ways are there to fully cover belt-like area of $4n-2$ triangles with diamond shapes. Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it. $2$ coverings are different if some $2$ triangles are covered by the same diamond s...
app_data_2627
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"] ] Output: 6 class Solution: def maximalRectangle(self, matrix): """...
app_data_2628
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input: 2 Output: [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
app_data_2629
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: Input: 3 Output: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] class Solution: def generateMatrix(self, n): """ :type n: int :rtype: List[List[int]] """ i...
app_data_2630
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). Now consider if some obstacles are added to the g...
app_data_2631
There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all course...
app_data_2632
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. Example: Input: [   [1,3,1], [1,5,1], [4,2,1] ] Output: 7 Explanation: Because the path 1→3→1→1...
app_data_2633
table.dungeon, .dungeon th, .dungeon td { border:3px solid black; } .dungeon th, .dungeon td { text-align: center; height: 70px; width: 70px; } The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid....
app_data_2634
Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Example: Input: nums = [1,2,3] Output: [ [3],   [1],   [2],   [1,2,3],   [1,3],   [2,3],   [1,2],   [] ] class Solution: def subsets(self, nums): """ ...
app_data_2635
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,5] Example 2: Input: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,12] ] Output: [1,2,3,4,8,12,11,10,9,5,6,7] class Solut...
app_data_2636
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline formed by these buildings collectively (Fi...
app_data_2637
Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: Input: [1,1,2] Output: [ [1,1,2], [1,2,1], [2,1,1] ] class Solution: def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ...
app_data_2638
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11). Note: Bonus point if yo...
app_data_2639
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Example: Input: [1,2,2] Output: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] class Solution: def subsetsWithDup(self, nums): ...
app_data_2640
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares. Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and ...
app_data_2641
We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i. You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have? -----Constraints----- - 1\leq N,Q \leq 5 \times 10^5 - 1\leq c_i \leq ...
app_data_2642
We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time. The i-th and j-th sardines (i \neq j) are on bad terms if and onl...
app_data_2643
We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: - The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\text...
app_data_2644
We have a permutation P = P_1, P_2, \ldots, P_N of 1, 2, \ldots, N. You have to do the following N - 1 operations on P, each exactly once, in some order: - Swap P_1 and P_2. - Swap P_2 and P_3. \vdots - Swap P_{N-1} and P_N. Your task is to sort P in ascending order by configuring the order of operations. If it is i...
app_data_2645
AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the p...
app_data_2646
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the ...
app_data_2647
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repe...
app_data_2648
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of ...
app_data_2649
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points? Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y...
app_data_2650
There are N infants registered in AtCoder, numbered 1 to N, and 2\times 10^5 kindergartens, numbered 1 to 2\times 10^5. Infant i has a rating of A_i and initially belongs to Kindergarten B_i. From now on, Q transfers will happen. After the j-th transfer, Infant C_j will belong to Kindergarten D_j. Here, we define the e...
app_data_2651
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i. For every...
app_data_2652
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads...
app_data_2653
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: - Operation j...
app_data_2654
There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i. Find the number of different values that the median of X_1, X_2, \cdots, X_N can take. -----Notes----- The median of X_1, X_2, \cdots, X_N is defined as follows. Let x_1, x_2, \cdots, x_N be the result of sorting X_1, X_2, \cdots, X_N ...
app_data_2655
Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i. The N players will arrive at the place one by one in some order. To mak...
app_data_2656
How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7). -----Constraints----- - K is an integer between 1 and 10^6 (inclusive). - S is a string of length...
app_data_2657
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted. -----Constraints-...
app_data_2658
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K t...
app_data_2659
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. -----Constraints----- - ...
app_data_2660
There is a function f(x), which is initially a constant function f(x) = 0. We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows: - An update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x). - ...
app_data_2661
Given are an integer N and arrays S, T, U, and V, each of length N. Construct an N×N matrix a that satisfy the following conditions: - a_{i,j} is an integer. - 0 \leq a_{i,j} \lt 2^{64}. - If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}. - If S_{i} = 1, the bitwise OR of the elements in the ...
app_data_2662
You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied: - If A_i and A_j (i < j) are painted with the same color, A_i < A_j. Find the minimum number of colors r...
app_data_2663
Chef likes arrays a lot. Today, he found an array A consisting of N positive integers. Let L denote the sorted (in non-increasing order) list of size N*(N+1)/2 containing the sums of all possible contiguous subarrays of A. Chef is interested in finding the first K elements from the list L. Can you help him in accomplis...
app_data_2664
Chef has bought ten balls of five colours. There are two balls of each colour. Balls of same colour have same weight. Let us enumerate colours by numbers from 1 to 5. Chef knows that all balls, except two (of same colour), weigh exactly one kilogram. He also knows that each of these two balls is exactly 1 kg heavier th...
app_data_2665
Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resulting set. Note that the square created need not to be parallel to the axis....
app_data_2666
Ramu was a lazy farmer. He had inherited a fairly large farm and a nice house from his father. Ramu leased out the farm land to others and earned a rather handsome income. His father used to keep a buffalo at home and sell its milk but the buffalo died a few days after his father did. Ramu too wanted to make some money...
app_data_2667
Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of Stamp Collecting Сommunity(SCC). SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC. Mike told them that all stamps of the members could be divided in...
app_data_2668
Today, Chef woke up to find that he had no clean socks. Doing laundry is such a turn-off for Chef, that in such a situation, he always buys new socks instead of cleaning the old dirty ones. He arrived at the fashion store with money rupees in his pocket and started looking for socks. Everything looked good, but then Ch...
app_data_2669
The lockdown hasn’t been great for our chef as his restaurant business got sabotaged because of lockdown, nevertheless no worries our chef is a multi-talented guy. Chef has decided to be a freelancer and work remotely. According to chef’s maths, he should be able to work on maximum tasks assuming that he can only work ...
app_data_2670
A pair of strings $(α, β)$ is called a subpair of a string $x$ if $x$ = $x_1+$$α+$$x_2+$$β+$$x_3$ (where a+b means concatenation of strings a and b) for some (possibly empty) strings $x1, x2$ and $x3$. We are given two strings and we need to find one subpair from each string such that : Let $(a,b) , (c,d) $be subpair ...
app_data_2671
Andy got a box of candies for Christmas. In fact, he discovered that the box contained several identical smaller boxes, and they could contain even smaller boxes, and so on. Formally, we say that candies are boxes of level 0, and for 1 ≤ i ≤ n, a level i box contains ai boxes of level i - 1. The largest box has level n...
app_data_2672
Guys don’t misinterpret this it is three only. -----Input:----- - First line will contain an integer $X$. -----Output:----- A single line containing the answer to the problem modulo 1000000007. -----Constraints----- - $1 \leq X < 10^5$ -----Sample Input 1:----- 1 -----Sample Output 1:----- 3 -----Sample Input 2:-...
app_data_2673
Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has a sequence of digits $S_{1}, S_{2}, \ldots , S_{N}$. He is staying in the first digit $S_{1}$ and wants to reach the last digit $S_{N}$ in the minimal number of jumps. While staying in some index $i$ Chef can jump into $i - 1$ a...
app_data_2674
Is the MRP of my new shoes exclusive or inclusive of taxes? -----Input:----- - First line will contain an integer $P$ -----Output:----- For each testcase, print either 'Inclusive' or 'Exclusive' without quotes. -----Constraints----- - $100 \leq P \leq 999$ -----Sample Input 1:----- 123 -----Sample Output 1:----- E...
app_data_2675
There are $n$ red balls kept on the positive $X$ axis, and $m$ blue balls kept on the positive $Y$ axis. You are given the positions of the balls. For each $i$ from $1$ to $n$, the $i$-th red ball has the coordinates $(x_i, 0)$, where $x_i$ is a positive integer. For each $i$ from $1$ to $m$, the $i$-th blue ball has t...
app_data_2676
Teddy and Freddy are two friends. Teddy has a pile of strings of size $N$. Each string $Si$ in the pile has length less or equal to $100$ ($len(Si) \leq 100$). Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$. Teddy and Freddy like playing with strings. Teddy gives Freddy a strin...
app_data_2677
$Alien$ likes to give challenges to $Codezen$ team to check their implementation ability, this time he has given a string $S$ and asked to find out whether the given string is a $GOOD$ string or not. According to the challenge $GOOD$ String is a string that has at least $3$ consecutive vowels and at least $5$ different...
app_data_2678
Zonal Computing Olympiad 2015, 29 Nov 2014 An interval is a pair of positive integers [a, b] with a ≤ b. It is meant to denote the set of integers that lie between the values a and b. For example [3,5] denotes the set {3,4,5} while the interval [3, 3] denotes the set {3}. We say that an interval [a, b] is covered by ...
app_data_2679
It is the last day of covid and you are coming back to your home with two empty sacks. On the way to your home, you found Ambani brothers donating all their wealth in form of coins after getting fed up with all the money they have. The coins have both positive and negative values and they are laid down in a line. Now a...
app_data_2680
Little Rohu from Pluto is the best bomb defusor on the entire planet. She has saved the planet from getting destruced multiple times now. Of course, she's proud of her achievments. But, to prepare herself for more complicated situations, she keeps challenging herself to handle tricky tasks. Her current challenge involv...
app_data_2681
Write a program to obtain 2 numbers $($ $A$ $and$ $B$ $)$ and an arithmetic operator $(C)$ and then design a $calculator$ depending upon the operator entered by the user. So for example if C="+", you have to sum the two numbers. If C="-", you have to subtract the two numbers. If C=" * ", you have to print the product. ...
app_data_2682
Mathison has bought a new deck of cards that contains 2N cards, numbered and ordered from 0 to 2N-1. Mathison is getting bored and decides to learn the Dynamo shuffle (or Sybil cut) - a flashy manner to shuffle cards. Unfortunately, the Dynamo shuffle is a little too complicated so Mathison decides to create his own sh...
app_data_2683
Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being similar to the original Tic-Tac-Toe, other than the fact that it is played on an NxN board. The game is played between two players taking turns. First p...
app_data_2684
As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma. We consider any sequence consisting of the letters of the English alphabet to be a word. So axxb,abbba and bbbccddx are words for our purpose. And aaabbaaa, abbba and bbb are examples of pa...
app_data_2685
You are given a string S of numbers. Dr. Dragoon has eaten up some numbers of the string. You decide to fix the string by putting the numbers 0 and 1 in the empty spaces. The base cost for putting the ‘0’ is x and putting ‘1’ is y . The cost of putting a number is the base cost multiplied by the number of times yo...
app_data_2686
Heroes in Indian movies are capable of superhuman feats. For example, they can jump between buildings, jump onto and from running trains, catch bullets with their hands and teeth and so on. A perceptive follower of such movies would have noticed that there are limits to what even the superheroes can do. For example, if...
app_data_2687
Knights' tournaments were quite popular in the Middle Ages. A lot of boys were dreaming of becoming a knight, while a lot of girls were dreaming of marrying a knight on a white horse. In this problem we consider one of these tournaments. Let's us call a tournament binary, if it runs according to the scheme described...
app_data_2688
We consider permutations of the numbers $1,..., N$ for some $N$. By permutation we mean a rearrangment of the number $1,...,N$. For example 24517638245176382 \quad 4 \quad 5 \quad 1 \quad 7 \quad 6 \quad 3 \quad 8 is a permutation of $1,2,...,8$. Of course, 12345678123456781 \quad 2 \quad 3 \quad 4 \quad 5 \quad 6 \qua...
app_data_2689
$Riggi$ is a spy of $KBI$ and he is on a secret mission, he is spying an Underworld Don $Anit$. $Riggi$ is spying him since 5 years and he is not able to find any evidence against $Anit$. $KBI$ told $Riggi$ they will send him a code string in a special format that will inform him whether he has continue or retur...
app_data_2690
Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i and j i.e abs(i-j) . Since Alisha is busy with her Semester exams help her fi...
app_data_2691
Tim buy a string of length N from his friend which consist of ‘d’ and ‘u’ letters only ,but now Tim wants to sell the string at maximum cost. The maximum cost of string is defined as the maximum length of a Substring (consecutive subsequence) consisting of equal letters. Tim can change at most P characters of strin...
app_data_2692
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
app_data_2693
This is a rather simple problem to describe. You will be given three numbers $S, P$ and $k$. Your task is to find if there are integers $n_1, n_2,...,n_k$ such that $n_1 + n_2 +...+ n_k = S$, $n_1 \cdot n_2 \cdot ... \cdot n_k = P$. If such integers exist, print them out. If no such sequence of integers exist, then pri...
app_data_2694
Zonal Computing Olympiad 2013, 10 Nov 2012 Spaceman Spiff has crash landed on Planet Quorg. He has to reach his ship quickly. But the evil Yukbarfs have stolen many Death Ray Blasters and have placed them along the way. You'll have to help him out! Spaceman Spiff is initially at the top left corner (1,1) of a rectang...
app_data_2695
Gotham City is again under attack. This time Joker has given an open challenge to solve the following problem in order to save Gotham. Help Batman in protecting Gotham by solving the problem. You are given two strings A and B composed of lowercase letters of Latin alphabet. B can be obtained by removing some characters...
app_data_2696
Every year the professor selects the top two students from his class and takes them on a fun filled field trip, this year Ali and Zafar were selected. The professor took them to a place where there was a never-ending queue of solid metal cubes. The professor could see $n$ cubes at a time. On the day before, he had pain...
app_data_2697
A greek once sifted some numbers. And it did something wonderful! -----Input:----- - First line will contain an integer $N$ -----Output:----- Output in a single line answer to the problem. -----Constraints----- - $1 \leq N \leq 10^5$ -----Sample Input 1:----- 10 -----Sample Output 1:----- 4 -----Sample Input 2:--...
app_data_2698
Chef loves cooking. Also, he is very hygienic. Hence, Chef grows his own vegetables in his mini kitchen garden. He has $M$ lanes in which he grows vegetables. The $ith$ lane has $Ai$ vegetables growing in it. Vegetables in $ith$ lane become edible on day $Di$ and day $Di+1$(that is, the vegetables are edible only on ...
app_data_2699
Rashmi loves the festival of Diwali as she gets to spend time with family and enjoy the festival. Before she can fully enjoy the festival she needs to complete the homework assigned by her teacher. Since Rashmi is smart , she has solved all the problems but is struck at one tricky pattern question. Your Task is to help...