question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square...
Solve the programming task below in a Python markdown code block. You are given a sequence of length N: A_1, A_2, ..., A_N. For each integer i between 1 and N (inclusive), answer the following question: - Find the maximum value among the N-1 elements other than A_i in the sequence. -----Constraints----- - 2 \leq N ...
Solve the programming task below in a Python markdown code block. We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this: 1 2 3 4 5 6 7 8 9 . . . N N . . . 9 8 7 6 5 4 3 2 1 Two numbers faced each other form a pair. Your task is to compute the number of pairs P ...
Solve the programming task below in a Python markdown code block. Given is a string S representing the day of the week today. S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively. After how many days is the next Sunday (tomorrow or later)? ---...
Solve the programming task below in a Python markdown code block. Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N? -----Constraints----- - 2 \leq N \leq 10^6 - All values in input are integers. -----Input----- Input is given from Standard Input in the followi...
Solve the programming task below in a Python markdown code block. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on ...
Solve the programming task below in a Python markdown code block. Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good ...
Solve the programming task below in a Python markdown code block. ## Nova polynomial add This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff300114...
Solve the programming task below in a Python markdown code block. Given are positive integers A and B. Let us choose some number of positive common divisors of A and B. Here, any two of the chosen divisors must be coprime. At most, how many divisors can we choose?Definition of common divisor An integer d is said to be...
Solve the programming task below in a Python markdown code block. Your program fails again. This time it gets "Wrong answer on test 233". This is the easier version of the problem. In this version $1 \le n \le 2000$. You can hack this problem only if you solve and lock both problems. The problem is about a test cont...
Solve the programming task below in a Python markdown code block. problem A mysterious $ X $ [cm] plant grows in one place. This plant has the following mysterious properties. * Say "nobiro" to this plant and it will grow $ A $ [cm]. * Say "tidime" to this plant and it will grow $ B $ [cm]. * If you say "karero" to ...
Solve the programming task below in a Python markdown code block. Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the followin...
Solve the programming task below in a Python markdown code block. There are $b$ boys and $g$ girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and $n$ participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Orga...
Solve the programming task below in a Python markdown code block. Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it ...
Solve the programming task below in a Python markdown code block. problem Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions. Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $. Example Input 8 5 2 4 9 4 ...
Solve the programming task below in a Python markdown code block. Takahashi is doing a research on sets of points in a plane. Takahashi thinks a set S of points in a coordinate plane is a good set when S satisfies both of the following conditions: * The distance between any two points in S is not \sqrt{D_1}. * The di...
Solve the programming task below in a Python markdown code block. Write ```python word_pattern(pattern, string) ``` that given a ```pattern``` and a string ```str```, find if ```str``` follows the same sequence as ```pattern```. For example: ```python word_pattern('abab', 'truck car truck car') == True word_pattern(...
Solve the programming task below in a Python markdown code block. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transf...
Solve the programming task below in a Python markdown code block. Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his c...
Solve the programming task below in a Python markdown code block. 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 se...
Solve the programming task below in a Python markdown code block. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the lef...
Solve the programming task below in a Python markdown code block. Monocarp has got an array $a$ consisting of $n$ integers. Let's denote $k$ as the mathematic mean of these elements (note that it's possible that $k$ is not an integer). The mathematic mean of an array of $n$ elements is the sum of elements divided by ...
Solve the programming task below in a Python markdown code block. There are $n$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $s$, where the $i$-th candle is lit if and only if $s_i=1$. Initially, the candle lights are described by...
Solve the programming task below in a Python markdown code block. You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$. The following actions are allowed: Token movement. To move the token from vertex $u$ to vertex $v$ if there is an edg...
Solve the programming task below in a Python markdown code block. Relative B came to Mr. A's house. He is 3 years old and loves blocks. The block he has is shaped like Figure 1. <image> Figure 1 Mr. B is laying blocks on the board. When I asked him, "What are you making?", He replied cheerfully, "Maze !!". The maze...
Solve the programming task below in a Python markdown code block. There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula. BMI = weight (kg) / (height (m)) 2 The closer the BMI value is to the standard value, the more "ideal body shape" is con...
Solve the programming task below in a Python markdown code block. In Aramic language words can only represent objects. Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $x$ of a word ...
Solve the programming task below in a Python markdown code block. In this Kata, you will be given an array of numbers and a number `n`, and your task will be to determine if `any` array elements, when summed (or taken individually), are divisible by `n`. For example: * `solve([1,3,4,7,6],9) == true`, because `3 +...
Solve the programming task below in a Python markdown code block. International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source form. Sources contain comments, extra whitespace (including trailing and ...
Solve the programming task below in a Python markdown code block. n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 Is called the factorial of n. For example, the factorial of 12 12! = 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 479001600 And there are two consecutive 0s at the end. Write a program that inputs t...
Solve the programming task below in a Python markdown code block. The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smalles...
Solve the programming task below in a Python markdown code block. You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must ...
Solve the programming task below in a Python markdown code block. Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spect...
Solve the programming task below in a Python markdown code block. A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly $1$ meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four directio...
Solve the programming task below in a Python markdown code block. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2^{n} members and coincidentally Natalia Fan Club also has 2^{n} members. Each member of MDC is ...
Solve the programming task below in a Python markdown code block. Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on th...
Solve the programming task below in a Python markdown code block. Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game. There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges ...
Solve the programming task below in a Python markdown code block. We have N non-negative integers: A_1, A_2, ..., A_N. Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue. Let the beauty of the painting be the \mbox{XOR} of the integers painted in red, plus the \mbo...
Solve the programming task below in a Python markdown code block. Create a function which checks a number for three different properties. - is the number prime? - is the number even? - is the number a multiple of 10? Each should return either true or false, which should be given as an array. Remark: The Haskell vari...
Solve the programming task below in a Python markdown code block. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next...
Solve the programming task below in a Python markdown code block. Note that girls in Arpa’s land are really attractive. Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th ch...
Solve the programming task below in a Python markdown code block. For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ ...
Solve the programming task below in a Python markdown code block. Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a sys...
Solve the programming task below in a Python markdown code block. You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (x_{i}, y_{i}). We know that no two bombs are at the same point and that no bomb is at point ...
Solve the programming task below in a Python markdown code block. Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test ...
Solve the programming task below in a Python markdown code block. Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment...
Solve the programming task below in a Python markdown code block. The hero of justice, the Spider, can pull a rope out of his arm and jump from building to building. However, due to the short rope, you can only move to buildings that are less than 50 distances from you. To move to a building farther away, you have to ...
Solve the programming task below in a Python markdown code block. < PREVIOUS KATA NEXT KATA > ## Task: You have to write a function `pattern` which returns the following Pattern(See Examples) upto desired number of rows. * Note:```Returning``` the pattern is not the same as ```Printing``` the pattern. ### Paramet...
Solve the programming task below in a Python markdown code block. You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the...
Solve the programming task below in a Python markdown code block. You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 th...
Solve the programming task below in a Python markdown code block. Let's say take 2 strings, A and B, and define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings `abc` and `abd` is 2, while the similarity of strings `aaa` and `aaab` is 3...
Solve the programming task below in a Python markdown code block. We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, an...
Solve the programming task below in a Python markdown code block. You have a simple undirected graph consisting of $n$ vertices and $m$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected. Let's make a definition. Let $v_1$ and $v_2$ ...
Solve the programming task below in a Python markdown code block. A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs...
Solve the programming task below in a Python markdown code block. One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get som...
Solve the programming task below in a Python markdown code block. The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts $h$ hours and each hour lasts $m$ minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number o...
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to determi...
Solve the programming task below in a Python markdown code block. There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on tram...
Solve the programming task below in a Python markdown code block. Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective is to d...
Solve the programming task below in a Python markdown code block. The trafic on the Internet is increasing these days due to smartphones. The wireless carriers have to enhance their network infrastructure. The network of a wireless carrier consists of a number of base stations and lines. Each line connects two base s...
Solve the programming task below in a Python markdown code block. Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height a_{i} off the ground. Besides, let the sequence a_{i} increase, that is, a_{i} < a_{i} + 1 for all i from 1 to n - 1; we will call such sequence ...
Solve the programming task below in a Python markdown code block. Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment l_{i} and ends at moment r_{i}. Polycarp owns two TVs. He can watch two different shows si...
Solve the programming task below in a Python markdown code block. You gave the twins Ai and Zu a program of games using strings. In this game, Ai and Zu each select a substring from the character string, compare them, and the person who chooses the smaller one will get points. The two competed and played the game many...
Solve the programming task below in a Python markdown code block. Let's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string. You have $a$ strings "a", $b$ string...
Solve the programming task below in a Python markdown code block. Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensi...
Solve the programming task below in a Python markdown code block. The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this purpose i...
Solve the programming task below in a Python markdown code block. # A History Lesson Soundex is an interesting phonetic algorithm developed nearly 100 years ago for indexing names as they are pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite...
Solve the programming task below in a Python markdown code block. # Task Call two arms equally strong if the heaviest weights they each are able to lift are equal. Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weake...
Solve the programming task below in a Python markdown code block. Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node. Before beginning the game, a special ...
Solve the programming task below in a Python markdown code block. 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 ca...
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Sereja is playing a game called Winner Eats Sandwich with his friends. There are N persons in total, including Sereja. Sereja is allotted the number 1, while his friends are allotted numbers fr...
Solve the programming task below in a Python markdown code block. There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a Teleporter, a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town...
Solve the programming task below in a Python markdown code block. Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking phot...
Solve the programming task below in a Python markdown code block. One day in the IT lesson Anna and Maria learned about the lexicographic order. String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ ...
Solve the programming task below in a Python markdown code block. A conglomerate consists of $n$ companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and contin...
Solve the programming task below in a Python markdown code block. Bob is a theoretical coder - he doesn't write code, but comes up with theories, formulas and algorithm ideas. You are his secretary, and he has tasked you with writing the code for his newest project - a method for making the short form of a word. Write...
Solve the programming task below in a Python markdown code block. Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane. You can use the following theorem: Theorem: an N-sided polygon satisfying the condition can be drawn if and only if...
Solve the programming task below in a Python markdown code block. ###BACKGROUND: Jacob recently decided to get healthy and lose some weight. He did a lot of reading and research and after focusing on steady exercise and a healthy diet for several months, was able to shed over 50 pounds! Now he wants to share his succe...
Solve the programming task below in a Python markdown code block. We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter. Snuke is creating another H-by-W matrix, A', by freely rearranging the elements i...
Solve the programming task below in a Python markdown code block. Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respecti...
Solve the programming task below in a Python markdown code block. ## Problem Determine whether a positive integer number is **colorful** or not. `263` is a colorful number because `[2, 6, 3, 2*6, 6*3, 2*6*3]` are all different; whereas `236` is not colorful, because `[2, 3, 6, 2*3, 3*6, 2*3*6]` have `6` twice. So t...
Solve the programming task below in a Python markdown code block. Problem statement Given the string $ S $. Find the number of all anagrams in $ S $ that are palindromic. An anagram of the string $ X $ is an anagram of $ Y $, which means that $ X $ is equal to $ Y $, or that the rearranged characters of $ X $ are eq...
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries: - Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and endin...
Solve the programming task below in a Python markdown code block. Let $n$ be an integer. Consider all permutations on integers $1$ to $n$ in lexicographic order, and concatenate them into one big sequence $p$. For example, if $n = 3$, then $p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]$. The length of thi...
Solve the programming task below in a Python markdown code block. A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tuto...
Solve the programming task below in a Python markdown code block. You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to ...
Solve the programming task below in a Python markdown code block. Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefor...
Solve the programming task below in a Python markdown code block. You are wandering in the explorer space of the 2050 Conference. The explorer space can be viewed as an undirected weighted grid graph with size n× m. The set of vertices is \{(i, j)|1≤ i≤ n, 1≤ j≤ m\}. Two vertices (i_1,j_1) and (i_2, j_2) are connecte...
Solve the programming task below in a Python markdown code block. Hint In solving this problem, the following may be referred to. Shows how to convert an integer value to a string. Assign value as a string to str. For C include <stdio.h> int main () { int value = 123; // Convert this value to a string char str [6...
Solve the programming task below in a Python markdown code block. Given are a permutation p_1, p_2, \dots, p_N of (1, 2, ..., N) and an integer K. Maroon performs the following operation for i = 1, 2, \dots, N - K + 1 in this order: * Shuffle p_i, p_{i + 1}, \dots, p_{i + K - 1} uniformly randomly. Find the expect...
Solve the programming task below in a Python markdown code block. Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago. You are given a connected undirected graph with $n$ vertices and $m$ weighted edges. There are $k$ special vertices: $x_1, x_2, \ldots, x_k$. Le...
Solve the programming task below in a Python markdown code block. A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them: All o...
Solve the programming task below in a Python markdown code block. Mr. Suzuki has opened a new mobile sales shop for freshly squeezed milk in the Aizu area. It is assumed that all the customers who come to buy that day are already in the store with bottles to take home and will not increase any more. Customers only ord...
Solve the programming task below in a Python markdown code block. For a rooted tree, find the lowest common ancestor of two nodes u and v. The given tree consists of n nodes and every node has a unique ID from 0 to n-1 where 0 is the root. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 100000 Input n k0 c1 c2 ... ck0 k1...
Solve the programming task below in a Python markdown code block. You are given a string S consisting of 0 and 1. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times. - Choose a contiguous segment [l,r] in S who...
Solve the programming task below in a Python markdown code block. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from a_{i} to b_{i}. Of course, Famil Door wants to have as many friends celeb...
Solve the programming task below in a Python markdown code block. Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he c...
Solve the programming task below in a Python markdown code block. When Masha came to math classes today, she saw two integer sequences of length $n - 1$ on the blackboard. Let's denote the elements of the first sequence as $a_i$ ($0 \le a_i \le 3$), and the elements of the second sequence as $b_i$ ($0 \le b_i \le 3$)....
Solve the programming task below in a Python markdown code block. Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowerca...
Solve the programming task below in a Python markdown code block. Once upon a time Mike and Mike decided to come up with an outstanding problem for some stage of ROI (rare olympiad in informatics). One of them came up with a problem prototype but another stole the idea and proposed that problem for another stage of th...