info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"12\\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086\", \"3\\n1 2 5\", \"12\\n161735902 394362112 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086\", \"3\\n1 3 5\", \"1...
There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equ...
0
{"tests": "{\"inputs\": [\"7 16\\n1 15\\n1000 0\\n...*...*........\\n.*.*.*.*.******.\\n.*.*.*.*.*....*.\\n.*.*.*.*.*....*.\\n.*...*...*....*.\\n.**************.\\n................\\n\", \"1 1\\n1 1\\n0 0\\n.\\n\", \"10 15\\n7 7\\n7 7\\n.*****..*******\\n**...*.********\\n**.*..........*\\n...**********.*\\n.**********...
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not o...
0.375
{"tests": "{\"inputs\": [\"5\\n1 2 3 4\\n5 -1 5 -1 7\\n\", \"25\\n1 2 1 4 4 4 1 2 8 5 1 8 1 6 9 6 10 10 7 10 8 17 14 6\\n846 -1 941 -1 1126 1803 988 -1 1352 1235 -1 -1 864 -1 -1 -1 -1 -1 -1 -1 -1 1508 1802 1713 -1\\n\", \"10\\n1 1 1 1 2 3 4 5 1\\n3 -1 -1 -1 -1 3 3 3 3 -1\\n\", \"10\\n1 1 2 4 4 5 6 3 3\\n0 -1 -1 0 -1 -1...
Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vert...
0
{"tests": "{\"inputs\": [\"33 57\\n\", \"99 55\\n\", \"37 19\\n\", \"31 32\\n\", \"99 20\\n\", \"37 39\\n\", \"7 10\\n\", \"57 15\\n\", \"99 177\\n\", \"99 193\\n\", \"19 12\\n\", \"13 21\\n\", \"57 67\\n\", \"23 39\\n\", \"97 100\\n\", \"99 99\\n\", \"69 17\\n\", \"55 55\\n\", \"39 73\\n\", \"7 7\\n\", \"9 5\\n\", \"9...
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon p...
0
{"tests": "{\"inputs\": [[\"Fox\", \"x\"], [\"Rhino\", \"o\"], [\"Meerkat\", \"t\"], [\"Emu\", \"t\"], [\"Badger\", \"s\"], [\"Giraffe\", \"d\"]], \"outputs\": [[true], [true], [true], [false], [false], [false]]}", "source": "taco"}
Some new animals have arrived at the zoo. The zoo keeper is concerned that perhaps the animals do not have the right tails. To help her, you must correct the broken function to make sure that the second argument (tail), is the same as the last letter of the first argument (body) - otherwise the tail wouldn't fit! If t...
0.875
{"tests": "{\"inputs\": [\"3 5 2\\n3 2 3 4\\n.....\\n.@..@\\n..@..\\n\", \"1 6 4\\n1 1 1 6\\n......\\n\", \"3 3 1\\n2 1 2 3\\n.@.\\n.@.\\n.@.\\n\", \"2 3 1\\n2 1 2 3\\n.@.\\n.@.\\n.@.\", \"3 5 2\\n3 2 3 4\\n.....\\n.@-.@\\n..@..\", \"1 6 4\\n1 1 1 1\\n......\", \"3 5 4\\n3 2 3 4\\n.....\\n.@..@\\n..@..\", \"1 6 4\\n1 2...
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west. Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it...
0.75
{"tests": "{\"inputs\": [\"2 2\\n1\\n1\\n2\\n\", \"7 4\\n1 1 3 3 5 3\\n2\\n2\\n3\\n5\\n\", \"7 4\\n1 1 3 3 5 3\\n2\\n4\\n3\\n5\\n\", \"7 4\\n1 1 3 3 5 3\\n2\\n3\\n3\\n5\\n\", \"7 4\\n1 1 3 3 5 3\\n2\\n4\\n3\\n3\\n\", \"7 4\\n1 1 3 3 5 6\\n2\\n4\\n3\\n5\\n\", \"7 4\\n1 1 3 3 5 3\\n2\\n5\\n3\\n3\\n\", \"7 4\\n1 1 3 3 5 3...
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of n nodes. The root of tree has index 1. Kay is very interested ...
0
{"tests": "{\"inputs\": [\"11 11 5\\n\", \"11 2 3\\n\", \"1 5 9\\n\", \"2 3 3\\n\", \"1 1000000000 1000000000\\n\", \"2 3 5\\n\", \"1000000000 1000000000 1000000000\\n\", \"1 0 1\\n\", \"101 99 97\\n\", \"1000000000 0 1\\n\", \"137 137 136\\n\", \"255 255 255\\n\", \"1 0 1000000000\\n\", \"123 456 789\\n\", \"666666 66...
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins. Across all the sets Misha scored a points ...
0
{"tests": "{\"inputs\": [\"2 1\\n2\\n1\\n\", \"10 2\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n4\\n1\\n9\\n\", \"10 5\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n18\\n\", \"10 5\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n13\\n\", \"2 2\\n2\\n1\\n\", \"10 8\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n9\\n\", \"10 2\\n2\\n7\\n3\\n9\\n13\\n7\\n9\\n4\\...
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to predict the stock price of a company over the next n days and wants to design a...
0
{"tests": "{\"inputs\": [\"4\\n1 2 2 4\\n\", \"3\\n2 3 3\\n\", \"3\\n2 3 1\\n\", \"1\\n1\\n\", \"16\\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10\\n\", \"20\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\\n\", \"20\\n11 14 2 10 17 5 9 6 18 3 17 7 4 15 17 1 4 14 10 11\\n\", \"100\\n46 7 63 48 75 82 85 90 65 23 36 96 96...
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function $g : \{1,2, \ldots, n \} \rightarrow \{1,2, \ldots, n \}$, that for any $x \in \{1,2, \ldots, n \}$ the formula g(g(x)) = g(x) holds. Let's denote as f^{(}k)(x) the function f applied k time...
0
{"tests": "{\"inputs\": [\"4\\n 0 2 2 2\\n 2 0 2 2\\n 2 2 0 2\\n 2 2 2 0\\n4\\n 0 2 4 4\\n 2 0 4 4\\n 4 4 0 2\\n 4 4 2 1\\n2\\n 0 12\\n 12 0\\n0\", \"4\\n 0 2 2 2\\n 2 0 2 2\\n 2 2 -1 2\\n 2 2 2 0\\n4\\n 0 2 4 4\\n 2 0 4 4\\n 4 4 0 2\\n 4 ...
Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illustrate how computers and switches are connected. Since he is a programmer, he is very reluctant to move throughout the office and examine c...
0
{"tests": "{\"inputs\": [\"1 1\\nq\\n\", \"1 500\\nwljexjwjwsxhascgpyezfotqyieywzyzpnjzxqebroginhlpsvtbgmbckgqixkdveraxlgleieeagubywaacncxoouibbhwyxhjiczlymscsqlttecvundzjqtuizqwsjalmizgeekugacatlwhiiyaamjuiafmyzxadbxsgwhfawotawfxkpyzyoceiqfppituvaqmgfjinulkbkgpnibaefqaqiptctoqhcnnfihmzijnwpxdikwefpxicbspdkppznpiqrpkyv...
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following restrictions are set: * In each row at most two different colours can be used. * No two adjacent squares can be painted the same c...
0
{"tests": "{\"inputs\": [\"zyxxxxxxyyz\\n5\\n5 5\\n1 3\\n1 11\\n1 4\\n3 6\\n\", \"yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\\n10\\n17 67\\n6 35\\n12 45\\n56 56\\n14 30\\n25 54\\n1 1\\n46 54\\n3 33\\n19 40\\n\", \"xxxxyyxyyzzyxyxzxyzyxzyyyzyzzxxxxzyyzzzzyxxxxzzyzzyzx\\n5\\n4 4\\n3 3\\n1 24\\n3...
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q_1q_2... q_{k}. The algorithm consists of two steps: Find any continuous subsequence (substring) of three characters of string q, which do...
0
{"tests": "{\"inputs\": [\"3 3 10\\n60 2 2 4\\n70 8 7 9\\n50 2 3 9\\n\", \"3 3 10\\n100 3 1 4\\n100 1 5 9\\n100 2 6 5\\n\", \"8 5 22\\n100 3 7 5 3 1\\n164 4 5 2 7 8\\n334 7 2 7 2 9\\n234 4 7 2 8 2\\n541 5 4 3 3 6\\n235 4 8 6 9 7\\n394 3 6 1 6 2\\n872 8 4 3 7 2\\n\", \"11 12 29799\\n31069 1476 2003 8569 2842 5037 3403 5...
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his understanding level of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and read...
0
{"tests": "{\"inputs\": [\"70 92 20 40\\n99 92 9 49\\n\", \"0 73 20 40\\n59 73 39 100\\n\", \"39 90 20 40\\n47 90 28 31\\n\", \"-46 55 20 40\\n-17 55 7 11\\n\", \"31 40 37 76\\n48 65 66 98\\n\", \"-81 -55 20 40\\n19 20 83 85\\n\", \"-27 -68 20 40\\n2 -68 9 48\\n\", \"48 30 20 40\\n77 37 10 99\\n\", \"-64 -47 20 40\\n-5...
A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine. Let us remind you that a ring is a region located between two...
0
{"tests": "{\"inputs\": [\"7\\n3 6\\n1 2\\n3 1\\n7 4\\n5 7\\n1 4\\n\", \"4\\n1 4\\n4 2\\n2 3\\n\", \"4\\n1 4\\n4 3\\n2 3\", \"7\\n3 6\\n2 2\\n3 1\\n7 4\\n5 7\\n1 4\", \"7\\n3 6\\n2 2\\n3 1\\n7 4\\n4 7\\n1 4\", \"7\\n3 6\\n1 2\\n3 2\\n7 4\\n5 7\\n1 4\", \"7\\n3 6\\n2 2\\n3 1\\n5 4\\n4 7\\n1 4\", \"4\\n1 2\\n4 2\\n2 3\",...
Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the gr...
0.125
{"tests": "{\"inputs\": [\"14\\n\", \"38\\n\", \"25\\n\", \"22\\n\", \"26\\n\", \"20\\n\", \"34\\n\", \"8\\n\", \"32\\n\", \"16\\n\", \"30\\n\", \"28\\n\", \"18\\n\", \"37\\n\", \"10\\n\", \"39\\n\", \"35\\n\", \"15\\n\", \"27\\n\", \"12\\n\", \"31\\n\", \"24\\n\", \"5\\n\", \"19\\n\", \"6\\n\", \"21\\n\", \"23\\n\", \...
Consider the following equation: <image> where sign [a] represents the integer part of number a. Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers x and y (x, y > 0), for which the ...
0
{"tests": "{\"inputs\": [\"4\\n0 1\\n4 2\\n2 4\\n3 4\", \"4\\n0 1\\n4 2\\n2 1\\n3 4\", \"4\\n-1 1\\n4 3\\n1 1\\n3 4\", \"4\\n-1 1\\n4 2\\n1 1\\n3 8\", \"4\\n-1 1\\n4 4\\n1 0\\n3 8\", \"4\\n1 2\\n4 2\\n2 4\\n3 4\", \"4\\n1 2\\n4 2\\n2 4\\n3 7\", \"4\\n0 1\\n4 3\\n2 1\\n2 4\", \"4\\n-2 1\\n4 2\\n1 1\\n1 4\", \"4\\n2 2\\n...
Problem statement There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows. 1. $ X_0 = 0 $ 2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $ Either. Find $ X_N $. Constraint * $ 1 \ leq N \ leq 10 ^ 5 $ * $ 1 \...
0
{"tests": "{\"inputs\": [\"4\\n3 2 3 6\\n2 8 5 10\\n\", \"3\\n1 2 3\\n1 2 3\\n\", \"1\\n0\\n1\\n\", \"2\\n0 0\\n69 6969\\n\", \"10\\n3 3 5 5 6 6 1 2 4 7\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10\\n206158430208 206162624513 68719476737 137506062337 206162624513 4194305 68719476737 206225539072 137443147777 68719476736\\n20224389...
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two intege...
0
{"tests": "{\"inputs\": [\"3 2\\n1 3 1\\n\", \"3 6\\n3 3 3\\n\", \"5 6\\n4 2 3 1 3\\n\", \"6 1\\n1 1 1 300 1 1\\n\", \"3 10\\n5 8 1\\n\", \"1 1\\n1\\n\", \"4 14\\n4 9 2 7\\n\", \"8 20\\n3 2 1 1 6 2 6 1\\n\", \"10 6\\n6 4 8 9 9 10 5 2 8 1\\n\", \"48 14\\n1 1 1 1 1 6 1 1 1 1 1 1 3 3 1 1 1 1 1 2 2 2 1 1 1 1 1 1 2 1 4 1 1 ...
You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of...
0.125
{"tests": "{\"inputs\": [\"9\\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000\\n\", \"4\\n1 0 1 0\\n\", \"3\\n0 0 0\\n\", \"17\\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000\\n\", \"5\\n1000000000 0 0 1000000000 -1000000000\\n\", \"50...
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as...
0
{"tests": "{\"inputs\": [\"3 3\\n0 1 0\\n0 1 0\\n1 0 0\\n1 0 0\\n1 0 0\\n1 0 0\\n\", \"6 7\\n0 0 1 1 0 0 1\\n0 1 0 0 1 0 1\\n0 0 0 1 0 0 1\\n1 0 1 0 1 0 0\\n0 1 0 0 1 0 1\\n0 1 0 1 0 0 1\\n1 1 0 1 0 1 1\\n0 1 1 0 1 0 0\\n1 1 0 1 0 0 1\\n1 0 1 0 0 1 0\\n0 1 1 0 1 0 0\\n0 1 1 1 1 0 1\\n\", \"3 4\\n0 1 0 1\\n1 0 1 0\\n0 1...
Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task. You are given two matrices $A$ and $B$ of size $n \times m$, each of which consists of $0$ and $1$ only. You can apply the following operation to the matrix $A$ arbitrary number of time...
0.875
{"tests": "{\"inputs\": [\"4\\n30\\n67\\n4\\n14\\n\", \"2\\n556\\n556\\n\", \"1\\n1\\n\", \"1\\n1\\n\", \"4\\n30\\n67\\n4\\n14\\n\", \"2\\n556\\n556\\n\", \"1\\n2\\n\", \"4\\n16\\n67\\n4\\n14\\n\", \"2\\n556\\n806\\n\", \"4\\n30\\n67\\n8\\n14\\n\", \"1\\n3\\n\", \"4\\n16\\n12\\n4\\n14\\n\", \"2\\n556\\n128\\n\", \"4\\n...
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar...
0
{"tests": "{\"inputs\": [\"11\\n(RaRbR)L)L(\\n\", \"11\\n(R)R(R)Ra)c\\n\", \"1\\na\\n\", \"3\\n(R)\\n\", \"3\\n(R(\\n\", \"3\\n)R)\\n\", \"3\\n)R(\\n\", \"3\\n(l)\\n\", \"21\\n(RRRRR)LLLL(RRR)LL(R)\\n\", \"3\\n(l)\\n\", \"3\\n(R)\\n\", \"3\\n)R(\\n\", \"1\\na\\n\", \"3\\n(R(\\n\", \"21\\n(RRRRR)LLLL(RRR)LL(R)\\n\", \"3...
The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that it points to only one of the characters (and not between a pair of characters)...
0.75
{"tests": "{\"inputs\": [[\"An old silent pond...\\nA frog jumps into the pond,\\nsplash! Silence again.\"], [\"An old silent pond...\\nA frog jumps into the pond, splash!\\nSilence again.\"], [\"An old silent pond...\\nA frog jumps into the pond,\\nsplash!\\nSilence again.\"], [\"An old silent pond... A frog jumps int...
[Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not. ### About syllables [Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of...
0.75
{"tests": "{\"inputs\": [\"4 2\\n2 3 2 3\\n\", \"5 2\\n1 2 3 4 5\\n\", \"1 1\\n1\\n\", \"1 1\\n1000000000\\n\", \"2 1\\n6042 8885\\n\", \"2 2\\n8224 8138\\n\", \"3 1\\n2403 4573 3678\\n\", \"3 2\\n1880 3827 5158\\n\", \"3 3\\n4062 8888 5423\\n\", \"4 1\\n1867 5670 374 4815\\n\", \"4 2\\n4049 2220 6447 3695\\n\", \"4 3\...
You are given a set of n elements indexed from 1 to n. The weight of i-th element is w_{i}. The weight of some subset of a given set is denoted as $W(S) =|S|\cdot \sum_{i \in S} w_{i}$. The weight of some partition R of a given set into k subsets is $W(R) = \sum_{S \in R} W(S)$ (recall that a partition of a given set i...
0.25
{"tests": "{\"inputs\": [\"2 1000000000\\n999999999 1000000000\\n1 2\\n\", \"2 1000000000\\n99999999 1000000000\\n1 1\\n\", \"2 1000000000\\n1 1000000000\\n2 2\\n\", \"2 10\\n4 5\\n2 2\\n\", \"2 2\\n4 5\\n1 2\\n\", \"2 1000000000\\n130296385 1000000000\\n1 1\\n\", \"3 19\\n4 6 8\\n2 2 3\\n\", \"2 2\\n4 5\\n2 2\\n\", \"...
There are two bus stops denoted A and B, and there n buses that go from A to B every day. The shortest path from A to B takes t units of time but some buses might take longer paths. Moreover, buses are allowed to overtake each other during the route. At each station one can find a sorted list of moments of time when a...
0
{"tests": "{\"inputs\": [\"1 1 3 2\\n\", \"4 3 2 2\\n\", \"3 4 2 3\\n\", \"4 4 5 5\\n\", \"1 1 1 1\\n\", \"1000 1000 1000 1000\\n\", \"125 992 14 25\\n\", \"999 998 997 996\\n\", \"984 286 976 284\\n\", \"999 1000 1000 999\\n\", \"999 1000 998 999\\n\", \"1 1000 1000 1\\n\", \"1 999 1000 1\\n\", \"50 80 6 3\\n\", \"114...
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the scre...
0.5
{"tests": "{\"inputs\": [\"3 1\\n6\\n\", \"3 3\\n1 7 8\\n\", \"3 4\\n1 3 5 7\\n\", \"10 10\\n334 588 666 787 698 768 934 182 39 834\\n\", \"2 4\\n3 2 4 1\\n\", \"3 4\\n3 4 1 6\\n\", \"2 0\\n\", \"2 1\\n1\\n\", \"17 0\\n\", \"17 1\\n95887\\n\", \"2 2\\n4 2\\n\", \"2 3\\n2 1 3\\n\", \"3 5\\n7 2 1 4 8\\n\", \"3 6\\n5 4 1 ...
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. $2^n$ teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify the champion. Teams are numbered from $1$ to $2^n$ and will play games on...
0
{"tests": "{\"inputs\": [\"15 12\\n2 77\\n8 79\\n5 70\\n0 1\\n0 4\\n6 10\\n4 38\\n3 36\\n9 1\\n2 9\\n0 72\\n10 17\\n5 93\\n7 10\\n3 49\\n\", \"15 3\\n2 39237\\n6 42209\\n8 99074\\n2 140949\\n3 33788\\n15 7090\\n13 29599\\n1 183967\\n6 20161\\n7 157097\\n10 173220\\n9 167385\\n15 123904\\n12 30799\\n5 47324\\n\", \"10 2...
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined,...
0
{"tests": "{\"inputs\": [\"3 4 2\\n\", \"3 4 3\\n\", \"3 1 560955243\\n\", \"99999989 999999937 2\\n\", \"4 3 3\\n\", \"6 11 33287298\\n\", \"626673832 329016046 38\\n\", \"236887699 1000000000 2\\n\", \"186860 5142 960834120\\n\", \"217041223 799999999 5865979\\n\", \"229999981 1000000000 2048\\n\", \"887669087 755467...
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k. Help Vasya! Find such points (if it's possible). If there are multiple solutio...
0
{"tests": "{\"inputs\": [\"-3 -2 9 6\\n3 -2 7 6\\n-1 0 5 0\\n2 2 0 -1\\n0 1 2 1\\n-3 -1 3 1\\n0 0 0 0\", \"-1 -2 8 12\\n3 -2 7 6\\n0 0 9 0\\n2 2 0 -1\\n1 1 2 1\\n-3 -1 3 1\\n0 0 0 0\", \"-1 -2 9 6\\n3 -2 7 6\\n-1 0 9 0\\n2 2 0 -1\\n1 2 2 0\\n-3 -1 3 1\\n0 0 0 0\", \"-3 -2 9 0\\n3 -2 4 6\\n-1 0 8 0\\n1 2 0 0\\n-1 1 2 1\...
With the motto "Creating your own path," a shrine created a fortune-telling fortune with its own hands. Ask the person who draws the lottery to throw six stones first, then the line segment connecting the first and second of the thrown stones, the line segment connecting the third and fourth, the fifth and six The fort...
0.125
{"tests": "{\"inputs\": [\"4 2\\n4 5 9 7\\n1 2 11 33\\n\", \"5 1\\n1 2 3 4 5\\n1 2 3 4 5\\n\", \"1 0\\n2\\n3\\n\", \"7 1\\n2 3 4 5 7 8 9\\n0 3 7 9 5 8 9\\n\", \"7 2\\n2 4 6 7 8 9 10\\n10 8 4 8 4 5 9\\n\", \"11 10\\n1 2 3 4 5 6 7 8 9 10 11\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10...
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo...
0.375
{"tests": "{\"inputs\": [\"10\\n2 4\\n2 5\\n1 3\\n10 7\\n1 6\\n2 8\\n9 5\\n8 6\\n10 6\", \"4\\n1 2\\n1 3\\n2 4\", \"10\\n2 4\\n2 5\\n1 3\\n3 7\\n1 6\\n2 8\\n9 5\\n8 6\\n10 6\", \"10\\n2 4\\n2 5\\n8 3\\n10 7\\n1 6\\n2 8\\n9 7\\n8 6\\n10 6\", \"10\\n2 4\\n2 5\\n1 3\\n10 7\\n1 6\\n2 8\\n9 5\\n8 6\\n10 2\", \"10\\n2 4\\n2 ...
There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ways to construct T'.) For a fixed T', we will define d(s,\ t) fo...
0
{"tests": "{\"inputs\": [[\"3\", \"4\", \"1 5 5 5\", \"4\", \"1 1 1 5\", \"3\", \"5 5 2\", \"\"], \"3\\n4\\n1 5 5 5\\n3\\n1 1 1 5\\n3\\n5 5 2\", \"3\\n4\\n1 5 5 5\\n3\\n1 2 1 5\\n3\\n5 5 2\", \"3\\n4\\n1 10 5 5\\n3\\n1 2 1 5\\n3\\n1 1 3\", \"3\\n4\\n1 5 5 6\\n4\\n1 1 1 5\\n3\\n5 5 2\", \"3\\n4\\n1 5 5 5\\n3\\n1 2 1 5\\...
Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only. Chef's canvas is N millimeters long and is initially all white. For simplicity, colors will be re...
0.125
{"tests": "{\"inputs\": [\"codefestival\\n101\", \"xyz\\n1\", \"zyx\\n1\", \"cdoeffstival\\n101\", \"zyx\\n2\", \"cdoeffstival\\n111\", \"zyx\\n3\", \"lavitsffeodc\\n111\", \"xyz\\n2\", \"caoeffstivdl\\n111\", \"xyz\\n3\", \"xyz\\n5\", \"xyz\\n8\", \"zyx\\n0\", \"zyx\\n4\", \"b\\n25\", \"yxz\\n1\", \"cdoefestival\\n001...
Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aa...
0
{"tests": "{\"inputs\": [[1, 9], [4, 17], [1, 90], [-4, 17], [-4, 37], [-14, -1], [-14, -6]], \"outputs\": [[8], [12], [72], [20], [38], [13], [9]]}", "source": "taco"}
# Don't give me five! In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive! Examples: ``` 1,9 -> 1,2,3,4,6,7,8,9 -> Result 8 4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12 ``...
0
{"tests": "{\"inputs\": [\"3 4\\nS...\\n....\\n..S.\\n\", \"2 2\\n..\\n..\\n\", \"2 2\\nSS\\nSS\\n\", \"7 3\\nS..\\nS..\\nS..\\nS..\\nS..\\nS..\\nS..\\n\", \"3 5\\n..S..\\nSSSSS\\n..S..\\n\", \"10 10\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nSSSSSSSSSS\\nS...
You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows: [Image] The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contain...
0.75
{"tests": "{\"inputs\": [\"1\\n0 17\\n\", \"5\\n1 1000000\\n100 100\\n101 9\\n102 4\\n103 8\\n\", \"16\\n1296 2\\n1568 1\\n7435 2\\n3660 1\\n6863 2\\n886 2\\n2596 1\\n7239 1\\n6146 1\\n5634 1\\n3119 2\\n1166 2\\n7610 2\\n5992 1\\n630 2\\n8491 2\\n\", \"3\\n0 20\\n1 18\\n2 4\\n\", \"1\\n1 1000000000\\n\", \"1\\n0 1\\n\"...
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a...
0
{"tests": "{\"inputs\": [\"5 4 2\\n1 2 5\\n1 2 3\\n2 3 4\\n1 4 10\\n1 5\\n\", \"3 1 1\\n1 2 3\\n3\\n\", \"2 3 1\\n1 2 3\\n1 2 18\\n1 2 13\\n2\\n\", \"3 7 0\\n1 3 9\\n1 2 5\\n1 2 21\\n1 2 12\\n1 2 13\\n2 3 19\\n2 3 8\\n\", \"4 13 1\\n1 4 10\\n1 3 6\\n1 4 3\\n3 4 1\\n1 3 2\\n1 2 15\\n1 4 21\\n1 4 20\\n2 4 13\\n1 4 7\\n2 ...
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities nu...
0.875
{"tests": "{\"inputs\": [\"11111111 77777777\\n\", \"3 7\\n\", \"4 3\\n\", \"1 4\\n\", \"1 10\\n\", \"2 1\\n\", \"2 66666666\\n\", \"23333 66666\\n\", \"1 8\\n\", \"7 2\\n\", \"1000000000 1000000000\\n\", \"66666666 66668888\\n\", \"998244353 19260817\\n\", \"19260817 19260817\\n\", \"7 1\\n\", \"2 5\\n\", \"6 2\\n\", ...
Little C loves number «3» very much. He loves all things about it. Now he is playing a game on a chessboard of size n × m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between ...
0
{"tests": "{\"inputs\": [\"5 4 7 6 4 1\\n10\\n19 16 18 12 16 15 16 20 16 14\\n\", \"158260522 877914575 602436426 24979445 861648772 623690081\\n1\\n896194147\\n\", \"58260522 77914575 2436426 24979445 61648772 23690081\\n10\\n582107247 906728404 411434947 673536177 411497300 488012525 561127307 800305059 992325267 112...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
0.5
{"tests": "{\"inputs\": [\"4 3\\n3543\\n\", \"4 2\\n2020\\n\", \"20 11\\n33883322005544116655\\n\", \"20 8\\n33883322005544116655\", \"20 5\\n33883322005544116655\", \"20 5\\n35091597582718018558\", \"20 3\\n35091597582718018558\", \"20 5\\n34713145004890865366\", \"20 5\\n63523169932268849551\", \"20 2\\n3388332200554...
Takahashi has a string S of length N consisting of digits from 0 through 9. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a 0 also co...
0
{"tests": "{\"inputs\": [\"4 9\\n1 4 3\\n2 4\\n3 3 1\\n1 2 3\\n2 2\\n3 1 2\\n1 3 1\\n2 2\\n3 1 3\\n\", \"1 2\\n2 1\\n3 1 1\\n\", \"2 3\\n1 2 1\\n2 1\\n3 2 1\\n\", \"2 3\\n1 1 2\\n2 1\\n3 2 1\\n\", \"10 10\\n2 9\\n1 2 1\\n1 3 2\\n3 1 1\\n3 1 1\\n2 3\\n3 1 1\\n3 1 1\\n3 1 2\\n3 1 1\\n\", \"10 10\\n1 1 2\\n2 1\\n2 1\\n2 1...
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: either employee y became the boss of employee x (at that, employee x didn't have a boss be...
0.875
{"tests": "{\"inputs\": [[4, 5], [5, 5], [6, 5], [2, 5, 3], [5, 5, 3], [8, 5, 3], [8.1, 5, 3], [1.99, 5, 3]], \"outputs\": [[-1], [0], [1], [0], [0], [0], [1], [-1]]}", "source": "taco"}
Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`. `a` is "close to" `b` if `margin` is higher than or equal to the difference between `a` and `b`. When `a` is lower than `b`, return `-1`. ...
0
{"tests": "{\"inputs\": [\"8 50\\n\", \"302237 618749\\n\", \"999999 1000000\\n\", \"893011 315181\\n\", \"4449 1336\\n\", \"871866 348747\\n\", \"999 999\\n\", \"2311 7771\\n\", \"429181 515017\\n\", \"21 15\\n\", \"201439 635463\\n\", \"977965 896468\\n\", \"1000000 1000000\\n\", \"384 187\\n\", \"720 972\\n\", \"198...
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving. More formally, first one of four diagonal directions is chosen and the billiard ball moves ...
0.125
{"tests": "{\"inputs\": [\"3 11\\n+ 1 2 a\\n+ 2 3 b\\n+ 3 2 a\\n+ 2 1 b\\n? 3\\n? 2\\n- 2 1\\n- 3 2\\n+ 2 1 c\\n+ 3 2 d\\n? 5\\n\", \"3 11\\n+ 1 2 a\\n+ 2 3 c\\n+ 3 2 a\\n+ 2 1 b\\n? 3\\n? 2\\n- 2 1\\n- 3 2\\n+ 2 1 c\\n+ 3 2 d\\n? 5\\n\", \"3 11\\n+ 1 2 a\\n+ 1 3 c\\n+ 3 2 a\\n+ 2 1 b\\n? 6\\n? 4\\n- 2 1\\n- 3 2\\n+ 2 ...
You are given a directed graph consisting of $n$ vertices. Each directed edge (or arc) labeled with a single character. Initially, the graph is empty. You should process $m$ queries with it. Each query is one of three types: "$+$ $u$ $v$ $c$" — add arc from $u$ to $v$ with label $c$. It's guaranteed that there is no ...
0
{"tests": "{\"inputs\": [\"2 2\\n14419485 34715515\\n45193875 34715515\\n\", \"2 2\\n100000000 100000000\\n0 0\\n\", \"2 2\\n217361 297931\\n297930 83550501\\n\", \"2 2\\n72765050 72765049\\n72763816 77716490\\n\", \"4 3\\n1 5 6 7\\n8 9 10\\n\", \"2 2\\n0 0\\n0 0\\n\", \"2 2\\n100000000 100000000\\n100000000 100000000\...
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i an...
0.125
{"tests": "{\"inputs\": [\"7\\n1\\n?\\n2\\n?0\\n10\\n79259?087\\n2\\n??\\n3\\n0?1\\n4\\n?????\\n3\\n012\", \"7\\n1\\n?\\n2\\n?0\\n10\\n79259?087\\n2\\n??\\n3\\n0?1\\n4\\n?????\\n3\\n13\", \"7\\n1\\n?\\n2\\n?0\\n10\\n79259?087\\n2\\n??\\n3\\n0?1\\n4\\n?????\\n3\\n0\", \"7\\n1\\n?\\n2\\n?0\\n10\\n79259?087\\n2\\n??\\n2\\...
From the FAQ: What am I allowed to post as a comment for a problem? Do NOT post code. Do NOT post a comment asking why your solution is wrong. Do NOT post a comment asking if you can be given the test case your program fails on. Do NOT post a comment asking how your solution can be improved. Do NOT post a comment gi...
0
{"tests": "{\"inputs\": [\"6\\n5 2\\n10 30 40 70 100\\n7 3\\n3 4 10 17 21 26 28\\n1 1\\n100\\n2 1\\n0 1000000\\n3 5\\n30 70 150\\n6 4\\n0 10 20 30 40 50\", \"6\\n5 2\\n10 30 40 70 100\\n7 3\\n3 5 10 17 21 26 28\\n1 1\\n100\\n2 1\\n0 1000000\\n3 5\\n30 70 211\\n6 4\\n0 10 20 30 40 50\", \"6\\n5 2\\n10 30 40 70 100\\n7 3...
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the generators wherever you like, but in order for electricity to be supp...
0
{"tests": "{\"inputs\": [\"2\\nD\\nT\", \"2\\nE\\nU\", \"2\\nF\\nU\", \"2\\nD\\nS\", \"2\\nC\\nU\", \"2\\nB\\nU\", \"2\\nD\\nV\", \"2\\nD\\nR\", \"2\\nA\\nU\", \"2\\nD\\nW\", \"2\\nG\\nU\", \"2\\nD\\nX\", \"2\\nD\\nY\", \"2\\nD\\nZ\", \"2\\nD\\nQ\", \"2\\nD\\nP\", \"2\\n@\\nU\", \"2\\nH\\nU\", \"2\\nI\\nU\", \"2\\nD\\n...
Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station....
0
{"tests": "{\"inputs\": [\"4\\n92 31\\n0 7\\n31 0\\n7 141\\n\", \"2\\n0 1\\n2 0\\n\", \"3\\n0 2\\n1 3\\n2 0\\n\", \"4\\n101 0\\n0 102\\n102 100\\n103 101\\n\", \"5\\n0 1\\n1 4\\n4 0\\n3 2\\n5 3\\n\", \"6\\n10001 0\\n0 10005\\n10003 10001\\n10002 10000\\n10005 10002\\n10004 10003\\n\", \"3\\n0 743259\\n72866 70294\\n743...
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working. Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of...
0
{"tests": "{\"inputs\": [\"4 3 2\\n1\\n2\\n3\\n4\\n\", \"2 1 1\\n1\\n2\\n\", \"7 5 20\\n26\\n27\\n28\\n29\\n30\\n31\\n32\\n\", \"10 10 1\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"10 1 10\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"1 999999 1000000\\n1000000000\\n\", \"5 5 6\\n999999999\\n999999998\\n9999999...
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to...
0
{"tests": "{\"inputs\": [\"3 1 1\\n\", \"5 1 2\\n\", \"1000 1 1000\\n\", \"999999 1 1\\n\", \"1 2 179350\\n\", \"2 1 1\\n\", \"2 2 1\\n\", \"100000 1 10\\n\", \"1 999999 999999\\n\", \"100 220905 13\\n\", \"200000 2 4\\n\", \"1234 5 777\\n\", \"12345 3 50\\n\", \"10 12347 98765\\n\", \"1 999599 123123\\n\", \"1 8888 99...
The well-known Fibonacci sequence $F_0, F_1, F_2,\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \geq 2$: $F_i = F_{i - 1} + F_{i - 2}$. Given an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a + d, a + 2\cdot d,\ldots, a + (n - 1)\cdot d)$. You need to find another i...
0
{"tests": "{\"inputs\": [\"5\\n11011\\n3\\n1 3 3\\n1 4 2\\n1 2 3\\n\", \"1\\n0\\n1\\n1 1 1\\n\", \"3\\n010\\n3\\n1 3 1\\n1 3 1\\n3 2 1\\n\", \"10\\n0100001001\\n10\\n2 5 4\\n10 2 1\\n5 3 5\\n2 9 2\\n5 3 1\\n3 3 3\\n9 8 1\\n5 3 1\\n9 5 2\\n2 3 6\\n\", \"5\\n00010\\n5\\n5 3 1\\n2 1 2\\n4 1 1\\n3 1 3\\n2 1 3\\n\", \"50\\n...
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with the $r$-th character as ...
0
{"tests": "{\"inputs\": [\"6 2\\nAABABA\\n\", \"3 2\\nBBA\\n\", \"100 2\\nBBBBBBBAAABBAAAABAABBBAABABAAABBBABBAAAABBABAAAAAAAAAAAAABAAABBBAAABAABBBBBBBABBBBAABAAABBBAABBAAAAB\\n\", \"10 2\\nBBABABABAB\\n\", \"1 26\\nZ\\n\", \"8 3\\nAABBABBB\\n\", \"41 2\\nAABAAABBBBBBAAAABBBAAAAAABBBBBBBBAAAAAAAA\\n\", \"20 3\\nCCCCAAA...
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. Input The first input line contains two integ...
0
{"tests": "{\"inputs\": [[1, 10, 30], [3, 10, 26], [1, 10, 8], [2, 30, 350], [1, 23, 30], [2, 23, 30], [43, 15, 3456]], \"outputs\": [[\"Showing 1 to 10 of 30 Products.\"], [\"Showing 21 to 26 of 26 Products.\"], [\"Showing 1 to 8 of 8 Products.\"], [\"Showing 31 to 60 of 350 Products.\"], [\"Showing 1 to 23 of 30 Prod...
A category page displays a set number of products per page, with pagination at the bottom allowing the user to move from page to page. Given that you know the page you are on, how many products are in the category in total, and how many products are on any given page, how would you output a simple string showing which...
0
{"tests": "{\"inputs\": [\"65\\n110\", \"271828182845904523\\n328419650112448238\", \"271828182845904523\\n491516385100905315\", \"65\\n158\", \"7\\n8\", \"65\\n181\", \"271828182845904523\\n636593337042278053\", \"271828182845904523\\n1128816364578546661\", \"7\\n15\", \"271828182845904523\\n294375876077939712\", \"65...
Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are? Constraints * 1 ≤ A ≤ B < 2^{60} * A and B are integers. Input The input is given from Standard Input in the following format: ...
0
{"tests": "{\"inputs\": [\"55\\n33 64 51 38 37 44 63 89 60 90 33 67 82 81 40 41 58 86 47 78 60 86 81 43 57 89 39 72 59 88 47 41 59 79 35 41 67 57 70 55 90 46 37 64 78 55 82 88 81 60 46 75 34 79 51\\n\", \"8\\n100 1 2 3 1000 3 2 1\\n\", \"25\\n8432 7540 8635 101 3810 1892 8633 1640 8440 2096 7974 5359 9912 6850 2898 554...
Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem. Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — that is the time needed to work with this customer. What is special about this...
0
{"tests": "{\"inputs\": [\"5\\n12\\n5 4 4 3 2 2 1 1 1 1 1 1\\n4\\n4 3 2 1\\n1\\n1000000\\n20\\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\\n32\\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\\n\", \"5\\n12\\n5 4 4 3 2 2 1 1 1 1 1 1\\n4\\n4 3 2 1\\n1\\n1000000\\n...
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n. Help the jury distrib...
0.125
{"tests": "{\"inputs\": [\"2\\n3 3\\n3 4\", \"2\\n3 3\\n3 0\", \"2\\n5 3\\n3 0\", \"2\\n5 3\\n6 0\", \"2\\n5 3\\n6 1\", \"2\\n5 2\\n6 1\", \"2\\n3 2\\n6 1\", \"2\\n1 2\\n6 1\", \"2\\n1 3\\n6 1\", \"2\\n0 3\\n6 1\", \"2\\n0 3\\n8 1\", \"2\\n-1 3\\n8 1\", \"2\\n-1 0\\n8 1\", \"2\\n-1 0\\n2 1\", \"2\\n0 0\\n2 1\", \"2\\n0...
Read problems statements in Mandarin Chinese and Russian. Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some table (which is in some poi...
0
{"tests": "{\"inputs\": [\"3 3\\n1 2\\n1 3\\n3 2\\n\", \"4 5\\n3 1\\n4 1\\n2 3\\n3 4\\n2 4\\n\", \"5 4\\n3 1\\n2 1\\n2 3\\n4 5\\n\", \"2 1\\n2 1\\n\", \"5 10\\n5 2\\n4 1\\n2 1\\n3 4\\n2 4\\n3 2\\n5 4\\n3 5\\n3 1\\n5 1\\n\", \"100 10\\n73 55\\n29 76\\n15 12\\n94 46\\n77 67\\n76 16\\n72 50\\n41 40\\n89 75\\n27 22\\n\", \...
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: Labels form a valid permutation of length n — an integer sequence such that each integer...
0
{"tests": "{\"inputs\": [\"3 3 3 1 1 9\\n1 1\\n1 2\\n1 3\\n2 1\\n2 2\\n2 3\\n3 1\\n3 2\\n3 3\\n\", \"5 5 0 0 0 1\\n1 4\\n\", \"14 76 376219315 550904689 16684615 24\\n11 21\\n1 65\\n5 25\\n14 63\\n11 30\\n1 19\\n5 7\\n9 51\\n2 49\\n13 75\\n9 9\\n3 63\\n8 49\\n5 1\\n1 67\\n13 31\\n9 35\\n3 53\\n13 73\\n5 71\\n1 32\\n5 4...
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j)....
0
{"tests": "{\"inputs\": [\"1000000000 1000000000 500000000 500000000 500000000 500000001\\n\", \"47001271 53942737 7275347 1652337 33989593 48660013\\n\", \"5664399 63519726 1914884 13554302 2435218 44439020\\n\", \"100 100 32 63 2 41\\n\", \"69914272 30947694 58532705 25740028 30431847 27728130\\n\", \"1000000000 1000...
You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (...
0
{"tests": "{\"inputs\": [\"100 20 100 10202\\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwhwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwww\\n\", \"7 1 100 8\\nhhhwwwh\\n\", \"5 2 4 12\\nhhhwh\\n\", \"12 10 10 1\\nwhwhwhwhwhwh\\n\", \"16 1 1000 2100\\nhhhwwwhhhwhhhwww\\n\", \"20 10 10 1\\nhwhwhwhwhwhwhwhwhhhw\\n...
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec...
0
{"tests": "{\"inputs\": [\"5\\n0 x 2 4 x\\n2\\nx x\\n2\\n1 2\\n2\\n2 1\\n2\\n1000000000 x\\n4\\nx 2 1 x\\n0\", \"5\\n1 x 2 0 x\\n2\\nx x\\n2\\n1 2\\n2\\n2 1\\n2\\n1000000000 x\\n4\\nx 2 1 x\\n0\", \"5\\n0 x 2 4 x\\n2\\nx x\\n2\\n1 2\\n2\\n0 1\\n2\\n1000000000 x\\n4\\nx 2 1 x\\n0\", \"5\\n0 x 3 4 x\\n2\\nx x\\n2\\n1 2\\...
Problem Statement Nathan O. Davis is a student at the department of integrated systems. Today's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an audio signal. He copied the given audio signal to his USB memory and brought ...
0
{"tests": "{\"inputs\": [\"2 50\\n6 10\\n\", \"3 100\\n14 22 40\\n\", \"5 1000000000\\n6 6 2 6 2\\n\", \"3 000\\n14 22 40\", \"2 46\\n6 10\", \"2 46\\n10 10\", \"2 12\\n10 10\", \"2 85\\n6 10\", \"3 101\\n14 2 2\", \"3 000\\n14 16 40\", \"3 010\\n14 16 40\", \"3 010\\n14 16 4\", \"3 110\\n14 16 4\", \"3 110\\n14 22 4\"...
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M. Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N): - There exists a non-negative integer p such that X= a_k \times (p+0.5). Find the number of semi-common...
0.25
{"tests": "{\"inputs\": [\"18\\n6 1 1 3 1 1 1 1 1 1 4 1 8 1 1 18 1 5\\n\", \"19\\n9 7 1 8 1 1 1 13 1 1 3 3 19 1 1 1 1 1 1\\n\", \"23\\n1 1 1 1 3 7 3 1 1 1 3 7 1 3 1 15 1 3 7 3 23 1 1\\n\", \"24\\n8 5 3 1 1 5 10 1 1 1 1 5 1 2 7 3 4 1 1 24 1 1 2 8\\n\", \"12\\n12 7 4 3 3 1 1 1 1 1 1 1\\n\", \"20\\n20 9 4 4 3 3 3 1 1 1 1 ...
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahub asks Iahubina: can you build a rooted tree, such that * each ...
0.125
{"tests": "{\"inputs\": [[[\"------------\", \"------------\", \"-L----------\", \"------------\", \"------------\", \"------------\"], 10], [[\"------------\", \"---M--------\", \"------------\", \"------------\", \"-------R----\", \"------------\"], 6], [[\"-----------L\", \"--R---------\", \"------------\", \"------...
## The story you are about to hear is true Our cat, Balor, sadly died of cancer in 2015. While he was alive, the three neighborhood cats Lou, Mustache Cat, and Raoul all recognized our house and yard as Balor's territory, and would behave respectfully towards him and each other when they would visit. But after Balor...
0
{"tests": "{\"inputs\": [\"2\\n3\\n1 10 15\\n1 10 3\\n3\\n10 20 30\\n15 5 20\", \"2\\n3\\n1 10 15\\n1 10 3\\n3\\n19 20 30\\n15 5 20\", \"2\\n3\\n1 10 29\\n1 10 3\\n2\\n17 39 30\\n15 5 20\", \"2\\n3\\n1 10 29\\n1 8 3\\n3\\n17 20 30\\n15 5 20\", \"2\\n3\\n1 10 29\\n1 8 3\\n3\\n17 32 30\\n15 5 20\", \"2\\n3\\n1 4 15\\n1 2...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. There are N students living in the dormitory of Berland State University. Each of them sometimes wants to use the kitchen, so the head of the dormitory came up with a timetable for kitchen's usage in order to avoid the conflicts: The first...
0.75
{"tests": "{\"inputs\": [\"4\\n4\\n1 2 3 4\\n5\\n1 3 2 4 5\\n3\\n2 3 1\\n1\\n1\\n\", \"1\\n8\\n7 6 5 4 3 2 8 1\\n\", \"1\\n10\\n10 3 2 1 9 8 7 6 5 4\\n\", \"1\\n10\\n10 1 9 8 7 6 5 4 3 2\\n\", \"1\\n8\\n8 1 7 6 5 4 3 2\\n\", \"1\\n11\\n6 2 11 1 10 9 8 7 5 4 3\\n\", \"1\\n10\\n8 7 6 5 4 3 9 2 10 1\\n\", \"1\\n9\\n9 1 8 ...
You are given a permutation $a$ of size $n$ and you should perform $n$ operations on it. In the $i$-th operation, you can choose a non-empty suffix of $a$ and increase all of its elements by $i$. How can we perform the operations to minimize the number of inversions in the final array? Note that you can perform operat...
0
{"tests": "{\"inputs\": [[\"8/8/8/8/8/8/8/8 w - -\"], [\"8/8/8/8/8/8/8/8 b - -\"], [\"k7/8/8/8/8/8/8/7K w - -\"], [\"k7/8/8/8/8/8/8/7K b - -\"], [\"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\"], [\"7k/1p4rp/p2B4/3P1r2/1P6/8/P6P/R6K b - - 0 31\"], [\"r3kr2/1qp2ppp/p3p3/3nP3/1pB5/1P2P3/P4PPP/2RQ1RK1 b q - 2...
A chess position can be expressed as a string using the Forsyth–Edwards Notation (FEN). Your task is to write a parser that reads in a FEN-encoded string and returns a depiction of the board using the Unicode chess symbols (♔,♕,♘,etc.). The board should be drawn from the perspective of the active color (i.e. the side ...
0
{"tests": "{\"inputs\": [\"5\\n4 10 6 6\\n6 5 4 3\\n1 1 0 0\\n31415 92653 58979 32384\\n1000000000 1000000000 999999999 999999999\", \"5\\n4 16 6 6\\n6 5 4 3\\n1 1 0 0\\n31415 92653 58979 32384\\n1000000000 1000000000 999999999 999999999\", \"5\\n4 26 6 6\\n6 5 4 3\\n1 1 0 0\\n31415 92653 58979 32384\\n1000000000 10000...
In this problem, you should process T testcases. For each testcase, you are given four integers N, M, A, B. Calculate \sum_{i = 0}^{N - 1} floor((A \times i + B) / M). Constraints * 1 \leq T \leq 100,000 * 1 \leq N, M \leq 10^9 * 0 \leq A, B < M Input Input is given from Standard Input in the following format: ...
0
{"tests": "{\"inputs\": [[\"1 2 3 5\"], [\"1 5\"], [\"\"], [\"1 2 3 4 5\"], [\"2 3 4 5\"], [\"2 6 4 5 3\"], [\"_______\"], [\"2 1 4 3 a\"], [\"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 ...
You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4). Return: * `0` if the elements can form such a sequence, and no number is missing ("not broken", e.g. `"1 2 4 3"`) * `1` if there ...
0
{"tests": "{\"inputs\": [\"10 10\\n2 3 1 5 6 7 8 4 10 9\\n2 3 1 4 5 6 7 8 10 9\\n\", \"4 3\\n2 1 4 3\\n4 3 1 2\\n\", \"3 100\\n2 3 1\\n2 3 1\\n\", \"55 28\\n35 33 46 8 11 13 14 26 42 38 1 7 34 5 2 21 17 45 54 43 4 18 27 50 25 10 29 48 6 16 22 28 55 53 49 41 39 23 40 47 51 37 36 19 9 32 52 12 24 3 20 15 30 44 31\\n5 52 ...
Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n. A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha...
0.125
{"tests": "{\"inputs\": [[1, [0, 0], []], [2, [0, 0], []], [3, [0, 0], []], [3, [1, 1], []], [2, [0, 0], [[1, 1]]], [3, [2, 0], [[1, 1]]], [3, [2, 0], [[0, 2]]], [10, [4, 6], [[0, 2], [5, 2], [5, 5]]], [8, [1, 1], [[5, 4]]], [8, [1, 5], [[5, 4]]], [8, [6, 1], [[5, 4]]]], \"outputs\": [[0], [3], [8], [8], [0], [0], [3],...
# Task Pac-Man got lucky today! Due to minor performance issue all his enemies have frozen. Too bad Pac-Man is not brave enough to face them right now, so he doesn't want any enemy to see him. Given a gamefield of size `N` x `N`, Pac-Man's position(`PM`) and his enemies' positions(`enemies`), your task is to count...
0
{"tests": "{\"inputs\": [\"8\\n5 6 2\\n2 4 3 5 7\\n5 11 2\\n2 4 3 5 7\\n3 2 3\\n4 2 6\\n5 2 3\\n10 1 3 9 2\\n2 10000 2\\n10000 10000\\n2 9999 2\\n10000 10000\\n4 6 4\\n3 2 3 2\\n5 5 3\\n1 2 2 1 2\\n\", \"2\\n2 1 2\\n1 1\\n2 2000000000 2\\n1 1\\n\", \"2\\n2 1 2\\n1 1\\n2 2000000000 2\\n1 1\\n\", \"8\\n5 6 2\\n2 4 3 5 7\...
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" ...
0.125
{"tests": "{\"inputs\": [\"5\\n0 0 0 0 0\\n\", \"2\\n10 2\\n\", \"20\\n10 5 3 1 3 7 7 6 8 3 6 2 9 10 5 2 10 9 10 4\\n\", \"10\\n8 8 2 2 2 2 10 10 10 8\\n\", \"5\\n1 2 3 1 1\\n\", \"20\\n10 6 1 9 10 10 7 0 10 5 9 1 5 7 4 9 3 9 7 2\\n\", \"20\\n7 7 7 7 7 7 10 10 10 10 23 21 23 20 22 23 22 23 95 97\\n\", \"7\\n1000000000 ...
Little Petya likes to play very much. And most of all he likes to play the following game: He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of ste...
0
{"tests": "{\"inputs\": [\"2\\n3\\n1 2\\n2 2\\n3 2\\n3\\n2 3\\n1 2\\n2 4\", \"2\\n3\\n1 2\\n2 2\\n3 2\\n3\\n2 3\\n1 2\\n2 8\", \"2\\n3\\n1 2\\n2 2\\n3 2\\n3\\n2 3\\n1 2\\n2 2\", \"2\\n3\\n1 1\\n2 2\\n3 2\\n3\\n2 3\\n1 2\\n2 2\", \"2\\n3\\n1 2\\n2 2\\n4 2\\n3\\n2 3\\n1 2\\n2 4\", \"2\\n3\\n1 1\\n2 2\\n3 2\\n3\\n2 3\\n1 ...
The Little Elephant from the Zoo of Lviv likes listening to music. There are N songs, numbered from 1 to N, in his MP3-player. The song i is described by a pair of integers B_{i} and L_{i} - the band (represented as integer) that performed that song and the length of that song in seconds. The Little Elephant is going t...
0
{"tests": "{\"inputs\": [\"2\\n2 1\\n\", \"3\\n2 4 2\\n\", \"2\\n1 1\\n\", \"3\\n1 1 1\\n\", \"20\\n1 6 8 9 10 10 11 11 10 10 9 6 6 6 6 4 3 2 1 0\\n\", \"3\\n0 2 1\\n\", \"3\\n2 2 1\\n\", \"2\\n2 4\\n\", \"2\\n1 3\\n\", \"1\\n1\\n\", \"5\\n1 0 2 1 0\\n\", \"20\\n2 2 4 5 5 6 7 6 5 5 7 6 4 3 3 3 3 3 3 1\\n\", \"5\\n1 1 0...
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following: function rangeIncrement(l,...
0
{"tests": "{\"inputs\": [\"1 1 1 1\\n0\\n\", \"3 10 10 150691913\\n8 7 10\\n\", \"1 5 5 1000\\n500\\n\", \"21 63 40 1009\\n4 4 2 2 4 4 3 2 4 2 0 3 3 4 3 4 3 0 4 2 4\\n\", \"29 157 50 1\\n3 0 0 3 1 1 2 0 4 4 1 2 2 1 0 0 2 0 3 2 2 3 3 1 4 1 1 4 1\\n\", \"10 9 20 48620\\n1 1 1 1 1 1 1 1 2 2\\n\", \"2 500 250 100\\n100 200...
Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes. Let's call a sequence of non-negative integers v1, v2, ..., vn a plan, if v1 + v2 + ... + vn = m...
0
{"tests": "{\"inputs\": [\"3\\n1 0 2\\n1 0\\n1\\n\", \"3\\n1 1 2\\n1 0\\n1\\n\", \"3\\n1 2 1\\n1 0\\n1\\n\", \"3\\n2 0 2\\n0 1\\n1\\n\", \"20\\n2 1 1 0 1 2 2 2 2 0 0 2 2 2 0 1 1 2 2 2\\n1 1 1 1 1 2 0 0 1 0 1 1 1 2 2 0 2 2 2\\n2 0 1 0 2 0 1 1 0 0 0 2 1 2 2 1 0 2\\n2 0 1 2 1 2 1 2 1 1 0 1 1 2 2 2 1\\n2 1 2 1 0 1 1 2 0 0 ...
You are given an integer $n$. You have to calculate the number of binary (consisting of characters 0 and/or 1) strings $s$ meeting the following constraints. For every pair of integers $(i, j)$ such that $1 \le i \le j \le n$, an integer $a_{i,j}$ is given. It imposes the following constraint on the string $s_i s_{i+1...
0
{"tests": "{\"inputs\": [[\"banana\", \"abn\"], [\"banana\", \"xyz\"], [\"banana\", \"an\"], [\"foos\", \"of\"], [\"string\", \"gnirts\"], [\"banana\", \"a\"], [\"bungholio\", \"aacbuoldiiaoh\"], [\"fumyarhncujlj\", \"nsejcwn\"]], \"outputs\": [[\"aaabnn\"], [\"banana\"], [\"aaannb\"], [\"oofs\"], [\"gnirts\"], [\"aaab...
Define a method that accepts 2 strings as parameters. The method returns the first string sorted by the second. ```python sort_string("foos", "of") == "oofs" sort_string("string", "gnirts") == "gnirts" sort_string("banana", "abn") == "aaabnn" ``` To elaborate, the second string defines the ordering. It is po...
0.875
{"tests": "{\"inputs\": [\"1 5 7 11 10\\n10\\n2 5 7 11 10\\n2 4\\n2 1 1 256 0\\n128 255\\n2 0 0 1 0\\n1234 5678\\n2 1 1 100 0\\n99 98\\n2 1 1 100 0\\n99 99\\n2 1 1 10000 0\\n1 0\\n2 1 2 10000 0\\n2 1\\n0 0 0 0 0\", \"1 5 7 11 10\\n10\\n2 5 5 11 10\\n2 4\\n2 1 1 256 0\\n128 255\\n2 0 0 1 0\\n1234 5678\\n2 1 1 100 0\\n99...
Nathan O. Davis is trying to capture a game and struggling to get a very rare item. This rare item can be obtained by arranging special patterns in a row on a casino slot machine. The slot machine has N reels, and pressing the button once stops the currently rotating leftmost reel. Therefore, you need to press the butt...
0
{"tests": "{\"inputs\": [\"7 11\\n1 2 2\\n1 3 1\\n2 4 2\\n2 5 2\\n2 6 1\\n6 4 1\\n3 5 1\\n3 6 1\\n4 7 2\\n5 7 2\\n6 7 1\", \"7 11\\n2 2 2\\n1 3 1\\n2 4 2\\n2 5 2\\n2 6 1\\n6 4 1\\n3 5 1\\n3 6 1\\n4 7 2\\n5 7 2\\n6 7 1\", \"7 11\\n1 2 2\\n1 3 1\\n2 4 2\\n2 5 2\\n2 6 1\\n3 4 1\\n3 5 2\\n3 6 1\\n4 7 2\\n2 7 2\\n6 7 1\", \...
Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come and go directly to each other. You can also follow several roads between any town. The course of the tournament is decided as follows. ...
0
{"tests": "{\"inputs\": [\"3 3\\n2 0 1\\n1 0 0\\n0 0 0\\n1 1\\n\", \"13 8\\n5 7 7 7 9 1 10 7\\n2 10 5 4 5 4 9 1\\n8 6 10 8 10 9 9 5\\n7 10 9 8 6 7 5 8\\n1 6 4 2 4 9 3 10\\n10 4 4 6 5 6 6 4\\n7 5 3 9 8 5 1 3\\n9 6 1 9 10 5 3 7\\n6 3 7 6 9 9 1 6\\n8 6 5 9 1 9 2 1\\n1 8 2 8 9 7 3 3\\n7 2 2 4 4 6 7 10\\n7 8 6 10 2 6 10 9\\...
Vasya has got a magic matrix a of size n × m. The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let a_{ij} be the element in the intersection of the i-th row and the j-th column. Vasya has also got a chip. Initially, the chip is in the intersec...
0
{"tests": "{\"inputs\": [\"4\\n6 3 3\\n1 2 3 2 2 2\\n6 2 4\\n1 1 2 2 2 2\\n6 5 1\\n6 5 4 3 2 1\\n4 0 4\\n4 4 4 3\\n\", \"4\\n6 3 3\\n1 2 6 2 2 2\\n6 2 4\\n1 1 2 2 2 2\\n6 5 1\\n6 5 4 3 2 1\\n4 0 4\\n4 4 4 3\\n\", \"4\\n6 3 3\\n1 2 6 2 2 2\\n6 2 4\\n1 1 2 2 2 2\\n6 5 1\\n6 5 4 1 2 1\\n4 0 4\\n4 4 4 3\\n\", \"4\\n6 3 3\\...
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color $c'$ $(1 \le c' \le n)$ turn a left sock into a ri...
0
{"tests": "{\"inputs\": [\"3 5\\n0W 1W\\n0W 2W\\n0W 2E\\n0E 1E\\n1E 2E\\naabbcdcee\\n-\\n-\\n-\\n-\\nbbaadeecc\\n3 3\\n0E 1W\\n1E 2W\\n2E 0W\\naabb\\nbbcc\\naa\\nbbbb\\ncc\\naaaa\\n3 4\\n0E 1W\\n0E 2E\\n1E 2W\\n2E 0W\\nababab\\n-\\n-\\naaabbb\\n-\\n-\\n0 0\", \"3 5\\n0W 1W\\n0W 2W\\n0W 2E\\n0E 1E\\n1E 2E\\naabbccdee\\n...
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the morning. Then, during the daytim...
0
{"tests": "{\"inputs\": [\"10 3 30000\\n00:06:54\\n00:42:06\\n03:49:45\\n04:38:35\\n05:33:30\\n05:51:46\\n10:46:34\\n14:34:59\\n14:40:06\\n14:53:13\\n\", \"1 1 86400\\n00:00:00\\n\", \"5 2 40000\\n06:30:57\\n07:27:25\\n09:10:21\\n11:05:03\\n12:42:37\\n\", \"7 4 30000\\n05:08:54\\n05:35:53\\n06:03:20\\n06:17:50\\n09:29:...
Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarp...
0
{"tests": "{\"inputs\": [\"7\\n1 2\\n2 3\\n2 4\\n2 5\\n4 6\\n6 7\", \"7\\n1 4\\n2 3\\n2 4\\n4 5\\n4 6\\n6 7\", \"7\\n1 4\\n2 3\\n2 4\\n4 5\\n7 6\\n6 7\", \"7\\n1 4\\n2 3\\n2 4\\n1 5\\n7 6\\n6 7\", \"7\\n1 4\\n2 3\\n2 4\\n1 5\\n7 6\\n6 5\", \"7\\n1 4\\n2 3\\n2 4\\n4 5\\n7 3\\n6 3\", \"7\\n1 2\\n2 3\\n4 4\\n1 5\\n7 6\\n6...
Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc. A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i. He would like to make one as follows: * Specify two non-negative integers A and B. * Pr...
0
{"tests": "{\"inputs\": [[\"BRB I need to go into a KPI meeting before EOD\"], [\"I am IAM so will be OOO until EOD\"], [\"Going to WAH today. NRN. OOO\"], [\"We're looking at SMB on SM DMs today\"], [\"OOO\"], [\"KPI\"], [\"EOD\"], [\"TBD\"], [\"TBD by EOD\"], [\"BRB I am OOO\"], [\"WAH\"], [\"IAM\"], [\"NRN\"], [\"CT...
Laura really hates people using acronyms in her office and wants to force her colleagues to remove all acronyms before emailing her. She wants you to build a system that will edit out all known acronyms or else will notify the sender if unknown acronyms are present. Any combination of three or more letters in upper ca...
0
{"tests": "{\"inputs\": [\"1 14\\n11110101110010\\n50 3\\n101\\n011\\n010\\n100\\n011\\n011\\n100\\n100\\n110\\n101\\n000\\n111\\n100\\n010\\n000\\n001\\n101\\n111\\n110\\n111\\n100\\n011\\n110\\n110\\n100\\n001\\n011\\n100\\n100\\n010\\n110\\n100\\n100\\n010\\n001\\n010\\n110\\n101\\n110\\n110\\n010\\n001\\n011\\n111\...
You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we w...
0.875
{"tests": "{\"inputs\": [[2, 5], [2, 3, 4], [9], [0], [0, 1], [1, 1, 1], [5, 6, 7, 9, 6, 9, 18, 4, 5, 15, 15, 10, 17, 7], [17, 20, 4, 15, 4, 18, 12, 14, 20, 19, 2, 14, 13, 7], [11, 13, 4, 5, 17, 4, 10, 13, 16, 13, 13], [20, 1, 6, 10, 3, 7, 8, 4], [3, 9, 9, 19, 18, 14, 18, 9], [3, 9, 9, 19, 18, 14, 18, 0]], \"outputs\":...
Write a function that calculates the *least common multiple* of its arguments; each argument is assumed to be a non-negative integer. In the case that there are no arguments (or the provided array in compiled languages is empty), return `1`. ~~~if:objc NOTE: The first (and only named) argument of the function `n` spec...
0.125
{"tests": "{\"inputs\": [\"ABRACADABRA\\n\", \"ABBBCBDB\\n\", \"AB\\n\", \"ABBCDEFB\\n\", \"THISISATEST\\n\", \"Z\\n\", \"ZZ\\n\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\n\", \"ABACBCABACACB\\n\", \"LEHLLLLLLHAFGEGLLHAFDLHHLLLLLDGGEHGGHLLLLLLLLDFLCBLLEFLLCBLLCGLEDLGGLECLDGLEHLLLGELLLEGLLLLGDLLLDALD\\n\", \"THISISTHELASTTEST\\n\...
You will receive 5 points for solving this problem. Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using t...
0
{"tests": "{\"inputs\": [\"r\\n\", \"llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrrrrrlllrrlrrrrrlrrrlrlrlrrlllllrrrrllrrlrlrrrllllrlrrlrrlrlrrll\\n\", \"llrrrrllrrlllrlrllrlrllllllrrrrrrrrllrrrrrrllrlrrrlllrrrrrrlllllllrrlrrllrrrllllrrlllrrrlrlrrlrlrllr\\n\", \"rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrr...
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order. The stones always fall to the center of Liss's inter...
0.125
{"tests": "{\"inputs\": [\"4 4\\n1 2 0\\n2 3 0\\n2 4 0\\n3 4 0\\n\", \"6 6\\n1 2 0\\n2 3 1\\n3 4 0\\n4 5 1\\n5 6 0\\n6 1 1\\n\", \"5 5\\n1 2 0\\n2 3 0\\n3 4 0\\n4 5 0\\n1 5 0\\n\", \"9 2\\n1 2 0\\n2 3 0\\n\", \"28567 13\\n28079 24675 1\\n18409 26720 1\\n980 10815 1\\n20794 16571 1\\n7376 19861 1\\n11146 706 1\\n4255 16...
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (the...
0
{"tests": "{\"inputs\": [\"79585\\n\", \"66536\\n\", \"66518\\n\", \"66529\\n\", \"66517\\n\", \"36871\\n\", \"66521\\n\", \"66549\\n\", \"66539\\n\", \"66537\\n\", \"99996\\n\", \"66547\\n\", \"96046\\n\", \"66525\\n\", \"48716\\n\", \"76\\n\", \"139\\n\", \"357\\n\", \"99993\\n\", \"27\\n\", \"75\\n\", \"66545\\n\", ...
Bob is playing a game named "Walk on Matrix". In this game, player is given an n × m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}. To reach the goal, position (n,m), player can move right or down, i.e. move from ...
0
{"tests": "{\"inputs\": [\"2\\n10 3 2\\n1 4\\n5 5\\n6 10\\n1 5\\n6 10\\n10 3 1\\n2 5\\n10 1\\n6 9\\n1 10\", \"2\\n10 3 2\\n1 4\\n5 5\\n6 10\\n1 5\\n6 10\\n10 3 1\\n4 5\\n10 1\\n6 9\\n1 10\", \"2\\n10 3 2\\n1 4\\n5 5\\n6 10\\n1 5\\n6 10\\n10 3 0\\n4 5\\n10 1\\n6 9\\n1 10\", \"2\\n10 3 2\\n1 4\\n5 5\\n6 10\\n1 4\\n6 10\\...
Read problems statements in Mandarin Chinese and Russian. Once Chef decided to divide the tangerine into several parts. At first, he numbered tangerine's segments from 1 to n in the clockwise order starting from some segment. Then he intended to divide the fruit into several parts. In order to do it he planned to se...
0
{"tests": "{\"inputs\": [\"4\\n1.00 200 1\\n1 0.50 28\\n1.00 200 2\\n1 0.75 40\\n3 0.60 100\\n1.00 50 2\\n1 0.75 40\\n3 0.60 100\\n1.00 100 2\\n3 0.50 10\\n2 0.10 20\", \"4\\n1.00 200 1\\n1 0.50 28\\n1.00 200 2\\n1 0.75 40\\n3 0.60 100\\n1.00 50 2\\n1 0.75 40\\n3 0.60 100\\n1.00 100 2\\n3 0.50 10\\n2 0.10 18\", \"4\\n1...
Chef talks a lot on his mobile phone. As a result he exhausts his talk-value (in Rokdas) very quickly. One day at a mobile recharge shop, he noticed that his service provider gives add-on plans which can lower his calling rates (Rokdas/minute). One of the plans said "Recharge for 28 Rokdas and enjoy call rates of 0.50 ...
0.25
{"tests": "{\"inputs\": [\"3\\n1\\n1\\n1\\n\", \"5\\n1\\n0\\n1\\n0\\n1\\n\", \"9\\n1\\n1\\n0\\n0\\n0\\n1\\n1\\n0\\n1\\n\", \"1\\n1\\n\", \"1\\n0\\n\", \"3\\n0\\n0\\n0\\n\", \"15\\n1\\n0\\n0\\n1\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n0\\n0\\n\", \"20\\n1\\n1\\n0\\n0\\n1\\n1\\n0\\n0\\n1\\n1\\n0\\n0\\n1\\n1\\n0\\n0\\n1\\n1...
In Morse code, an letter of English alphabet is represented as a string of some length from $1$ to $4$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1". Because there are $2^1+2^2+2^3+2^4 = 30$ strings w...
0