info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"5\\n3 6 9 12 15\\n\", \"4\\n3 7 5 2\\n\", \"1\\n1\\n\", \"16\\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082\\n\", \"18\\n341796022 486073481 86513380 593942288 60606166 627385348 7...
Karen has just arrived at school, and she has a math test today! [Image] The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
0
{"tests": "{\"inputs\": [\"9\\n5 10 4\\n4 5 20\\n2 2 3\\n1 100000007 100000008\\n1 100000007 100000009\\n1 100000007 100000008\\n1 1000000000 1000000000\\n1 1000000000 999999999\\n3 4 12\\n\", \"3\\n1 999999999 1000000000\\n1 1000000000 1000000000\\n1 1000000000 999999999\\n\", \"1\\n1 1000000000 999999999\\n\", \"1\\n...
There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them ...
0
{"tests": "{\"inputs\": [\"3\\n0 0 0\\n0 0 0\\n0 0 0\\n\", \"5\\n27 20 28 11 17\\n25 21 1 20 14\\n14 22 28 1 6\\n1 2 23 2 7\\n6 0 1 29 6\\n\", \"5\\n0 1 0 1 0\\n0 0 0 0 1\\n0 0 5 0 0\\n0 0 0 0 1\\n0 0 0 0 0\\n\", \"15\\n0 2 1 2 1 0 2 0 2 2 2 2 2 0 2\\n2 0 1 0 1 1 2 2 0 2 2 0 3 0 1\\n3 3 2 2 2 1 2 3 2 3 1 2 3 3 2\\n0 3 ...
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exac...
0.875
{"tests": "{\"inputs\": [[[54, 70, 86, 1, -2, -5, 0, 5, 78, 145, 212, 15]], [[59, 58, 57, 55, 53, 51]], [[7, 2, -3, 3, 9, 15]], [[-17, -9, 1, 9, 17, 4, -9]], [[7, 2, 3, 2, -2, 400, 802]], [[-1, 7000, 1, -6998, -13997]]], \"outputs\": [[639], [390], [30], [39], [1200], [-13994]]}", "source": "taco"}
# Task You are given a regular array `arr`. Let's call a `step` the difference between two adjacent elements. Your task is to sum the elements which belong to the sequence of consecutive elements of length `at least 3 (but as long as possible)`, such that the steps between the elements in this sequence are the sam...
0
{"tests": "{\"inputs\": [[103115104105123101118119981001098], [103115104105123101118119981001098103115104105123101118119981001098103115104105123101118119981001098], [1091011161151121151071091261051061151181081151231191201211161091041201081091191111011201011091199810010981051221051141201081151211071081091201191021181091...
## Welcome to my (amazing) kata! You are given a gigantic number to decode. Each number is a code that alternates in a pattern between encoded text and a smaller, encoded number. The pattern's length varies with every test, but the alternation between encoded text and an encoded number will always be there. Followi...
0
{"tests": "{\"inputs\": [\"3\\n#.#\\n...\\n#.#\\n\", \"4\\n##.#\\n#...\\n####\\n##.#\\n\", \"5\\n#.###\\n....#\\n#....\\n###.#\\n#####\\n\", \"5\\n#.###\\n....#\\n#....\\n....#\\n#..##\\n\", \"6\\n#.##.#\\n......\\n#.##.#\\n......\\n##.###\\n#...##\\n\", \"3\\n###\\n#.#\\n###\\n\", \"21\\n#########.###.#####.#\\n#.####...
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile: [Image] By the pieces lay a large square wooden board. The board is divided into $n^2$ cells arranged into ...
0.125
{"tests": "{\"inputs\": [\"4\\naa\\nabba\\nbbcd\\nabcde\", \"4\\nab\\nabba\\nbbcd\\nedcba\", \"4\\nb`\\nabba\\nbcbe\\nbbced\", \"4\\n`b\\nabba\\nbebe\\nbecbd\", \"4\\n`b\\naabb\\nbebe\\nbecbd\", \"4\\n`c\\naabb\\nbebe\\nbecce\", \"4\\ne`\\na`bb\\nbbee\\neddeb\", \"4\\ne`\\na`ba\\nbbee\\neddeb\", \"4\\n_f\\na`ba\\nebbe\...
RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1. <image> Figure B-1: Layout of the exchange lines A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are d...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"7\\n38 -29 87 93 39 28 -55\\n1 2\\n2 5\\n3 2\\n2 4\\n1 7\\n7 6\\n\", \"5\\n1 2 7 6 7\\n1 5\\n5 3\\n3 4\\n2 4\\n\", \"3\\n2 2 2\\n3 2\\n1 2\\n\", \"3\\n999397 999397 999397\\n2 3\\n2 1\\n\", \"5\\n1000000000 0 1000000000 0 1000000000\\n1 2\\n2 3\\n...
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. [Image] There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the ...
0
{"tests": "{\"inputs\": [[100, 2], [100, 3], [100, 4], [500, 2], [1000, 3], [100000, 4], [144, 2], [145, 2], [440, 2], [441, 2], [257, 2]], \"outputs\": [[441], [961], [81796], [625], [9216], [298116], [625], [625], [441], [625], [441]]}", "source": "taco"}
There are some perfect squares with a particular property. For example the number ```n = 256``` is a perfect square, its square root is ```16```. If we change the position of the digits of n, we may obtain another perfect square``` 625``` (square root = 25). With these three digits ```2```,```5``` and ```6``` we can ge...
0
{"tests": "{\"inputs\": [\"1\\n0 z\\n1\\n1\\n\", \"10\\n0 i\\n1 q\\n2 g\\n0 k\\n1 e\\n5 r\\n4 m\\n5 h\\n3 o\\n3 e\\n5\\n8 9 1 10 6\\n\", \"10\\n0 i\\n1 q\\n2 g\\n0 k\\n1 e\\n5 r\\n4 m\\n4 g\\n3 o\\n3 e\\n5\\n8 9 1 10 6\\n\", \"10\\n0 i\\n1 q\\n2 g\\n1 k\\n1 e\\n5 r\\n4 m\\n4 g\\n3 o\\n3 e\\n5\\n8 9 1 10 6\\n\", \"10\\n...
You are given a set of strings S. Each string consists of lowercase Latin letters. For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the followin...
0.125
{"tests": "{\"inputs\": [\"5\\n3 1 5 2 6\\n\", \"5\\n1 2 3 4 5\\n\", \"5\\n1 100 101 100 1\\n\", \"10\\n96 66 8 18 30 48 34 11 37 42\\n\", \"1\\n87\\n\", \"2\\n93 51\\n\", \"3\\n31 19 5\\n\", \"4\\n86 21 58 60\\n\", \"5\\n21 6 54 69 32\\n\", \"6\\n46 30 38 9 65 23\\n\", \"7\\n82 60 92 4 2 13 15\\n\", \"8\\n77 84 26 34 ...
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
0
{"tests": "{\"inputs\": [\"3 2\\n1\\n3\\n11\", \"3 2\\n0\\n3\\n11\", \"3 3\\n1\\n3\\n14\", \"3 2\\n0\\n4\\n11\", \"2 2\\n0\\n3\\n20\", \"3 2\\n1\\n6\\n16\", \"3 2\\n0\\n4\\n1\", \"3 1\\n0\\n3\\n11\", \"3 2\\n-2\\n4\\n11\", \"3 2\\n0\\n6\\n1\", \"3 1\\n1\\n6\\n18\", \"3 1\\n-1\\n4\\n11\", \"2 1\\n1\\n0\\n20\", \"3 2\\n1...
JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + ...
0
{"tests": "{\"inputs\": [\"3\\n1 1\\n1 2\\n1 111111111111\\n\", \"5\\n0 69\\n1 194\\n1 139\\n0 47\\n1 66\\n\", \"10\\n4 1825\\n3 75\\n3 530\\n4 1829\\n4 1651\\n3 187\\n4 584\\n4 255\\n4 774\\n2 474\\n\", \"1\\n0 1\\n\", \"1\\n999 1000000000000000000\\n\", \"10\\n1 8\\n1 8\\n9 5\\n0 1\\n8 1\\n7 3\\n5 2\\n0 9\\n4 6\\n9 4...
What are you doing at the end of the world? Are you busy? Will you save us? [Image] Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, f_{0... ∞}. f_0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know a...
0
{"tests": "{\"inputs\": [[\"3D2a5d2f\"], [\"4D1a8d4j3k\"], [\"4D2a8d4j2f\"], [\"3n6s7f3n\"], [\"0d4n8d2b\"], [\"0c3b1n7m\"], [\"7m3j4ik2a\"], [\"3A5m3B3Y\"], [\"5M0L8P1\"], [\"2B\"], [\"7M1n3K\"], [\"A4g1b4d\"], [\"111111\"], [\"4d324n2\"], [\"5919nf3u\"], [\"2n1k523n4i\"], [\"6o23M32d\"], [\"1B44n3r\"], [\"M21d1r32\"]...
Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty strings should return an empty string. The first occurrence of...
0
{"tests": "{\"inputs\": [[\"55555\"], [\"44444\"], [\"44441\"], [\"33233\"], [\"22262\"], [\"12121\"], [\"44455\"], [\"66116\"], [\"12345\"], [\"23456\"], [\"34561\"], [\"13564\"], [\"62534\"], [\"44421\"], [\"61623\"], [\"12346\"]], \"outputs\": [[50], [50], [40], [40], [40], [30], [30], [30], [20], [20], [20], [20], ...
[Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results are: | Result | Points | Rules ...
0
{"tests": "{\"inputs\": [\"1\\n4\\n\", \"1\\n87\\n\", \"3\\n1 2 1\\n\", \"9\\n72 49 39 50 68 35 75 94 56\\n\", \"2\\n93 51\\n\", \"2\\n3 1\\n\", \"8\\n77 84 26 34 17 56 76 3\\n\", \"5\\n2 6 2 1 2\\n\", \"10\\n4 2 2 4 1 2 2 4 2 1\\n\", \"7\\n2 1 2 2 2 2 2\\n\", \"6\\n1 7 3 1 6 2\\n\", \"6\\n46 30 38 9 65 23\\n\", \"9\\n...
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
0
{"tests": "{\"inputs\": [\"3\\n1 2\\n1 2\\n1 2\\n\", \"2\\n42 1337\\n13 420\\n\", \"2\\n1 1\\n0 0\\n\", \"2\\n1 1\\n1 1\\n\", \"2\\n1 1\\n0 1\\n\", \"2\\n0 1\\n0 1\\n\", \"2\\n0 0\\n0 1\\n\", \"2\\n0 0\\n0 1\\n\", \"2\\n0 0\\n0 1\\n\", \"2\\n0 1\\n1 1\\n\", \"2\\n10 34\\n17 26\\n\", \"2\\n12 19\\n39 69\\n\", \"2\\n25 2...
An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared $n$ problems; and since the platform is very popular, $998244351$ coder from all over the world is going to solve them. For each problem, the authors estimated the number of people who would solve it...
0
{"tests": "{\"inputs\": [\"3\\n3 2 3\\n4 3 2\\n3 1 3\\n1 2\\n2 3\\n\", \"5\\n3 4 2 1 2\\n4 2 1 5 4\\n5 3 2 1 1\\n1 2\\n3 2\\n4 3\\n5 3\\n\", \"5\\n3 4 2 1 2\\n4 2 1 5 4\\n5 3 2 1 1\\n1 2\\n3 2\\n4 3\\n5 4\\n\", \"4\\n4 7 3 2\\n2 3 7 2\\n1 1 2 1\\n4 3\\n1 2\\n3 2\\n\", \"7\\n1 8 3 2 6 3 2\\n2 6 6 5 4 1 9\\n6 4 7 1 5 5 2...
You are given a tree consisting of $n$ vertices. A tree is an undirected connected acyclic graph. [Image] Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color. You have to paint the vertices so that any path consisting of exactly ...
0
{"tests": "{\"inputs\": [\"3 6 1\\n3 2\", \"100001 100000 0\", \"10 10 14\\n4 3\\n2 2\\n7 3\\n9 10\\n7 9\\n8 1\\n10 10\\n5 4\\n3 4\\n2 8\\n6 4\\n4 4\\n5 8\\n9 2\", \"100101 100000 0\", \"10 10 14\\n4 3\\n2 1\\n7 3\\n9 10\\n7 9\\n8 1\\n10 10\\n5 4\\n3 4\\n2 8\\n6 4\\n4 4\\n5 8\\n9 2\", \"110101 100000 0\", \"110111 1000...
Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i-th obstacle is at (X_i,Y_i). Here, we represent the cell at the i-th row and j-th column (1 \leq i \leq H, 1 \leq j \leq W) by (i,j). There is no obstacle at (1,1), and there is a piece ...
0
{"tests": "{\"inputs\": [\"3\\n586\\n\", \"2\\n09\\n\", \"9\\n123456789\\n\", \"3\\n911\\n\", \"3\\n089\\n\", \"3\\n159\\n\", \"9\\n000000000\\n\", \"4\\n0874\\n\", \"6\\n235689\\n\", \"2\\n10\\n\", \"3\\n358\\n\", \"6\\n123456\\n\", \"1\\n0\\n\", \"4\\n0068\\n\", \"6\\n021149\\n\", \"5\\n04918\\n\", \"2\\n05\\n\", \"4...
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his cont...
0.125
{"tests": "{\"inputs\": [\"30 36 36 32 34 38\\n\", \"125 7 128 8 124 11\\n\", \"7 1 7 3 5 3\\n\", \"4 60 4 60 4 60\\n\", \"50 40 46 38 52 34\\n\", \"1 1000 1 1 1000 1\\n\", \"718 466 729 470 714 481\\n\", \"66 6 65 6 66 5\\n\", \"1 6 1 5 2 5\\n\", \"7 5 4 8 4 5\\n\", \"677 303 685 288 692 296\\n\", \"2 4 5 3 3 6\\n\", ...
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. ...
0
{"tests": "{\"inputs\": [[\"Carlos Ray Norris\", \"Carlos Ray Norris\"], [\"Carlos Ray Norris\", \"Carlos Ray\"], [\"Carlos Ray Norris\", \"Ray Norris\"], [\"Carlos Ray Norris\", \"Carlos Norris\"], [\"Carlos Ray Norris\", \"Norris\"], [\"Carlos Ray Norris\", \"Carlos\"], [\"Carlos Ray Norris\", \"Norris Carlos\"], [\"...
The objective is to disambiguate two given names: the original with another Let's start simple, and just work with plain ascii strings. The function ```could_be``` is given the original name and another one to test against. ```python # should return True if the other name could be the same person > could_be("Chuc...
0.625
{"tests": "{\"inputs\": [\"48\\n\", \"6\\n\", \"1\\n\", \"994\\n\", \"567000123\\n\", \"123830583943\\n\", \"3842529393411\\n\", \"999999993700000\\n\", \"2\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"112\\n\", \"113\\n\", \"114\\n\", \"265\\n\", \"995\\n\", \"200385\\n\", \"909383000\\n\", \"108000000057\\n\", \"38592592348...
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a^3. A tower consisting of blocks with sides a_1, a_2, ..., a_{k} has the total volume a_1^3 + a_2^3 + ...
0
{"tests": "{\"inputs\": [\"2\\n3 3\\n0 2 1\\n3 1 2 3\\n1 7\\n2 4 7\\n4 7\\n0 1 3 0 1 0 0\\n1 7\\n3 9 4 5\\n7 1 2 3 4 5 6 7\\n1 1\", \"2\\n3 3\\n0 2 1\\n3 1 2 3\\n1 7\\n2 4 7\\n4 7\\n0 1 2 0 1 0 0\\n1 7\\n3 9 4 5\\n7 1 2 3 4 5 6 7\\n1 1\", \"2\\n3 3\\n0 2 1\\n3 1 2 3\\n1 7\\n2 4 7\\n4 7\\n0 1 2 0 2 0 0\\n1 7\\n3 9 4 5\\...
Little Elephant likes lemonade. When Little Elephant visits any room, he finds the bottle of the lemonade in that room that contains the greatest number of litres of lemonade and drinks it all. There are n rooms (numbered from 0 to n-1), each contains C_{i} bottles. Each bottle has a volume (in litres). The first roo...
0.75
{"tests": "{\"inputs\": [\"8 6\\n4 5\\n3 5\\n2 5\\n1 2\\n2 8\\n6 7\\n\", \"4 6\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n3 4\\n\", \"5 7\\n1 3\\n2 4\\n4 5\\n5 3\\n2 1\\n1 4\\n3 2\\n\", \"5 9\\n1 3\\n2 4\\n4 5\\n5 3\\n2 1\\n1 4\\n3 2\\n1 5\\n2 5\\n\", \"10 10\\n6 3\\n2 9\\n9 4\\n4 5\\n10 3\\n8 3\\n10 5\\n7 6\\n1 4\\n6 8\\n\", \"1...
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed...
0.25
{"tests": "{\"inputs\": [\"3 1 1000\\n011\\n\", \"4 4 100500\\n0110\\n1010\\n0101\\n1001\\n\", \"2 0 1000\\n\", \"2 1 1000\\n11\\n\", \"5 0 13\\n\", \"5 3 19\\n10001\\n10001\\n00110\\n\", \"3 0 100500\\n\", \"4 0 100500\\n\", \"5 0 100500\\n\", \"6 0 100500\\n\", \"3 1 100501\\n101\\n\", \"4 2 100501\\n1010\\n1010\\n\"...
An n × n square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2. You are given n and the first m rows of the matrix. Print the number of special n × n matrices, such that the first m rows coincide with the given ones. As the re...
0
{"tests": "{\"inputs\": [\"9\\n5 1 3 6 8 2 9 0 10\\n\", \"5\\n1 2 4 0 2\\n\", \"8\\n3 2 0 1 0 1 2 3\\n\", \"7\\n3 2 0 1 0 1 2\\n\", \"1\\n1337\\n\", \"5\\n1 4 2 5 3\\n\", \"6\\n5 1 4 2 6 3\\n\", \"6\\n1 2 100 3 101 4\\n\", \"12\\n12 8 1 3 7 5 9 6 4 10 11 2\\n\", \"12\\n11 2 1 3 5 8 9 10 7 6 4 12\\n\", \"8\\n3 2 0 1 0 1...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
0
{"tests": "{\"inputs\": [\"6\\n0 1 0 0 0 0\\n\", \"7\\n1 1 1 1 1 1 1\\n\", \"10\\n1 0 1 1 1 0 1 0 1 0\\n\", \"7\\n0 0 1 0 0 0 1\\n\", \"30\\n1 0 0 0 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0\\n\", \"113\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood. Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights ...
0
{"tests": "{\"inputs\": [\"1\", \"0\", \"10\", \"11\", \"21\", \"101\", \"111\", \"011\", \"010\", \"110\", \"102\", \"2100\", \"2\", \"12\", \"22\", \"20\", \"001\", \"000\", \"100\", \"202\", \"201\", \"121\", \"220\", \"120\", \"112\", \"200\", \"221\", \"212\", \"122\", \"211\", \"210\", \"222\", \"0\", \"1\", \"2\...
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`. Takahashi has a sequence that is initially ...
0
{"tests": "{\"inputs\": [\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"8\\n\", \"5\\n\", \"6\\n\", \"10\\n\", \"20\\n\", \"1023\\n\", \"536870911\\n\", \"641009859\\n\", \"524125987\\n\", \"702209411\\n\", \"585325539\\n\", \"58376259\\n\", \"941492387\\n\", \"824608515\\n\", \"2691939\\n\", \"802030518\\n\", \"685146646\\...
Fox Ciel studies number theory. She thinks a non-empty set S contains non-negative integers is perfect if and only if for any $a, b \in S$ (a can be equal to b), $(a \text{xor} b) \in S$. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or). Please calculate the number of perfe...
0
{"tests": "{\"inputs\": [\"4\\nBAAAAAAAABBABAB\\n\", \"2\\nBAA\\n\", \"2\\nABA\\n\", \"2\\nAAB\\n\", \"2\\nAAA\\n\", \"2\\nBBB\\n\", \"2\\nBBB\\n\", \"2\\nAAB\\n\", \"2\\nBBB\\n\", \"2\\nAAA\\n\", \"2\\nAAA\\n\", \"2\\nAAA\\n\", \"4\\nBBBBBBBBBBBBBBB\\n\", \"4\\nBBBABBBBBABBBBB\\n\", \"4\\nBBABBBBBBBBBBBB\\n\", \"4\\nA...
You are given a rooted tree of $2^n - 1$ vertices. Every vertex of this tree has either $0$ children, or $2$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children is the left one, and the other child is the right one. Formally, you are given a perfect...
0
{"tests": "{\"inputs\": [\"1\\n17 2\\n30 26 22 21 18 16 13 12 10 8 7 6 5 4 3 0 0\\n\", \"1\\n71 2\\n100 99 98 97 96 95 94 93 92 91 90 87 86 82 79 78 76 71 70 69 68 66 64 63 62 56 55 53 52 51 50 46 43 42 39 38 37 35 33 31 30 29 22 20 19 18 11 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"1\\n67 2\\n100 99 98 9...
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. The boy has found an online judge with tasks divided by topics they cover. ...
0
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n1 3 2\\n\", \"5\\n1 2 4 5 3\\n1 5 4 2 3\\n\", \"5\\n1 2 4 5 3\\n1 2 5 4 3\\n\", \"5\\n1 5 2 4 3\\n4 3 2 5 1\\n\", \"3\\n1 2 3\\n2 3 1\\n\", \"10\\n4 7 8 1 2 3 5 9 6 10\\n6 3 8 7 10 2 1 4 5 9\\n\", \"5\\n5 3 2 4 1\\n2 4 5 1 3\\n\", \"5\\n1 3 5 4 2\\n1 4 5 3 2\\n\", \"2\\n1 2\\n2 1\...
Professor Phunsuk Wangdu has performed some experiments on rays. The setup for n rays is as follows. There is a rectangular box having exactly n holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each...
0.5
{"tests": "{\"inputs\": [\"3\\n1 1\\n1 2\\n2 1\\n\", \"4\\n1 1\\n1 2\\n2 1\\n2 2\\n\", \"1\\n233 666\\n\", \"5\\n7 7\\n5 8\\n8 5\\n4 9\\n9 4\\n\", \"10\\n100 34\\n27 17\\n17 73\\n12 60\\n53 25\\n46 31\\n61 86\\n22 91\\n82 91\\n8 41\\n\", \"2\\n5 5\\n7 2\\n\", \"2\\n5 5\\n2 7\\n\", \"2\\n5 1\\n3 4\\n\", \"2\\n2 3\\n5 1\...
There are $n$ points on the plane, $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$. You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the tri...
0.875
{"tests": "{\"inputs\": [\"2 2 3\\n000\\n000\\n\\n111\\n111\\n\", \"3 3 3\\n111\\n111\\n111\\n\\n111\\n111\\n111\\n\\n111\\n111\\n111\\n\", \"1 1 10\\n0101010101\\n\", \"1 1 1\\n0\\n\", \"1 1 1\\n1\\n\", \"3 1 1\\n1\\n\\n1\\n\\n1\\n\", \"3 1 1\\n1\\n\\n0\\n\\n1\\n\", \"1 3 1\\n1\\n1\\n1\\n\", \"1 3 1\\n1\\n0\\n1\\n\", ...
A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer nu...
0
{"tests": "{\"inputs\": [\"10 10\\nPPPPPPPPPP\\nPPPPPPPWPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\nPPPPPPPPPP\\n\", \"10 1\\n.\\nW\\nW\\nP\\nP\\n.\\n.\\n.\\nW\\nP\\n\", \"4 8\\n..PW..WW\\nWWPP.PP.\\nP...PW.P\\nP.WW...P\\n\", \"5 5\\n.....\\n..P..\\n.W.W.\\n..P..\\n.....
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size n × m. Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of ...
0.25
{"tests": "{\"inputs\": [[\"C E G\"], [\"Db F Ab\"], [\"D F# A\"], [\"Eb G Bb\"], [\"E G# B\"], [\"F A C\"], [\"F# A# C#\"], [\"Gb Bb Db\"], [\"G B D\"], [\"Ab C Eb\"], [\"A C# E\"], [\"Bb D F\"], [\"B D# F#\"], [\"C Eb G\"], [\"C# E G#\"], [\"D F A\"], [\"D# F# A#\"], [\"Eb Gb Bb\"], [\"E G B\"], [\"F Ab C\"], [\"F# A...
Check if given chord is minor or major. _____________________________________________________________ Rules: 1. Basic minor/major chord have three elements. 2. Chord is minor when interval between first and second element equals 3 and between second and third -> 4. 3. Chord is major when interval between first and ...
0.25
{"tests": "{\"inputs\": [\"3,4,5\\n5,5,8\\n4,5,4\\n5,4,3\", \"3,3,5\\n5,5,8\\n4,4,4\\n5,4,3\", \"3,4,5\\n5,5,8\\n4,5,4\\n3,4,5\", \"3,4,5\\n8,5,5\\n4,5,4\\n3,4,5\", \"3,5,5\\n6,5,8\\n4,4,5\\n5,4,3\", \"3,3,5\\n5,5,8\\n3,4,4\\n5,4,3\", \"3,4,5\\n8,5,5\\n4,5,4\\n5,4,3\", \"4,4,5\\n5,5,8\\n4,5,4\\n3,4,5\", \"3,4,5\\n5,5,8...
There is a factory that inputs the data of the side and diagonal lengths to the machine and cuts out the plastic plate. At this factory, we cut out only parallelogram molds, although they vary in size. You have been ordered by your boss to count the number of rectangles and rhombuses produced among the parallelograms t...
0.625
{"tests": "{\"inputs\": [\"35 5\\n151 -160 -292 -31 -131 174 359 42 438 413 164 91 118 393 76 435 371 -76 145 605 292 578 623 405 664 330 455 329 66 168 179 -76 996 163 531\\n\", \"1 1\\n1\\n\", \"82 8\\n-483 465 435 -789 80 -412 672 512 -755 981 784 -281 -634 -270 806 887 -495 -46 -244 609 42 -821 100 -40 -299 -6 560 ...
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: <image> A swap operation is the following sequence of actions: * choose two indexes i, j (i ≠ j); * perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp. What maximum value of function m(a) can Serej...
0
{"tests": "{\"inputs\": [\"7\\n7\\n6\\n5\\n4\\n3\\n2\\n1\\n\", \"2\\n5\\n5\\n\", \"10\\n81\\n97\\n12\\n2\\n16\\n96\\n80\\n99\\n6\\n83\\n\", \"10\\n15106\\n13599\\n69319\\n33224\\n26930\\n94490\\n85089\\n60931\\n23137\\n62868\\n\", \"10\\n5059464500\\n8210395556\\n3004213265\\n248593357\\n5644084048\\n9359824793\\n81206...
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
0
{"tests": "{\"inputs\": [\"972408\\n\", \"956022\\n\", \"54\\n\", \"448\\n\", \"68\\n\", \"941322\\n\", \"6\\n\", \"160\\n\", \"908550\\n\", \"635758\\n\", \"966\\n\", \"992164\\n\", \"924936\\n\", \"24\\n\", \"180\\n\", \"1000000\\n\", \"38\\n\", \"10\\n\", \"921566\\n\", \"999998\\n\", \"999994\\n\", \"726\\n\", \"16...
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels,...
0
{"tests": "{\"inputs\": [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]], \"outputs\": [[3], [3], [2], [3], [2], [4], [0], [1], [1], [2]]}", "source": "taco"}
Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars. He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they take twice as long. His first set of redemption pushups takes 5 mi...
0.5
{"tests": "{\"inputs\": [\"3\\n1 2 1000\\n\", \"2\\n1 1\\n\", \"30\\n6 7 7 6 7 7 7 7 7 7 7 7 7 7 7 5 7 7 7 7 2 1 5 3 7 3 2 7 5 1\\n\", \"20\\n4 4 3 4 4 4 4 4 4 4 4 3 3 2 1 4 4 3 3 3\\n\", \"3\\n1 1 2\\n\", \"200\\n11 23 6 1 15 6 5 9 8 9 13 11 7 21 14 17 8 8 12 6 18 4 9 20 3 9 6 9 9 12 18 5 22 5 16 20 11 6 22 10 5 6 8 1...
Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfect...
0
{"tests": "{\"inputs\": [\"2\\n1 2 3\\n5 4 100\\n\", \"16\\n1 1 1\\n3 4 7\\n4 5 13\\n456 123 7890123\\n1 1 1000000000\\n45 12 782595420\\n1 1000000000 1000000000\\n1 999999999 1000000000\\n1 99999 676497416\\n5 6 930234861\\n8 9 881919225\\n500000000 500000000 1000000000\\n1000000000 1000000000 1000000000\\n999999999 1...
Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = $2$, b = $3$ changes the value of a to $5$ (the value of b does not change). In a prototype...
0.75
{"tests": "{\"inputs\": [\"4 10\\n4 1 4 2 2 1 4 3 3 1\\n\", \"7 1\\n3\\n\", \"9 10\\n9 8 7 4 5 8 1 6 8 2\\n\", \"8 1\\n8\\n\", \"8 10\\n7 7 7 7 7 7 7 7 7 2\\n\", \"10 10\\n1 9 7 6 2 4 7 8 1 3\\n\", \"1000 100\\n343 745 296 856 507 192 780 459 9 193 753 28 334 871 589 105 612 751 708 129 32 628 974 641 323 596 604 759 9...
Alice is playing a game with her good friend, Marisa. There are n boxes arranged in a line, numbered with integers from 1 to n from left to right. Marisa will hide a doll in one of the boxes. Then Alice will have m chances to guess where the doll is. If Alice will correctly guess the number of box, where doll is now, ...
0
{"tests": "{\"inputs\": [\"12\\nYES\\nesYes\\ncodeforces\\nes\\nse\\nYesY\\nesYesYesYesYesYesYe\\nseY\\nYess\\nsY\\no\\nYes\\n\", \"1\\nesY\\n\", \"1\\nYesYesYesYesYesYesa\\n\", \"1\\nali\\n\", \"1\\nsYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesY\\n\", \"1\\nccf\\n\"], \"outputs\": [\"NO\\nYES\\nNO\\nYES\\nNO\\nYES...
You talked to Polycarp and asked him a question. You know that when he wants to answer "yes", he repeats Yes many times in a row. Because of the noise, you only heard part of the answer — some substring of it. That is, if he answered YesYes, then you could hear esY, YesYes, sYes, e, but you couldn't Yess, YES or se. ...
0.75
{"tests": "{\"inputs\": [\"3 2\\n3 4\\n10 20\\n100 50\\n2 500000\\n0 0\", \"3 2\\n3 4\\n13 20\\n100 50\\n2 500000\\n0 0\", \"3 2\\n3 4\\n22 20\\n100 50\\n2 500000\\n0 0\", \"3 1\\n3 4\\n10 20\\n100 50\\n3 500000\\n0 0\", \"3 2\\n3 4\\n13 20\\n100 50\\n4 500000\\n0 0\", \"3 2\\n3 4\\n10 20\\n100 52\\n2 500000\\n0 0\", \...
Bamboo Blossoms The bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his travel to Tsukuba. He liked the flower so much that he was tempted to make a garden where the bamboos bloom annually. Dr. ACM started resea...
0
{"tests": "{\"inputs\": [\"2 4\", \"1 8\", \"5 6\", \"1 0\", \"9 6\", \"4 13\", \"9 3\", \"6 1\", \"2 13\", \"7 1\", \"2 29\", \"17 2\", \"20 2\", \"21 1\", \"1 3\", \"2 2\", \"2 22\", \"17 1\", \"15 1\", \"33 1\", \"27 1\", \"11 1\", \"2 25\", \"1 1\", \"29 1\", \"61 1\", \"9 17\", \"5 1\", \"13 1\", \"32 1\", \"28 1\...
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the pane...
0
{"tests": "{\"inputs\": [\"3 3\\n100 100 100\\n100 1 100\\n100 100 100\\n\", \"4 5\\n87882 40786 3691 85313 46694\\n28884 16067 3242 97367 78518\\n4250 35501 9780 14435 19004\\n64673 65438 56977 64495 27280\\n\", \"3 3\\n3 1 2\\n3 2 0\\n2 3 2\\n\", \"3 3\\n1 10 1\\n1 10 1\\n1 10 1\\n\", \"3 3\\n0 0 0\\n0 10000 0\\n0 0 ...
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column. Iahub starts with ...
0
{"tests": "{\"inputs\": [[[\"A\", \"B\", \"A\"]], [[\"A\", \"B\", \"C\"]], [[\"A\", \"B\", \"B\", \"A\"]], [[\"A\", \"A\", \"A\", \"A\"]], [[\"A\"]], [[\"A\", \"A\", \"A\", \"BBBBBBBB\"]], [[\"A\", \"B\", \"C\", \"C\"]], [[]], [[\"B\", \"C\", \"\", \"\"]]], \"outputs\": [[\"A\"], [null], [null], [\"A\"], [\"A\"], [\"A\...
Goal Given a list of elements [a1, a2, ..., an], with each ai being a string, write a function **majority** that returns the value that appears the most in the list. If there's no winner, the function should return None, NULL, nil, etc, based on the programming language. Example majority(["A", "B", "A"]) returns "A"...
0
{"tests": "{\"inputs\": [\"10 12\\nsin im gye gap eul byeong jeong mu gi gyeong\\nyu sul hae ja chuk in myo jin sa o mi sin\\n14\\n1\\n2\\n3\\n4\\n10\\n11\\n12\\n13\\n73\\n2016\\n2017\\n2018\\n2019\\n2020\\n\", \"1 1\\na\\na\\n1\\n1\\n\", \"10 12\\nsin im gye gap eul byeong jeong mu gi gyeong\\nyu sul hae ja chuk in my...
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences of $n$ strings $s_1, s_2, s_3, \ldots, s_{n}$ and $m$ strings $t_1, t_2, t_3...
0.75
{"tests": "{\"inputs\": [\"1\\n2 3 1\\n2 3 1\\n2\\n\", \"3\\n1 2 3 4 5 6 7 8 9\\n1 2 3\\n4 5 9\\n6 7 8\\n5\\n\", \"2\\n6 4 5 1 3 2\\n6 1 3\\n4 5 2\\n6\\n\", \"5\\n5 3 2 7 12 9 4 14 1 10 8 13 6 15 11\\n5 3 9\\n2 7 12\\n4 10 15\\n14 8 13\\n1 6 11\\n13\\n\", \"3\\n2 9 5 8 7 1 3 6 4\\n2 5 1\\n9 7 6\\n8 3 4\\n9\\n\", \"6\\n...
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and a...
0
{"tests": "{\"inputs\": [[\"2017-01-01\"], [\"2018-12-24\"], [\"2018-12-31\"], [\"2019-01-01\"], [\"2016-02-29\"], [\"2015-12-29\"], [\"2024-12-31\"], [\"2025-01-05\"], [\"2025-01-06\"], [\"1995-12-31\"], [\"1996-01-01\"], [\"1999-12-31\"], [\"2000-01-02\"], [\"2000-01-03\"], [\"2016-12-25\"], [\"2016-12-26\"], [\"2017...
According to ISO 8601, the first calendar week (1) starts with the week containing the first thursday in january. Every year contains of 52 (53 for leap years) calendar weeks. **Your task is** to calculate the calendar week (1-53) from a given date. For example, the calendar week for the date `2019-01-01` (string) sho...
0
{"tests": "{\"inputs\": [\"4 3 7\\n7 4 17\\n3 0 8\\n11 2 0\\n13 3 5\\n3 1\\n2 1\\n4 3\\n\", \"4 3 7\\n7 4 17\\n3 0 8\\n11 2 0\\n13 3 5\\n3 1\\n2 1\\n4 1\\n\", \"4 3 7\\n7 4 17\\n3 0 8\\n11 2 0\\n14 3 5\\n3 1\\n2 1\\n4 3\\n\", \"10 10 2\\n2 1 1615\\n2 1 1326\\n0 0 3880\\n2 0 1596\\n1 2 4118\\n0 0 4795\\n0 1 814\\n0 0 45...
You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer $n$ castles of your opponent. Let's describe the game process in detail. Initially you control an army of $k$ warriors. Your enemy controls $n$ castles; to conquer the $i$-th c...
0
{"tests": "{\"inputs\": [\"zimxucbrzojfqvizcopkplrpnvihveqpgvzszkubftoozrydxijokjxfhdfjracjonqupmnhadtsotxrxmwgno\\n51\\n\", \"geovcaxzjyhxbpnbkbsxfpkyofopxquzzxeigdflfumisevzsjdywehxconimkkbvjyxbqlnmaphvnngcjqoefqkfzmiruubbcmv\\n24\\n\", \"jeliuewohkqtghdneuuhcputwiddnmkbhhnlxxbfjunhcd\\n50\\n\", \"aaaaaaaaaaaaaaaaaaa...
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to l...
0
{"tests": "{\"inputs\": [\"4\\n3 6 2 3\\n5\\n3 12\\n7 9\\n4 14\\n1 10\\n8 7\\n\", \"4\\n3 5 2 3\\n5\\n3 12\\n7 9\\n4 14\\n1 10\\n8 7\\n\", \"4\\n3 5 2 3\\n3\\n3 12\\n7 9\\n4 14\\n1 10\\n8 7\\n\", \"4\\n3 5 2 3\\n5\\n3 12\\n2 9\\n4 14\\n1 7\\n8 7\\n\", \"4\\n3 5 2 3\\n5\\n3 12\\n2 9\\n4 14\\n1 7\\n8 13\\n\", \"4\\n3 5 2...
Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of $n$ heroes, the strength of the $i$-th hero is equal to $a_i$. According to the rules of th...
0.375
{"tests": "{\"inputs\": [\"3\\n1 3\\n100000 100000\\n2 2\\n\", \"3\\n1 5\\n100000 100000\\n2 2\\n\", \"3\\n1 3\\n100000 100000\\n3 2\\n\", \"3\\n2 3\\n100000 100000\\n3 2\\n\", \"3\\n2 4\\n100010 100100\\n2 2\\n\", \"3\\n1 6\\n100000 100000\\n3 2\\n\", \"3\\n1 3\\n100000 100100\\n2 2\\n\", \"3\\n1 6\\n100000 100001\\n3...
You are given a special jigsaw puzzle consisting of $n\cdot m$ identical pieces. Every piece has three tabs and one blank, as pictured below. $\{3$ The jigsaw puzzle is considered solved if the following conditions hold: The pieces are arranged into a grid with $n$ rows and $m$ columns. For any two pieces that shar...
0.875
{"tests": "{\"inputs\": [[0, 1], [18018018, 80000000000], [1, 1], [1, 2], [1, 3], [1554, 70]], \"outputs\": [[\"0.0\"], [\"0.(0)(2)5(2)5(2)5\"], [\"1.0\"], [\"0.5\"], [\"0.(3)\"], [\"22.2\"]]}", "source": "taco"}
Write ```python function repeating_fractions(numerator, denominator) ``` that given two numbers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part has repeated digits, replace those digits with a single digit in parentheses. For example: ```python re...
0
{"tests": "{\"inputs\": [\"13 6\\n7 75\\n8 84\\n16 95\\n29 21\\n49 33\\n54 56\\n55 80\\n65 63\\n67 50\\n73 47\\n80 26\\n82 74\\n86 77\\n\", \"3 2\\n2 6\\n3 9\\n6 8\\n\", \"19 2\\n1 73\\n2 96\\n3 24\\n5 96\\n11 13\\n14 96\\n16 31\\n17 60\\n34 69\\n39 41\\n60 40\\n61 96\\n66 7\\n67 56\\n68 28\\n73 12\\n74 81\\n78 77\\n95...
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness e...
0
{"tests": "{\"inputs\": [\"4\\n1 1\\n221 2\\n177890 2\\n998244353 1\\n\", \"1\\n88884444 1\\n\", \"1\\n9994444 1\\n\", \"1\\n9994444 1\\n\", \"1\\n88884444 1\\n\", \"1\\n9994444 2\\n\", \"1\\n88884444 2\\n\", \"1\\n10739757 1\\n\", \"4\\n1 1\\n221 2\\n177890 1\\n998244353 1\\n\", \"1\\n10862575 2\\n\", \"1\\n12678347 2...
It is a simplified version of problem F2. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$). You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful. A number is called $k$-beautiful if its decimal representation having no leading...
0
{"tests": "{\"inputs\": [\"4\\n4\\n1 2 10 100\\n4\\n100 100 100 1\\n5\\n5 1 1 1 8\\n6\\n1 2 3 6 5 6\\n\", \"4\\n4\\n0 2 10 100\\n4\\n100 000 100 1\\n5\\n5 2 1 1 3\\n6\\n1 4 4 3 5 12\\n\", \"4\\n4\\n1 2 10 100\\n4\\n100 100 100 1\\n5\\n5 1 1 1 8\\n6\\n1 2 2 3 5 6\\n\", \"4\\n4\\n0 2 14 100\\n4\\n100 000 100 1\\n5\\n5 2 ...
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once: * You go through the heaps from the 3-rd heap to the n-th heap, in this order. * Let i be the number of the current heap. * You can choose a number d (0 ≤ 3 ⋅...
0
{"tests": "{\"inputs\": [[\"Hi everybody!\", [\" \", \"!\"]], [\"(1+2)*6-3^9\", [\"+\", \"-\", \"(\", \")\", \"^\", \"*\"]], [\"Solve_this|kata-very\\\\quickly!\", [\"!\", \"|\", \"\\\\\", \"_\", \"-\"]], [\"\", []], [\"\"], [\"some strange string\"], [\"1_2_3_huhuh_hahaha\", [\"_\"]], [\"((1+2))*(6-3)^9\", [\"+\", \"-...
Your task is to write function which takes string and list of delimiters as an input and returns list of strings/characters after splitting given string. Example: ```python multiple_split('Hi, how are you?', [' ']) => ['Hi,', 'how', 'are', 'you?'] multiple_split('1+2-3', ['+', '-']) => ['1', '2', '3'] ``` List of del...
0
{"tests": "{\"inputs\": [\"5 3\\n0 2 4\\n1 3 1\\n0 8 3\\n0 20 10\\n1 5 5\\n\", \"5 2\\n1 15 2\\n1 11 2\\n0 17 2\\n0 16 1\\n1 18 2\\n\", \"6 2\\n1 17 3\\n1 6 1\\n0 4 2\\n1 10 1\\n1 7 3\\n1 5 1\\n\", \"7 2\\n1 14 1\\n1 9 2\\n0 6 3\\n0 20 2\\n0 4 2\\n0 3 1\\n0 9 2\\n\", \"8 2\\n0 20 3\\n1 5 2\\n1 4 1\\n1 7 1\\n0 1 3\\n1 5...
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. [Image] One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of h_{i} centimeter...
0
{"tests": "{\"inputs\": [\"90081 33447 66380 6391049189\", \"2 5 6 1\", \"90081 33447 77758 6391049189\", \"2 9 7 0\", \"4 1 3 5\", \"90081 33447 77758 2284871002\", \"6 1 2 17\", \"121980 33447 90629 11295524182\", \"4 1 1 5\", \"111605 33447 77758 2284871002\", \"11 1 2 17\", \"4 1 1 7\", \"111605 33447 14069 2284871...
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows: * The beauty of the tower is the sum of the scores of the N layers, where the sco...
0.125
{"tests": "{\"inputs\": [[\"I miss you!\"], [\"u want to go to the movies?\"], [\"Can't wait to see youuuuu\"], [\"I want to film the bayou with you and put it on youtube\"], [\"You should come over Friday night\"], [\"You u youville utube you youyouyou uuu raiyou united youuuu u you\"]], \"outputs\": [[\"I miss your s...
Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you take his phone and change the autocorrect options so that every time ...
0.125
{"tests": "{\"inputs\": [\"5 2\", \"7 2\", \"10 2\", \"2 2\", \"1 2\", \"4 3\", \"8 2\", \"6 2\", \"7 4\", \"3 3\", \"14 4\", \"4 15\", \"18 4\", \"8 15\", \"17 4\", \"17 3\", \"17 2\", \"9 53\", \"7 27\", \"10 4\", \"7 3\", \"5 4\", \"14 2\", \"19 2\", \"17 7\", \"12 4\", \"29 4\", \"11 2\", \"14 27\", \"20 4\", \"26 ...
prison There are an infinite number of prisoners. Initially, the prisoners are numbered 0, 1, 2, .... Do the following N times: * Release the 0th prisoner and execute the k, 2k, 3k, ... th prisoners. * Then renumber the remaining prisoners. At this time, the prisoners with the smallest original numbers are numbered ...
0
{"tests": "{\"inputs\": [\"4 3\\nxy 4 4\\nxz 1 2\\nyz 2 3\\n4 5\\nxy 1 1\\nxy 3 3\\nxz 3 2\\nyz 2 1\\nyz 3 3\\n0 0\", \"4 3\\nxy 4 4\\nxz 1 2\\nyz 2 3\\n4 5\\nxy 1 1\\nxy 3 3\\nxz 3 1\\nyz 2 1\\nyz 3 3\\n0 0\", \"4 3\\nxy 4 3\\nxz 1 2\\nyz 2 3\\n4 5\\nxy 1 1\\nwy 3 3\\nxz 3 2\\nyz 2 1\\nyz 3 3\\n0 0\", \"5 3\\nxy 4 3\\...
There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure. <image> Then, as shown in the figure above (right), make a hole that penetrates horizontally or vertically from the marked surface to the opposite surface. You...
0.25
{"tests": "{\"inputs\": [\"10\\n148 134\\n145 140\\n105 144\\n196 199\\n195 166\\n110 175\\n140 198\\n112 188\\n147 145\\n153 196\\n\", \"1\\n3 5\\n\", \"10\\n9 9\\n-5 2\\n-2 9\\n0 6\\n6 7\\n-1 -10\\n-8 6\\n3 6\\n-3 -9\\n0 4\\n\", \"4\\n1000000000 -1000000000\\n-1000000000 1000000000\\n-200000000 200000000\\n200000000 ...
As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that. Let's consider a set of fun...
0
{"tests": "{\"inputs\": [\"3\\n1 4\\n2 5\\n3 6\\n\", \"6\\n3 2\\n5 11\\n7 12\\n6 9\\n8 4\\n1 10\\n\", \"19\\n30 27\\n6 38\\n10 28\\n20 5\\n14 18\\n32 2\\n36 29\\n12 1\\n31 24\\n15 4\\n35 11\\n3 7\\n21 17\\n25 19\\n16 8\\n23 22\\n37 33\\n13 9\\n34 26\\n\", \"4\\n4 2\\n6 8\\n5 1\\n3 7\\n\", \"17\\n11 12\\n17 22\\n34 7\\n...
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 a_{i}-th chair, and his girlfriend, sitting on the b_{i}-th chair. The chai...
0
{"tests": "{\"inputs\": [\"4\\nabac\\n3\\n2 1 0\\nabc\\n1\\n0\\nabba\\n3\\n1 0 1\\necoosdcefr\\n10\\n38 13 24 14 11 5 3 24 17 0\\n\", \"1\\nabac\\n3\\n2 1 0\\n\", \"1\\ncbba\\n2\\n0 0\\n\", \"1\\nzbb\\n2\\n0 0\\n\", \"2\\naccccccc\\n1\\n0\\naaaaac\\n3\\n0 0 0\\n\", \"1\\naaad\\n3\\n0 0 0\\n\", \"1\\naaabb\\n3\\n0 0 0\\...
Polycarp wrote on the board a string $s$ containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string $s$, and he rewrote the remaining letters in any order. As a result, he got some new string $t$. You have to find it with s...
0
{"tests": "{\"inputs\": [\"10 5 100\\n64 90 3 94 96 97 52 54 82 31\\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\\n6 8\\n8 3\\n3 9\\n2 3\\n10 3\\n\", \"10 5 100\\n48 73 30 46 95 19 98 73 94 24\\n501216 675859 843572 565104 879875 828759 80776 766980 213551 492652\\n1 2\\n6 5\\n7 6\\n10 3\\n8 1\...
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if...
0.375
{"tests": "{\"inputs\": [\"4\\n1 1 2\\n2 10 4\\n5 2 3\\n3 2 2\\n\", \"5\\n1 1000000000 999999998\\n1 1000000000 999999999\\n1 1000000000 1000000000\\n1000000000 1000000000 2\\n1000000000 1000000000 1000000000\\n\", \"1\\n999999999 1000000000 2\\n\", \"1\\n999999929 999999937 2\\n\", \"1\\n1000000000 999999999 30\\n\", ...
You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor. You must paint a fence which consists of $10^{100}$ planks in two colors in the following way (suppose planks are numbered fro...
0
{"tests": "{\"inputs\": [\"110\\n\", \"010\\n\", \"0001111\\n\", \"0111001100111011101000\\n\", \"0\\n\", \"1\\n\", \"0000000000000000\\n\", \"0100000001000001\\n\", \"0000100010001110\\n\", \"1001101000001101\\n\", \"0010000110000100\\n\", \"1111101000110110\\n\", \"1111111111111010\\n\", \"1111111111111111\\n\", \"00...
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems. Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the foll...
0
{"tests": "{\"inputs\": [\"6\\n58376259 643910770 5887448 757703054 544067926 902981667\\n\", \"16\\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082\\n\", \"7\\n941492387 72235422 449924898 783332532 378192988 ...
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
0
{"tests": "{\"inputs\": [\"1\\n5\", \"1\\n0\", \"1\\n1\", \"1\\n2\", \"1\\n4\", \"1\\n8\", \"1\\n13\", \"1\\n6\", \"1\\n25\", \"1\\n9\", \"1\\n45\", \"1\\n14\", \"1\\n24\", \"1\\n27\", \"1\\n12\", \"1\\n10\", \"1\\n11\", \"1\\n19\", \"1\\n17\", \"1\\n22\", \"1\\n48\", \"1\\n68\", \"1\\n32\", \"1\\n35\", \"1\\n61\", \"1...
If you draw a few infinitely long straight lines on an infinitely wide plane, this plane will be divided into several areas. For example, if you draw a straight line, the plane will be divided into two areas. Even if you draw the same number of straight lines, the number of areas obtained will differ depending on how y...
0.625
{"tests": "{\"inputs\": [\"3 3\\n..#\\n#..\\n...\\n\", \"10 37\\n.....................................\\n...#...####...####..###...###...###..\\n..#.#..#...#.##....#...#.#...#.#...#.\\n..#.#..#...#.#.....#...#.#...#.#...#.\\n.#...#.#..##.#.....#...#.#.###.#.###.\\n.#####.####..#.....#...#..##....##...\\n.#...#.#...#.#....
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repe...
0.5
{"tests": "{\"inputs\": [\"0\\n(a*(1*b))\\n(1^a)\\n(-(-a*-b)*a)\\nca^(b^((^d)))\\n.\", \"0\\n(a*(1*b))\\n(1^a)\\n(-(-b*-b)*a)\\nca^(b^((^d)))\\n.\", \"0\\n(a*(1*b))\\n(0^a)\\n(-(-b*-b)*a)\\nca^(b^((^e)))\\n.\", \"0\\n(a*(0*b))\\n(1^a)\\n(-(-a*-b)*a)\\n(a^(b^(c^d)))\\n.\", \"0\\na(*(1*c))\\n(1^a)\\n(-(-b*-b)*a)\\nca)(b^...
Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `*` `(` `)`, start symbol <E> and the following production rule: > <E>...
0
{"tests": "{\"inputs\": [\"5\\n4\\nRLRL\\n6\\nLRRRRL\\n8\\nRLLRRRLL\\n12\\nLLLLRRLRRRLL\\n5\\nRRRRR\\n\", \"1\\n27\\nLLLLRRLRLRRRRLRLLLLLLLLLLLL\\n\", \"1\\n31\\nLLLLRRLRLRRRRLRLLLLLLRRRRLLLLLL\\n\", \"1\\n27\\nLLLLRRLRRLRLLLLLLRRRRLLLLLL\\n\", \"1\\n28\\nLLLLLLLLLLLLLLLRRRRLRRLLRLRL\\n\", \"1\\n27\\nLLLLRRLRRLRLLLLLLR...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
0
{"tests": "{\"inputs\": [\"4\\n1 1\\n1 1\\n1 1\\n1 1\\n\", \"3\\n5 5\\n3 3\\n1 1\\n\", \"3\\n5 5\\n3 3\\n2 2\\n\", \"3\\n2 3\\n1 4\\n1 4\\n\", \"6\\n1 5\\n2 4\\n1 1\\n1 1\\n1 1\\n1 1\\n\", \"3\\n1 4\\n2 2\\n1 1\\n\", \"5\\n1 3\\n2 5\\n3 4\\n1 2\\n1 9\\n\", \"2\\n3 3\\n3 3\\n\", \"1\\n1 1\\n\", \"10\\n9 9\\n5 5\\n1 1\\n...
Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2n. Unlike Arthur, Sasha understood the topic...
0
{"tests": "{\"inputs\": [\"8 10 8\\n1 1 10\\n1 4 13\\n1 7 1\\n1 8 2\\n2 2 0\\n2 5 14\\n2 6 0\\n2 6 1\\n\", \"3 2 3\\n1 1 2\\n2 1 1\\n1 1 5\\n\", \"1 10 10\\n1 8 1\\n\", \"3 4 5\\n1 3 9\\n2 1 9\\n1 2 8\\n\", \"10 500 500\\n2 88 59\\n2 470 441\\n1 340 500\\n2 326 297\\n1 74 45\\n1 302 273\\n1 132 103\\n2 388 359\\n1 97 6...
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
0
{"tests": "{\"inputs\": [\"4 2\\n4\\n3\\n7\\n5\\n0 0\", \"4 2\\n1\\n6\\n4\\n5\\n0 0\", \"4 2\\n8\\n3\\n10\\n5\\n0 0\", \"4 2\\n4\\n3\\n7\\n1\\n0 0\", \"4 2\\n4\\n1\\n14\\n3\\n0 0\", \"4 2\\n8\\n3\\n16\\n5\\n0 0\", \"4 2\\n4\\n3\\n11\\n1\\n0 0\", \"4 2\\n9\\n5\\n16\\n5\\n0 0\", \"4 2\\n2\\n2\\n1\\n5\\n0 0\", \"4 2\\n1\\...
One day, the teacher came up with the following game. The game uses n cards with one number from 1 to 10 and proceeds as follows. 1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal...
0
{"tests": "{\"inputs\": [\"3 6 2 3 3\\n1 2 1 3\\n1 4 3 4\\n1 2 2 3\\n\", \"1 1 1 1 1\\n1 1 1 1\\n\", \"100000000 100000000 100000000 100000000 1\\n100000000 100000000 100000000 1\\n\", \"100000000 100000000 100000000 100000000 1\\n100000000 100000000 100000000 1\\n\", \"1 1 1 1 1\\n1 1 1 1\\n\", \"1 0 1 1 1\\n1 1 1 1\\...
You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room. The bu...
0.125
{"tests": "{\"inputs\": [\"2 3 3\\n2 2\\nRLR\\nLUD\", \"4 3 5\\n2 2\\nUDRRR\\nLLDTD\", \"2 6 11\\n2 1\\nRLDRRUDDLRL\\nURRDRLLDLRD\", \"2 6 3\\n2 2\\nRLR\\nLUD\", \"4 1 5\\n2 2\\nUDRRR\\nLLDTD\", \"4 1 5\\n0 2\\nUDRRR\\nLLDTD\", \"4 1 5\\n0 2\\nUDRRR\\nDTDLL\", \"1 1 5\\n0 2\\nUDRRR\\nDTDLL\", \"1 1 5\\n-1 2\\nUDRRR\\nD...
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a st...
0
{"tests": "{\"inputs\": [\"3\\n8 4 1\\n2\\n2 3\\n1 2\\n\", \"6\\n1 2 4 8 16 32\\n4\\n1 6\\n2 5\\n3 4\\n1 2\\n\", \"6\\n1 2 4 12 16 32\\n4\\n1 6\\n2 5\\n3 4\\n1 2\\n\", \"3\\n6 4 1\\n2\\n2 3\\n1 2\\n\", \"6\\n0 2 4 12 16 32\\n4\\n2 6\\n2 5\\n3 4\\n1 2\\n\", \"6\\n0 2 4 12 16 32\\n4\\n2 3\\n2 5\\n3 4\\n1 2\\n\", \"3\\n8 ...
For an array $b$ of length $m$ we define the function $f$ as $ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $ where $\oplus$ is bitwise exclusive OR. For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(...
0.125
{"tests": "{\"inputs\": [\"2\\n2\\n2\", \"4\\n0\\n4\\n2\\n8\", \"2\\n2\\n11\", \"2\\n2\\n0\", \"4\\n0\\n4\\n2\\n10\", \"2\\n2\\n22\", \"2\\n1\\n0\", \"4\\n1\\n4\\n2\\n10\", \"2\\n2\\n9\", \"4\\n1\\n4\\n0\\n10\", \"2\\n1\\n9\", \"4\\n1\\n4\\n0\\n12\", \"2\\n0\\n9\", \"2\\n0\\n15\", \"2\\n0\\n21\", \"4\\n0\\n4\\n4\\n8\",...
Now I have a card with n numbers on it. Consider arranging some or all of these appropriately to make numbers. Find the number obtained by adding all the numbers created at this time. For example, if you have 1 and 2, you will get 4 numbers 1, 2, 12, 21 so the total number is 36. Even if the same numbers are produced ...
0
{"tests": "{\"inputs\": [[\"a\"], [\"stress\"], [\"moonmen\"], [\"\"], [\"abba\"], [\"aa\"], [\"~><#~><\"], [\"hello world, eh?\"], [\"sTreSS\"], [\"Go hang a salami, I'm a lasagna hog!\"]], \"outputs\": [[\"a\"], [\"t\"], [\"e\"], [\"\"], [\"\"], [\"\"], [\"#\"], [\"w\"], [\"T\"], [\",\"]]}", "source": "taco"}
Write a function named `first_non_repeating_letter` that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input `'stress'`, the function should return `'t'`, since the letter *t* only occurs once in the string, and occurs first in the string. ...
0
{"tests": "{\"inputs\": [\"5\\nRURUU\\n-2 3\\n\", \"4\\nRULR\\n1 1\\n\", \"3\\nUUU\\n100 100\\n\", \"6\\nUDUDUD\\n0 1\\n\", \"100\\nURDLDDLLDDLDDDRRLLRRRLULLRRLUDUUDUULURRRDRRLLDRLLUUDLDRDLDDLDLLLULRURRUUDDLDRULRDRUDDDDDDULRDDRLRDDL\\n-59 -1\\n\", \"8\\nUUULLLUU\\n-3 0\\n\", \"9\\nUULUURRUU\\n6379095 -4\\n\", \"5\\nDUU...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move from $(x, y)$ to $(x - 1, y)$; R — move from $(x, y)$ to $(x + 1...
0
{"tests": "{\"inputs\": [\"7\\n576460752303423487 2\\n82 9\\n101 104\\n10 21\\n31 10\\n0 1\\n10 30\\n\", \"1\\n128817972817282999 327672410994637530\\n\", \"66\\n7 0\\n5 7\\n1 3\\n3 2\\n3 5\\n0 6\\n1 2\\n0 7\\n4 5\\n4 7\\n5 1\\n2 0\\n4 0\\n0 5\\n3 6\\n7 3\\n6 0\\n5 2\\n6 6\\n1 7\\n5 6\\n2 2\\n3 4\\n2 1\\n5 3\\n4 6\\n6 ...
In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns: * Replace b with b - ak. Number k can be chosen by...
0
{"tests": "{\"inputs\": [\"4\\n8 2\\n()(())()\\n10 3\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n\", \"4\\n8 2\\n()(())()\\n10 3\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n\", \"4\\n8 2\\n)())(()(\\n10 3\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n\", \"4\\n8 2\\n)())(()(\\n10 1\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n\", \"4\\n8 3\\n)())(()...
You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence $s=s_{1}s_{2}\dots s_{n}$ of length $n$. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choose any consecutive substring of $s$ and reverse it. In othe...
0.375
{"tests": "{\"inputs\": [\"0\\n\", \"-1\\n\", \"1\\n\", \"-2\\n\", \"-4\\n\", \"-3\\n\", \"-5\\n\", \"-7\\n\", \"-6\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"7\\n\", \"5\\n\", \"9\\n\", \"17\\n\", \"25\\n\", \"8\\n\", \"-10\\n\", \"-15\\n\", \"-9\\n\", \"10\\n\", \"6\\n\", \"12\\n\", \"16\\n\", \"11\\n\", \"13\\n\", \"-11\...
In this problem you have to solve a simple classification task: given an image, determine whether it depicts a Fourier doodle. You are given a set of 50 images with ids 1 through 50. You are also given a text file labels.txt containing the labels for images with ids 1 through 20, which comprise the learning data set....
0
{"tests": "{\"inputs\": [\"4\\nab\\nbc\\nca\\nd\\n\", \"26\\nhw\\nwb\\nba\\nax\\nxl\\nle\\neo\\nod\\ndj\\njt\\ntm\\nmq\\nqf\\nfk\\nkn\\nny\\nyz\\nzr\\nrg\\ngv\\nvc\\ncs\\nsi\\niu\\nup\\nph\\n\", \"3\\nabcd\\nefg\\ncdefg\\n\", \"20\\nckdza\\nw\\ntvylck\\nbqtv\\ntvylckd\\nos\\nbqtvy\\nrpx\\nzaj\\nrpxebqtvylckdzajfmi\\nbq...
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
0
{"tests": "{\"inputs\": [\"5\\n5 4 3 2 1\\n\", \"3\\n1 2 3\\n\", \"1\\n1\\n\", \"10\\n5 1 6 2 8 3 4 10 9 7\\n\", \"100\\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16...
You are given a permutation $p_1, p_2, \ldots, p_n$. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment $1,2,\ldots, k$, in other words in the end there should be an integer $i$, $1 \leq i \leq n-k+1$ such that $p_i = 1, p_{i...
0
{"tests": "{\"inputs\": [[\"len(list)\"], [\"string\"], [\"\"], [\"def f(x\"], [\")(\"], [\"(a(b)c()d)\"], [\"f(x[0])\"]], \"outputs\": [[{\"3\": 8}], [{}], [{}], [false], [false], [{\"0\": 9, \"2\": 4, \"6\": 7}], [{\"1\": 6}]]}", "source": "taco"}
Write a function which outputs the positions of matching bracket pairs. The output should be a dictionary with keys the positions of the open brackets '(' and values the corresponding positions of the closing brackets ')'. For example: input = "(first)and(second)" should return {0:6, 10:17} If brackets cannot be pair...
0
{"tests": "{\"inputs\": [\"3\\n1 1000000000\\n999999999 1000000000\\n1000000000 1000000000\\n4\\n1 2\\n1 2\\n2 3\\n1 3\\n\", \"2\\n304 54\\n88203 83\\n1\\n1 2\\n\", \"20\\n4524 38\\n14370 10\\n22402 37\\n34650 78\\n50164 57\\n51744 30\\n55372 55\\n56064 77\\n57255 57\\n58862 64\\n59830 38\\n60130 68\\n66176 20\\n67502 ...
Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos User ainta, who lives in a 2D world, is going to post a video as well. There are n dominoes on a 2D Cartesian plane. i-th domino (1 ≤ i ≤ n) can be represented a...
0.125
{"tests": "{\"inputs\": [\"3\\nAZAMON APPLE\\nAZAMON AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMON APPLE\\nAZAMON AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMON APPLE\\nAZOMAN AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMNO ELPPA\\nAZAMON AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMON APPLE\\nAZAMON...
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better ...
0
{"tests": "{\"inputs\": [\"aabc\\n\", \"aabcd\\n\", \"u\\n\", \"ttttt\\n\", \"xxxvvvxxvv\\n\", \"wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww\\n\", \"aabbcccdd\\n\", \"baaab\\n\", \"aaabbbhhlhlugkjgckj\\n\", \"aabcc\\n\", \"bbbcccddd\\n\", \"zzzozzozozozoza\\n\", ...
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
0
{"tests": "{\"inputs\": [\"4 5\\n3 1 7 5\\n\", \"3 10\\n100 100 100\\n\", \"10 9\\n4 5 5 7 5 4 5 2 4 3\\n\", \"3 3\\n7 12 8\\n\", \"70 3956\\n246 495 357 259 209 422 399 443 252 537 524 299 538 234 247 558 527 529 153 366 453 415 476 410 144 472 346 125 299 321 363 334 297 316 346 309 497 281 163 396 482 254 447 318 31...
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You may perform the following operation on this sequence: choose any element and either increase or decrease it by one. Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can ...
0
{"tests": "{\"inputs\": [\"4\\n1\\n0\\n4\\n3\", \"8\\n2\\n0\\n0\\n2\\n0\\n3\\n4\\n1\", \"4\\n0\\n0\\n4\\n3\", \"8\\n2\\n0\\n1\\n2\\n0\\n1\\n0\\n1\", \"8\\n2\\n0\\n1\\n2\\n0\\n1\\n0\\n0\", \"8\\n4\\n0\\n0\\n2\\n0\\n1\\n2\\n1\", \"7\\n314159265\\n429733551\\n846264338\\n327950288\\n419716939\\n937510582\\n0\", \"8\\n2\\n...
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions: * He never visits a point with coordinate less than 0, or a point with coordinate greater than L. * He starts walking at a point with integer coordinate, and also finishes walking at a point with ...
0
{"tests": "{\"inputs\": [\"3 3 2 4 4\\n2 5 4 10\\n\", \"3 3 3 3 5\\n2 3 5 4 2\\n\", \"5 5 1 2 3\\n2 2 3\\n\", \"3 4 1 1 3\\n2 3 2\\n\", \"572 540 6 2 12\\n2 3 2 2 2 3 3 3 2 2 2 2\\n\", \"375 905 1 1 17\\n2 2 3 3 3 3 3 3 2 2 2 2 3 2 2 2 3\\n\", \"37 23 4 1 16\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"20 19 6 8 18\\n3 4 ...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
0
{"tests": "{\"inputs\": [\"6\\n0 1 80\\n1 2 20\\n0 2 60\\n2 3 50\\n3 4 66\\n1 4 90\\n2\\n0 1 1\\n1 2 1\\n0\", \"6\\n0 1 80\\n1 2 20\\n0 2 60\\n2 3 50\\n3 4 66\\n0 4 90\\n2\\n0 1 1\\n1 2 1\\n0\", \"6\\n0 1 80\\n1 2 20\\n0 2 60\\n2 2 50\\n3 4 66\\n0 4 90\\n2\\n0 1 1\\n1 2 1\\n0\", \"6\\n0 1 80\\n1 2 20\\n0 2 60\\n2 2 50\...
Mr. A, who will graduate next spring, decided to move when he got a job. The company that finds a job has offices in several towns, and the offices that go to work differ depending on the day. So Mr. A decided to live in a town where he had a short time to go to any office. So you decided to find the most convenient t...
0