info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"5\\n2\\n8\\n1\\n10\\n12\", \"5\\n2\\n8\\n1\\n10\\n13\", \"5\\n2\\n8\\n1\\n18\\n24\", \"5\\n3\\n8\\n0\\n18\\n24\", \"5\\n3\\n5\\n0\\n18\\n24\", \"5\\n3\\n5\\n0\\n17\\n4\", \"5\\n5\\n5\\n0\\n26\\n4\", \"5\\n2\\n8\\n1\\n0\\n9\", \"5\\n2\\n3\\n1\\n10\\n12\", \"5\\n4\\n8\\n1\\n18\\n13\", \"5\\n2\\...
Carving the cake 2 (Cake 2) JOI-kun and IOI-chan are twin brothers and sisters. JOI has been enthusiastic about making sweets lately, and JOI tried to bake a cake and eat it today, but when it was baked, IOI who smelled it came, so we decided to divide the cake. became. The cake is round. We made radial cuts from a p...
0.25
{"tests": "{\"inputs\": [\"5 2\\n2 4 5 3 1\\n\", \"5 1\\n2 1 3 5 4\\n\", \"7 1\\n7 2 1 3 5 4 6\\n\", \"5 1\\n2 4 5 3 1\\n\", \"100 1\\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 3...
There are $n$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The $i$-th student has integer programming skill $a_i$. All programming skills are distinct and between $1$ and $n$, inclusive. Firstly, the first coach wi...
0.125
{"tests": "{\"inputs\": [[[2, -4, 6, -6]], [[7, -3, -10]], [[7, -8, 1, -2]], [[8, 10, -6, -7, 9]], [[-3, 4, -10, 2, -6]], [[2, -6, -4, 1, -8, -2]], [[16, 25, -48, -47, -37, 41, -2]], [[-30, -11, 36, 38, 34, -5, -50]], [[-31, -5, 11, -42, -22, -46, -4, -28]], [[46, 39, -45, -2, -5, -6, -17, -32, 17]], [[-9, -8, -6, -46,...
# Scenario With **_Cereal crops_** like wheat or rice, before we can eat the grain kernel, we need to remove that inedible hull, or *to separate the wheat from the chaff*. ___ # Task **_Given_** a *sequence of n integers* , **_separate_** *the negative numbers (chaff) from positive ones (wheat).* ___ # Notes * *...
0
{"tests": "{\"inputs\": [\"15 7 2\", \"1000 101 10\", \"1100 101 10\", \"1100 111 10\", \"7 2 3\", \"20 7 2\", \"15 3 2\", \"1000 101 3\", \"1100 100 10\", \"1100 101 19\", \"7 1 3\", \"20 13 2\", \"17 3 2\", \"1000 111 3\", \"11 2 3\", \"20 8 2\", \"3 3 2\", \"1000 100 3\", \"11 2 4\", \"20 10 2\", \"3 2 2\", \"1000 0...
Snuke has a string x of length N. Initially, every character in x is `0`. Snuke can do the following two operations any number of times in any order: * Choose A consecutive characters in x and replace each of them with `0`. * Choose B consecutive characters in x and replace each of them with `1`. Find the number o...
0
{"tests": "{\"inputs\": [\"2\\n0 0\\n0 0\\n9\\n3\\n1 2\\n2 2\\n1 1\\n2 1\\n3\\n1 2\\n1 1\\n3\\n\", \"1\\n0\\n5\\n1 1\\n3\\n1 1\\n1 1\\n3\\n\", \"5\\n1 0 1 0 1\\n0 1 0 1 0\\n1 0 1 0 1\\n0 1 0 1 0\\n1 0 1 0 1\\n7\\n3\\n2 4\\n1 3\\n3\\n2 5\\n1 5\\n3\\n\", \"2\\n0 0\\n0 0\\n2\\n1 1\\n3\\n\", \"4\\n1 1 0 0\\n1 1 0 0\\n0 0 0...
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is ...
0
{"tests": "{\"inputs\": [\"2 5 5 7 6 13\\n517 1024 746 6561 4303 3125\\n0 0 0 0 0 0\", \"2 5 5 7 6 13\\n517 1334 746 6561 4303 3125\\n0 0 0 0 0 0\", \"2 5 5 7 6 13\\n517 1024 746 11315 4303 3125\\n0 0 0 0 0 0\", \"2 5 5 7 6 13\\n913 1334 1228 6561 4303 3125\\n0 0 0 0 0 0\", \"2 5 5 7 6 13\\n517 1024 746 14921 4303 3125...
A calculator scholar has discovered a strange life form called an electronic fly that lives in electronic space. While observing the behavior of the electronic flies, the electronic flies at the (x, y, z) point in this space then move to (x', y', z') indicated by the following rules. I found out. <image> However, a1...
0.5
{"tests": "{\"inputs\": [\"3 3\\n1 2 1 2\\n2 3 2 1\\n3 1 3 2\\n5 5\\n1 2 2 2\\n2 3 1 1\\n1 4 1 1\\n4 5 1 1\\n5 3 1 1\\n5 10\\n1 2 32 10\\n1 3 43 43\\n1 4 12 52\\n1 5 84 23\\n2 3 58 42\\n2 4 86 99\\n2 5 57 83\\n3 4 11 32\\n3 5 75 21\\n4 5 23 43\\n5 10\\n1 2 1 53\\n1 3 1 65\\n1 4 1 24\\n1 5 1 76\\n2 3 2 19\\n2 4 1 46\\n2...
King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom. Amazingly, there are no roads in the kingdom now. Recently, he planned to construct roads between the capital and the cities, but it turned out that the construction cost of his plan is much higher than expected. In order to ...
0
{"tests": "{\"inputs\": [[7], [25], [50], [100], [1000], [10000]], \"outputs\": [[18], [107], [304], [993], [63589], [4721110]]}", "source": "taco"}
Consider a sequence generation that follows the following steps. We will store removed values in variable `res`. Assume `n = 25`: ```Haskell -> [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] Let's remove the first number => res = [1]. We get.. -> [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21...
0
{"tests": "{\"inputs\": [\"3\\n7\\n4 6 11 11 15 18 20\\n4\\n10 10 10 11\\n3\\n1 1 1000000000\\n\", \"1\\n3\\n78788 78788 100000\\n\", \"1\\n3\\n78788 78788 157577\\n\", \"1\\n10\\n1 7 7 7 7 9 9 9 9 9\\n\", \"1\\n6\\n1 1 1 2 2 3\\n\", \"1\\n3\\n5623 5624 10000000\\n\", \"1\\n3\\n5739271 5739272 20000000\\n\", \"1\\n14\\...
You are given an array $a_1, a_2, \dots , a_n$, which is sorted in non-decreasing order ($a_i \le a_{i + 1})$. Find three indices $i$, $j$, $k$ such that $1 \le i < j < k \le n$ and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to $a_i$, $a_j$ and $a_k$ (for...
0
{"tests": "{\"inputs\": [\"3\\n10 20 10\\n6\\n1 1\\n2 1\\n2 2\\n3 1\\n3 2\\n3 3\\n\", \"7\\n1 2 1 3 1 2 1\\n9\\n2 1\\n2 2\\n3 1\\n3 2\\n3 3\\n1 1\\n7 1\\n7 7\\n7 4\\n\", \"1\\n1\\n3\\n1 1\\n1 1\\n1 1\\n\", \"1\\n1000000000\\n1\\n1 1\\n\", \"2\\n1 10\\n3\\n2 2\\n2 1\\n1 1\\n\", \"2\\n3922 3922\\n3\\n2 2\\n2 1\\n1 1\\n\"...
This is the harder version of the problem. In this version, $1 \le n, m \le 2\cdot10^5$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers $a=[a_1,a_2,\dots,a_n]$ of length $n$. Its subsequence is obtained by removin...
0.25
{"tests": "{\"inputs\": [\"3 300\\n100 46 150\\n100 50 150\\n100 50 150\\n3 300\\n100 50 150\\n100 50 150\\n200 50 150\\n9 18\\n3 1 1\\n3 1 1\\n3 1 1\\n4 100 1\\n5 100 1\\n5 100 1\\n10 5 3\\n10 5 3\\n1 7 1000\\n10 18\\n1 2 3\\n2 3 4\\n3 4 5\\n4 5 6\\n5 6 7\\n6 7 8\\n7 8 9\\n8 9 10\\n9 10 11\\n10 11 12\\n0 0\", \"3 300\...
The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out how many operators needed to handle this situation. For simplicity, let u...
0
{"tests": "{\"inputs\": [[1], [5], [25], [30], [96], [50], [66], [306], [307], [308]], \"outputs\": [[0], [2], [4], [5], [5], [7], [7], [17], [18], [17]]}", "source": "taco"}
Final kata of the series (highly recommended to compute [layers](https://www.codewars.com/kata/progressive-spiral-number-position/) and [branch](https://www.codewars.com/kata/progressive-spiral-number-branch/) first to get a good idea), this is a blatant ripoff of [the one offered on AoC](http://adventofcode.com/2017/d...
0
{"tests": "{\"inputs\": [\"100 2 8\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\\n00\...
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having c...
0
{"tests": "{\"inputs\": [\"86232 41348\\n\", \"2 2\\n\", \"100000 17\\n\", \"1 1\\n\", \"4 2\\n\", \"1 99999\\n\", \"4 3\\n\", \"21857 94145\\n\", \"1 29\\n\", \"5444 31525\\n\", \"50664 46559\\n\", \"2 1\\n\", \"7683 65667\\n\", \"4 4\\n\", \"4 1\\n\", \"50000 100000\\n\", \"12345 31\\n\", \"25063 54317\\n\", \"62600 ...
A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the o...
0.5
{"tests": "{\"inputs\": [\"5\\n2 1 1 2 5\\n\", \"3\\n4 5 3\\n\", \"2\\n10 10\\n\", \"4\\n1 2 2 1\\n\", \"6\\n3 2 3 3 2 3\\n\", \"1\\n1\\n\", \"14\\n7 7 7 4 3 3 4 5 4 4 5 7 7 7\\n\", \"10\\n1 9 7 6 2 4 7 8 1 3\\n\", \"6\\n1 1 1 1 2 1\\n\", \"7\\n1 1 2 2 3 3 1\\n\", \"4\\n2 2 2 3\\n\", \"7\\n4 1 1 2 4 3 3\\n\", \"4\\n3 1...
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a sequence $a$ of $n$ integers, with $a_i$ being the height of the $i...
0
{"tests": "{\"inputs\": [\"9\\n9 4\\n7 5\\n4 1\\n6 5\\n5 2\\n3 1\\n2 1\\n8 3\\n3\\n9 7 2\\n1 6 4\\n8 4 1\\n\", \"7\\n3 4\\n2 3\\n6 5\\n2 7\\n5 2\\n1 2\\n6\\n5 6 2\\n3 2 4\\n5 1 1\\n2 4 3\\n3 7 4\\n6 5 2\\n\", \"3\\n2 3\\n2 1\\n3\\n3 2 3\\n3 1 2\\n1 2 4\\n\", \"7\\n2 7\\n4 2\\n6 5\\n2 1\\n1 3\\n5 4\\n5\\n1 4 2\\n7 3 1\\...
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree. You have a map of that network, so for each railway section you know which stations it connects. Each of the n-1 sections has some integer...
0.375
{"tests": "{\"inputs\": [\"57319 68943\", \"25 10\", \"1000000000000000000 1000000000010000000\", \"10 36\", \"105904 68943\", \"25 12\", \"1000000001000000000 1000000000010000000\", \"10 48\", \"109335 68943\", \"13 12\", \"1000001001000000000 1000000000010000000\", \"13 48\", \"49791 68943\", \"6 12\", \"100000100100...
Problem There are $ 2 $ teams, Team UKU and Team Ushi. Initially, Team UKU has $ N $ people and Team Uku has $ M $ people. Team UKU and Team Ushi decided to play a game called "U & U". "U & U" has a common score for $ 2 $ teams, and the goal is to work together to minimize the common score. In "U & U", everyone's phys...
0
{"tests": "{\"inputs\": [\"3 6\\n1 4 3\\n\", \"5 400\\n3 1 4 1 5\\n\", \"6 20\\n10 4 3 10 25 2\\n\", \"1 400\\n3 1 4 1 5\", \"3 6\\n1 7 3\", \"3 6\\n1 5 2\", \"3 7\\n1 5 0\", \"4 590\\n0 1 1 1 5\", \"5 1135\\n1 1 1 2 5\", \"1 734\\n3 1 4 1 5\", \"3 6\\n1 7 2\", \"1 734\\n3 1 4 0 5\", \"1 1126\\n3 1 4 0 5\", \"3 6\\n1 5...
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is unnecessary ...
0.125
{"tests": "{\"inputs\": [\"1010\\n1110\", \"1\\n1\", \"11010\\n11001\", \"0100100\\n1111101\", \"1010\\n1111\", \"0100100\\n1100000\", \"1010\\n0000\", \"0100100\\n0000001\", \"11010\\n11011\", \"0100100\\n0111111\", \"1010\\n1010\", \"11010\\n10011\", \"0100100\\n0101111\", \"1010\\n1011\", \"11010\\n10111\", \"010010...
You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same length consisting of 0 and 1. You can transform A using the following operations in any order and as many times as you want: * Shift A by one character to the left (i.e., if A = A_1 A_2 ... A_n, replace A with A_2 A_3 ... A_n A_1). * Shift A...
0
{"tests": "{\"inputs\": [\"7\\n1 2\\n1 2\\n3 2\\n1 1 2 2 3 3\\n3 3\\n3 4 4 1 1 1 1 1 2\\n2 2\\n1 1 2 1\\n4 2\\n50 50 50 50 3 50 50 50\\n4 2\\n6 6 6 6 2 2 9 6\\n2 9\\n1 3 3 3 3 3 1 1 3 1 3 1 1 3 3 1 1 3\\n\", \"7\\n1 2\\n1 2\\n3 2\\n1 1 2 2 3 6\\n3 3\\n3 4 4 1 1 1 1 1 2\\n2 2\\n1 1 2 1\\n4 2\\n50 50 50 50 3 50 50 50\\n4...
It is the hard version of the problem. The only difference is that in this version $1 \le n \le 300$. In the cinema seats can be represented as the table with $n$ rows and $m$ columns. The rows are numbered with integers from $1$ to $n$. The seats in each row are numbered with consecutive integers from left to right: ...
0
{"tests": "{\"inputs\": [[3], [4], [100], [97], [101], [120], [130]], \"outputs\": [[[2, 5]], [[3, 5]], [[97, 101]], [[89, 101]], [[97, 103]], [[113, 127]], [[127, 131]]]}", "source": "taco"}
We need a function ```prime_bef_aft()``` that gives the largest prime below a certain given value ```n```, ```befPrime or bef_prime``` (depending on the language), and the smallest prime larger than this value, ```aftPrime/aft_prime``` (depending on the language). The result should be output in a list like the f...
0
{"tests": "{\"inputs\": [\"3 3\\n1000000 1000000 1000000\\n2 1\\n1 3\\n3 2\\n\", \"4 3\\n10 10 5 1\\n2 1\\n3 1\\n3 4\\n\", \"4 3\\n1 2 8 6\\n1 3\\n1 4\\n3 4\\n\", \"6 8\\n69 36 41 23 91 35\\n1 2\\n3 1\\n3 2\\n1 4\\n3 4\\n3 5\\n5 4\\n4 6\\n\", \"6 7\\n85 2 34 6 83 61\\n1 2\\n2 3\\n4 2\\n4 3\\n1 5\\n4 5\\n6 3\\n\", \"6 6...
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has i...
0.875
{"tests": "{\"inputs\": [\"5: 2 - 3\\n17: 1 + 3 * (2 + 3 / 5 * 2) + 7\\n11: 1 / 8 - 5 - 8 * 2\\n19: 8 / (2 - 3 * 7)\\n1153: 10 * 4 / 7 + ( 50 + 81 / 22 ) + 11\\n0:\", \"5: 2 - 3\\n17: 1 + 3 * (2 + 3 / 5 * 2) + 7\\n11: 1 / 8 - 5 - 8 * 2\\n19: 8 / (2 - 3 * 7)\\n1153: 10 * 3 / 7 + ( 50 + 81 / 24 ) + 11\\n0:\", \"5: 2 - 3\...
The reciprocal of all non-zero real numbers is real, but the reciprocal of an integer is not necessarily an integer. This is the reason why 3/2 * 2 = 2 even though 3.0 / 2.0 * 2.0 = 3.0 in C language. However, if you consider integers with the same remainder after dividing by a prime number as the same, you can make al...
0
{"tests": "{\"inputs\": [\"4 1\\n1 2\\n3 4\\n2 3\", \"10 10\\n8 9\\n2 8\\n4 6\\n4 9\\n7 8\\n2 9\\n1 8\\n3 4\\n3 4\\n2 7\", \"3 2\\n1 2\\n2 2\", \"4 3\\n1 2\\n3 4\\n2 2\", \"6 1\\n1 2\", \"1 1\\n1 2\\n3 4\\n2 3\", \"10 10\\n8 9\\n2 8\\n7 6\\n4 9\\n7 8\\n2 9\\n1 8\\n3 4\\n3 4\\n2 7\", \"3 0\\n1 2\\n2 2\", \"10 1\\n8 9\\n...
There are N turkeys. We number them from 1 through N. M men will visit here one by one. The i-th man to visit will take the following action: * If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it. * If either turkey x_i or y_i is alive (but not both): eats the alive one. * ...
0
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n\", \"2 2\\n1 2\\n\", \"3 1\\n3 2\\n3 1\\n\", \"5 2\\n2 1\\n2 3\\n5 3\\n4 1\\n\", \"4 4\\n3 2\\n4 3\\n2 1\\n\", \"21 1\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 10\\n10 11\\n11 12\\n12 13\\n5 14\\n14 15\\n14 16\\n14 17\\n14 18\\n14 19\\n14 20\\n14 21\\n\", \"6 5\\n1 2\\n...
Two players, Red and Blue, are at it again, and this time they're playing with crayons! The mischievous duo is now vandalizing a rooted tree, by coloring the nodes while playing their favorite game. The game works as follows: there is a tree of size n, rooted at node 1, where each node is initially white. Red and Blue...
0
{"tests": "{\"inputs\": [[\"aba\", \"abbabba\"], [\"aba\", \"abaa\"], [\"aba\", \"a\"], [\"a\", \"a\"], [\"a\", \"aaa\"], [\"abcdefgh\", \"hgfedcba\"]], \"outputs\": [[9], [4], [3], [1], [3], [64]]}", "source": "taco"}
# Task You are given two string `a` an `s`. Starting with an empty string we can do the following two operations: ``` append the given string a to the end of the current string. erase one symbol of the current string.``` Your task is to find the least number of operations needed to construct the given string s. Assume...
0.375
{"tests": "{\"inputs\": [\"1\\n1\\n\", \"3\\n1 2 3\\n\", \"100\\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 509 236 782 44 467 607 326 267 15 564 858 499 337 74 346 443 4...
Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has a_{i} coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) ...
0
{"tests": "{\"inputs\": [\"100\\n9 13 6 72 98 70 5 100 26 75 25 87 35 10 95 31 41 80 91 38 61 64 29 71 52 63 24 74 14 56 92 85 12 73 59 23 3 39 30 42 68 47 16 18 8 93 96 67 48 89 53 77 49 62 44 33 83 57 81 55 28 76 34 36 88 37 17 11 40 90 46 84 94 60 4 51 69 21 50 82 97 1 54 2 65 32 15 22 79 27 99 78 20 43 7 86 45 19 6...
As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are a...
0.5
{"tests": "{\"inputs\": [\"4\\n1 1\\n3 1\\n4 1\\n2 1\\n3\\n5 2\\n1 2\\n1 2\\n1\\n1000 1000\\n10\\n5 62\\n10 68\\n15 72\\n20 73\\n25 75\\n30 77\\n35 79\\n40 82\\n45 100\\n815 283\\n6\\n74 78\\n53 55\\n77 77\\n12 13\\n39 42\\n1 1\\n0\", \"4\\n1 1\\n3 1\\n4 1\\n2 1\\n3\\n5 2\\n1 2\\n1 2\\n1\\n1000 1001\\n10\\n5 62\\n10 68...
At the school where the twins Ami and Mami attend, the summer vacation has already begun, and a huge amount of homework has been given this year as well. However, the two of them were still trying to go out without doing any homework today. It is obvious that you will see crying on the last day of summer vacation as it...
0
{"tests": "{\"inputs\": [\"10 4 10\\n1 1 11\\n7 7 15\\n2 3 11\\n2 8 6\\n\", \"10 6 8\\n3 6 7\\n1 4 3\\n2 7 10\\n4 7 4\\n7 10 15\\n4 7 7\\n\", \"1 3 1\\n1 1 5\\n1 1 3\\n1 1 12\\n\", \"10 2 6\\n1 7 1123\\n2 10 33\\n\", \"10 5 4\\n2 8 3\\n4 7 15\\n1 1 13\\n7 9 10\\n10 10 2\\n\", \"10 6 9\\n6 8 7\\n2 8 11\\n2 6 10\\n8 10 9...
Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as n holes in a row. We will consider the holes numbered from 1 to n, from left to right. Ilya is really keep on helping his city. So, he wants to fix at least k holes (perharps he can fix more) on a single Zoo...
0.125
{"tests": "{\"inputs\": [\"2\\n14 0\\n1 16 1 81 1 36 1 1024 1 1000000 1 1048576 1 4194304\\n14 0\\n1 16 1 81 1 36 1 1024 1 1000000 1 1048576 1 4194304\\n\", \"1\\n2 0\\n1 16\\n\", \"2\\n14 0\\n1 16 1 81 1 36 1 1024 1 1000000 1 1048576 1 4194304\\n14 0\\n1 16 1 112 1 36 1 1024 1 1000000 1 1048576 1 4194304\\n\", \"3\\n5...
This is the easy version of the problem. The only difference is that in this version k = 0. There is an array a_1, a_2, …, a_n of n positive integers. You should divide it into a minimal number of continuous segments, such that in each segment there are no two numbers (on different positions), whose product is a perfe...
0.5
{"tests": "{\"inputs\": [\"82\\n\", \"49\\n\", \"35\\n\", \"79\\n\", \"92\\n\", \"57\\n\", \"100\\n\", \"75\\n\", \"56\\n\", \"41\\n\", \"16\\n\", \"25\\n\", \"8\\n\", \"74\\n\", \"90\\n\", \"44\\n\", \"13\\n\", \"64\\n\", \"70\\n\", \"7\\n\", \"9\\n\", \"4\\n\", \"72\\n\", \"69\\n\", \"2\\n\", \"29\\n\", \"68\\n\", \"...
Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in...
0
{"tests": "{\"inputs\": [\"6\\n4\\n2\\n2\\n4\\n2\\n4\", \"5\\n1\\n4\\n1\\n2\\n2\", \"6\\n4\\n2\\n2\\n1\\n2\\n4\", \"6\\n4\\n1\\n2\\n1\\n2\\n4\", \"7\\n1\\n2\\n1\\n2\\n3\\n3\\n2\", \"6\\n3\\n2\\n2\\n2\\n2\\n4\", \"7\\n1\\n3\\n1\\n2\\n1\\n3\\n2\", \"7\\n1\\n3\\n1\\n2\\n4\\n3\\n2\", \"7\\n1\\n3\\n1\\n2\\n2\\n3\\n2\", \"6\...
There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possible final s...
0
{"tests": "{\"inputs\": [\"2 3\\n1 -1\\n1 1\\n1 2\\n2 2\\n\", \"5 5\\n-1 1 1 1 -1\\n1 1\\n2 3\\n3 5\\n2 5\\n1 5\\n\", \"3 3\\n1 1 1\\n2 2\\n1 1\\n1 1\\n\", \"4 4\\n-1 -1 -1 -1\\n1 3\\n1 2\\n1 2\\n1 1\\n\", \"5 5\\n-1 -1 -1 -1 -1\\n1 1\\n1 1\\n3 4\\n1 1\\n1 4\\n\", \"6 6\\n-1 -1 1 -1 -1 1\\n1 1\\n3 4\\n1 1\\n1 1\\n1 3\\...
Eugeny has array a = a_1, a_2, ..., a_{n}, consisting of n integers. Each integer a_{i} equals to -1, or to 1. Also, he has m queries: Query number i is given as a pair of integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The response to the query will be integer 1, if the elements of array a can be rearranged so as the...
0.375
{"tests": "{\"inputs\": [\"2 2\\n\", \"2 3\\n\", \"3 3\\n\", \"20 68\\n\", \"1 1\\n\", \"1 2\\n\", \"1 3\\n\", \"2 1\\n\", \"2 2\\n\", \"3 1\\n\", \"3 2\\n\", \"68 42\\n\", \"1 35\\n\", \"25 70\\n\", \"59 79\\n\", \"65 63\\n\", \"46 6\\n\", \"28 82\\n\", \"98 98\\n\", \"98 99\\n\", \"98 100\\n\", \"99 98\\n\", \"99 99\...
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
0.75
{"tests": "{\"inputs\": [\"6\\n010000\\n000001\\n\", \"10\\n1111100000\\n0000011111\\n\", \"8\\n10101010\\n01010101\\n\", \"10\\n1111100000\\n1111100001\\n\", \"12\\n011001010101\\n111001010101\\n\", \"9\\n111110000\\n111100000\\n\", \"5\\n10100\\n01010\\n\", \"10\\n1010111110\\n1011101101\\n\", \"3\\n000\\n000\\n\", \...
Naman has two binary strings $s$ and $t$ of length $n$ (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert $s$ into $t$ using the following operation as few times as possible. In one operation, he can choose any subsequence of $s$ and rotate it clockwise once. For exam...
0
{"tests": "{\"inputs\": [\"4 5\\n..XXX\\n...X.\\n...X.\\n...X.\\n5\\n1 3\\n3 3\\n4 5\\n5 5\\n1 5\\n\", \"1 1\\nX\\n1\\n1 1\\n\", \"1 1\\n.\\n1\\n1 1\\n\", \"3 3\\n..X\\n.X.\\nX..\\n10\\n1 3\\n1 3\\n1 3\\n2 3\\n1 3\\n1 2\\n1 3\\n2 2\\n2 3\\n2 2\\n\", \"3 3\\n...\\nXXX\\nXX.\\n10\\n2 3\\n1 2\\n2 2\\n1 3\\n2 3\\n1 2\\n1 3...
The problem statement looms below, filling you with determination. Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in ...
0
{"tests": "{\"inputs\": [\"5\\n1 3 1 4 5\\n\", \"4\\n4 2 2 4\\n\", \"2\\n1 1\\n\", \"5\\n100 1 100 1 100\\n\", \"4\\n2 3 4 2\\n\", \"4\\n2 1 3 3\\n\", \"5\\n1 5 5 1 4\\n\", \"4\\n2 3 4 2\\n\", \"4\\n2 1 3 3\\n\", \"8\\n4 2 5 5 1 2 5 2\\n\", \"5\\n1 5 5 1 4\\n\", \"4\\n1 3 4 2\\n\", \"4\\n2 1 5 3\\n\", \"8\\n7 2 5 5 1 2...
There are $n$ beautiful skyscrapers in New York, the height of the $i$-th one is $h_i$. Today some villains have set on fire first $n - 1$ of them, and now the only safety building is $n$-th skyscraper. Let's call a jump from $i$-th skyscraper to $j$-th ($i < j$) discrete, if all skyscrapers between are strictly lower...
0.375
{"tests": "{\"inputs\": [\"100 5\\n101 101 5 5\\n110 110 2 3\\n-112 -100 9 11\\n-208 160 82 90\\n-110 108 10 2\\n10 11\\n15 0 5 1\\n25 0 5 1\\n35 0 5 1\\n45 0 5 1\\n55 0 5 1\\n65 0 5 1\\n75 0 5 1\\n85 0 5 1\\n95 0 5 1\\n-19 0 5 20\\n-30 0 500 5\\n0 0\", \"100 5\\n101 101 5 5\\n110 110 2 3\\n-112 -100 5 11\\n-208 160 82...
In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another. <image> But hope remains. The ultimate defense force weapon, the ultra...
0
{"tests": "{\"inputs\": [[5, 6], [19, 20], [6, 20], [15, 20], [8, 20], [9, 8], [4, 10], [12, 12], [7, 10], [4, 12]], \"outputs\": [[19], [208], [195], [204], [197], [36], [48], [77], [51], [69]]}", "source": "taco"}
Your task is to return the number of visible dots on a die after it has been rolled(that means the total count of dots that would not be touching the table when rolled) 6, 8, 10, 12, 20 sided dice are the possible inputs for "numOfSides" topNum is equal to the number that is on top, or the number that was rolled. f...
0
{"tests": "{\"inputs\": [\"3 2 5\\n1 2 3\\n2 3 3\\n2\\n3 2\\n1 3\\n\", \"4 0 1\\n1\\n2 1\\n\", \"5 4 4\\n1 2 2\\n2 3 2\\n3 4 3\\n4 5 2\\n20\\n2 1\\n3 1\\n4 1\\n5 1\\n1 2\\n3 2\\n4 2\\n5 2\\n1 3\\n2 3\\n4 3\\n5 3\\n1 4\\n2 4\\n3 4\\n5 4\\n1 5\\n2 5\\n3 5\\n4 5\\n\", \"4 0 0\\n1\\n2 1\", \"5 4 4\\n1 2 2\\n2 3 2\\n3 4 3\\...
There are N towns numbered 1 to N and M roads. The i-th road connects Town A_i and Town B_i bidirectionally and has a length of C_i. Takahashi will travel between these towns by car, passing through these roads. The fuel tank of his car can contain at most L liters of fuel, and one liter of fuel is consumed for each un...
0.125
{"tests": "{\"inputs\": [[\"\"], [\"a\"], [\"street\"], [\"STREET\"], [\" a\"], [\"st re et\"], [\"f\"], [\"quirky\"], [\"MULTIBILLIONAIRE\"], [\"alacrity\"]], \"outputs\": [[0], [1], [6], [6], [1], [6], [4], [22], [20], [13]]}", "source": "taco"}
Write a program that, given a word, computes the scrabble score for that word. ## Letter Values You'll need these: ``` Letter Value A, E, I, O, U, L, N, R, S, T 1 D, G 2 B, C, M, P 3 F, H, V, W, Y 4 K ...
0
{"tests": "{\"inputs\": [\"3\\n4 4\\n1 1 1 1\\n3 1\\n1 2 3\\n3 3\\n1 2 3\\n\", \"10\\n2 2\\n4 3\\n2 2\\n13 13\\n2 2\\n9 11\\n2 1\\n14 5\\n2 1\\n13 2\\n2 2\\n4 5\\n2 1\\n11 14\\n2 2\\n15 3\\n2 2\\n12 10\\n2 2\\n13 12\\n\", \"10\\n3 2\\n3 6 1\\n3 3\\n9 0 2\\n3 3\\n8 8 2\\n4 2\\n9 0 0 1\\n4 4\\n5 3 0 2\\n4 4\\n2 8 6 0\\n5...
Hanh lives in a shared apartment. There are $n$ people (including Hanh) living there, each has a private fridge. $n$ fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A f...
0
{"tests": "{\"inputs\": [\"3\\n100\\n001\\n\", \"4\\n0101\\n0011\\n\", \"8\\n10001001\\n01101110\\n\", \"1\\n0\\n1\\n\", \"6\\n110110\\n000000\\n\", \"15\\n101010101010101\\n010101010101010\\n\", \"7\\n1110001\\n0000000\\n\", \"7\\n1110001\\n0000001\\n\", \"91\\n001001000011000100101101101111100100011000100010011111001...
You are given two binary strings $a$ and $b$ of the same length. You can perform the following two operations on the string $a$: Swap any two bits at indices $i$ and $j$ respectively ($1 \le i, j \le n$), the cost of this operation is $|i - j|$, that is, the absolute difference between $i$ and $j$. Select any arbit...
0
{"tests": "{\"inputs\": [\"3\\n5\\n2 1 aa\\n1 2 a\\n2 3 a\\n1 2 b\\n2 3 abca\\n2\\n1 5 mihai\\n2 2 buiucani\\n3\\n1 5 b\\n2 3 a\\n2 4 paiu\\n\", \"1\\n5\\n2 1 bb\\n1 2 b\\n2 3 b\\n1 2 c\\n2 3 bcdbweakpretests\\n\", \"1\\n2\\n1 1 ab\\n2 1 ab\\n\", \"1\\n2\\n1 3 c\\n2 3 b\\n\", \"1\\n3\\n2 1 z\\n2 1 a\\n1 1 z\\n\", \"1\\...
Alperen has two strings, $s$ and $t$ which are both initially equal to "a". He will perform $q$ operations of two types on the given strings: $1 \;\; k \;\; x$ — Append the string $x$ exactly $k$ times at the end of string $s$. In other words, $s := s + \underbrace{x + \dots + x}_{k \text{ times}}$. $2 \;\; k \;\; x...
0
{"tests": "{\"inputs\": [\"16\\ninsert 35 99\\ninsert 3 80\\ninsert 1 53\\ninsert 14 25\\ninsert 80 76\\ninsert 42 3\\ninsert 102 47\\ninsert 21 12\\ninsert 7 10\\ninsert 6 90\\nprint\\nfind 21\\nfind 22\\ndelete 35\\ndelete 99\\nprint\", \"16\\ninsert 35 99\\ninsert 3 80\\ninsert 1 53\\ninsert 14 25\\ninsert 80 76\\ni...
A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shuffle the elements to be inserted. However, we should consider to maintain t...
0.875
{"tests": "{\"inputs\": [\"1 1\\n-16\", \"5 3\\n-10 10 -18 10 -10\", \"4 2\\n7 -10 -10 10\", \"4 2\\n7 -6 -10 12\", \"4 2\\n7 -6 -10 20\", \"4 2\\n9 -1 -10 20\", \"4 2\\n13 -1 -10 20\", \"4 2\\n3 -1 -10 20\", \"4 3\\n3 -1 -10 20\", \"4 3\\n3 -1 -1 20\", \"10 5\\n5 -4 -5 -8 -4 0 2 -4 0 7\", \"4 4\\n9 -1 -10 20\", \"4 3\...
There are N squares aligned in a row. The i-th square from the left contains an integer a_i. Initially, all the squares are white. Snuke will perform the following operation some number of times: * Select K consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares...
0
{"tests": "{\"inputs\": [[1, 50], [3, 100], [3, 200], [6, 350], [6, 1000], [7, 1500], [7, 2500], [7, 3000], [9, 4000], [9, 5000], [11, 5000]], \"outputs\": [[8], [7], [18], [86], [214], [189], [309], [366], [487], [622], [567]]}", "source": "taco"}
The integers 14 and 15, are contiguous (1 the difference between them, obvious) and have the same number of divisors. ```python 14 ----> 1, 2, 7, 14 (4 divisors) 15 ----> 1, 3, 5, 15 (4 divisors) ``` The next pair of contiguous integers with this property is 21 and 22. ```python 21 -----> 1, 3, 7, 21 (4 divisors) 22 --...
0.875
{"tests": "{\"inputs\": [\"3\\n2 3 4\\n2 2\\n2 3 4\\n3 2\\n2 4 3\\n3 2\\n\", \"1\\n2 100 2\\n1000000 1000000\\n\", \"1\\n2 100 1\\n999999 1000000\\n\", \"1\\n3 1000000000 1\\n1000000 1000000 1000000\\n\", \"1\\n2 1000000000 1\\n1000000 1000000\\n\", \"1\\n2 2 1\\n1000000 1000000\\n\", \"1\\n4 100 1\\n999999 1000000 100...
There is a graph of $n$ rows and $10^6 + 2$ columns, where rows are numbered from $1$ to $n$ and columns from $0$ to $10^6 + 1$: Let's denote the node in the row $i$ and column $j$ by $(i, j)$. Initially for each $i$ the $i$-th row has exactly one obstacle — at node $(i, a_i)$. You want to move some obstacles so that...
0
{"tests": "{\"inputs\": [[\"AAA\", [1]], [\"AAA\", [2]], [\"AAA\", [-1]], [\"AAAA\", [2]], [\"AGGTGACACCGCAAGCCTTATATTAGC\"], [\"AGGTGACACCGCAAGCCTTATATTAGC\", [1, 2]], [\"AGGTGACACCGCAAGCCTTATATTAGC\", [2, 1]], [\"AGGTGACACCGCAAGCCTTATATTAGC\", []], [\"\"], [\"\", []]], \"outputs\": [[[\"K\"]], [[\"\"]], [[\"F\"]], [[...
In genetics a reading frame is a way to divide a sequence of nucleotides (DNA bases) into a set of consecutive non-overlapping triplets (also called codon). Each of this triplets is translated into an amino-acid during a translation process to create proteins. In a single strand of DNA you find 3 Reading frames, for e...
0
{"tests": "{\"inputs\": [[\"scout\", [20, 12, 18, 30, 21]], [\"masterpiece\", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]], [\"nomoretears\", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]], [\"notencrypted\", [14, 15, 20, 5, 14, 3, 18, 25, 16, 20, 5, 4]], [\"tenthousand\", [21, 5, 14, 20, 8, 16, 21, 19, 1, 14, 5]], [\"oneoho...
# Introduction Digital Cypher assigns a unique number to each letter of the alphabet: ``` a b c d e f g h i j k l m n o p q r s t u v w x y z 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 ``` In the encrypted word we write the corresponding numbers instead o...
0
{"tests": "{\"inputs\": [\"3 5\\n1 4 4 3 4\\n1 4 1 4 2\\n1 4 4 4 3\\n\", \"1 1\\n1\\n\", \"1 1\\n2\\n\", \"3 1\\n1\\n1\\n1\\n\", \"1 1\\n1\\n\", \"1 1\\n2\\n\", \"3 1\\n1\\n1\\n1\\n\", \"3 1\\n1\\n1\\n2\\n\", \"3 5\\n1 4 4 3 4\\n1 4 2 4 2\\n1 4 4 4 3\\n\", \"3 5\\n1 4 4 3 4\\n1 4 2 4 2\\n1 3 4 4 3\\n\", \"3 5\\n1 4 4 3...
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Mon...
0.25
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n4 3\\n1 4\\n3 4\\n\", \"6 5\\n2 3\\n2 1\\n3 4\\n6 5\\n4 5\\n\", \"2 1\\n1 2\\n\", \"100000 12\\n8 7\\n1 9\\n5 4\\n11 12\\n7 8\\n3 4\\n3 5\\n12 15\\n15 13\\n13 14\\n7 8\\n11 14\\n\", \"10 15\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n1 6\\n2 7\\n3 8\\n4 9\\n5 10\\n6 8\\n7 9\\n8 10\\n9 6\\n10 ...
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo! There are $n$ snacks flavors, numbered with integers $1, 2, \ldots, n$. Bessie has $n$ snacks, one snack of each flav...
0
{"tests": "{\"inputs\": [\"2 3\\n...\\n.#.\\n...\", \"6 6\\n..#..#\\n......\\n..#..\\n......\\n.#....\\n-...#.\", \"2 6\\n#.#...\\n......\\n..#0.\\n......\\n.#.-..\\n--..#-\", \"2 3\\n...\\n.#.\\n..-\", \"2 3\\n/..\\n.#.\\n..-\", \"2 3\\n/..\\n.#.\\n..,\", \"3 3\\n...\\n/#.\\n...\", \"2 3\\n...\\n.#.\\n..,\", \"3 3\\n....
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if t...
0
{"tests": "{\"inputs\": [\"4\\n0 1 1 1\\n\", \"1\\n3\\n\", \"1\\n0\\n\", \"1\\n2000000000\\n\", \"1\\n1\\n\", \"26\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\\n\", \"1\\n2000000000\\n\", \"26\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\\n\", \"1\\n0\\n\", \"1\\n1\\n\", \"1\\n1646661570\\n\", \"1\\n...
Ivan has got an array of n non-negative integers a_1, a_2, ..., a_{n}. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2^{a}_1, 2^{a}_2, ..., 2^{a}_{n} on a piece of paper. Now he wonders, what minimum number of integers of form 2^{b} (b ≥ 0) need to be added to the piece of p...
0.25
{"tests": "{\"inputs\": [\"3 7 3\\n2 3 0 0 2 0 1\\n2 1 3\\n1 0 0 0 1 0 0\\n0 0 0 0 0 0 1\\n1 1 0 0 0 0 0\\n\", \"4 5 5\\n3 5 2 0 4\\n4 2 5 4\\n0 0 0 0 1\\n1 0 1 0 0\\n0 1 0 0 0\\n1 1 1 0 0\\n\", \"1 1 1\\n0\\n0\\n0\\n\", \"1 1 1\\n1\\n1\\n1\\n\", \"1 100 99\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny. He has a special interest to create difficult problems for others to solve. This time, with many $1 \times 1 \times 1$ toy bricks, he builds up a 3-dimensional object. We c...
0.375
{"tests": "{\"inputs\": [\"z\\na\\n\", \"abc\\naaac\\n\", \"bcbcdddbbd\\nbcbcdbdbbd\\n\", \"aaabccadac\\nacabbbabaa\\n\", \"a\\nb\\n\", \"acaccaaadz\\ncaadccaaaa\\n\", \"aa\\nab\\n\", \"abacaba\\naba\\n\", \"aabbaa\\naaaaaaaaaaaaaaaaaaaa\\n\", \"ac\\na\\n\", \"a\\na\\n\", \"aabbaa\\ncaaaaaaaaa\\n\", \"aaaaaaaaa\\na\\n\...
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
0
{"tests": "{\"inputs\": [\"2 1000000000\\n2 1\\n\", \"2 1\\n2 1\\n\", \"4 1\\n4 1\\n2 4\\n3 1\\n\", \"3 1000000000\\n3 2\\n2 1\\n\", \"4 1\\n1 3\\n1 4\\n2 1\\n\", \"4 1\\n2 3\\n1 4\\n2 1\\n\", \"6 1\\n2 1\\n4 3\\n2 5\\n5 4\\n5 6\\n\", \"6 1\\n2 1\\n2 3\\n2 5\\n2 4\\n5 6\\n\", \"4 5\\n1 2\\n1 3\\n1 4\\n\", \"6 2\\n2 1\\...
You are given a tree (an undirected connected graph without cycles) and an integer s. Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and their sum is s. At the same time, he wants to make the diameter of the tree as small as possible. Let's define the diameter of...
0.375
{"tests": "{\"inputs\": [[5], [12], [13], [16], [17], [20], [9001], [9004], [9005], [9008], [90001], [90002], [90004], [90005], [90009], [900001], [900004], [900005], [9000001], [9000004], [90000001], [90000004], [900000012], [9000000041]], \"outputs\": [[[[3, 1]]], [[[4, 1]]], [[[7, 3]]], [[[4, 0]]], [[[9, 4]]], [[[6,...
In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied. In this kata we want to find all integers `x, y` (`x >= 0, y >= 0`) solutions of a diophantine equation o...
0
{"tests": "{\"inputs\": [\"2\\n5 2\\n3 5\\n5 1\\n1\", \"2\\n5 2\\n3 5\\n7 1\\n1\", \"2\\n5 2\\n3 3\\n7 1\\n1\", \"2\\n6 2\\n1 3\\n7 1\\n2\", \"2\\n6 0\\n1 3\\n7 0\\n1\", \"2\\n5 2\\n3 3\\n7 0\\n1\", \"2\\n5 2\\n1 3\\n7 0\\n1\", \"2\\n6 2\\n1 3\\n7 0\\n1\", \"2\\n6 2\\n1 3\\n7 1\\n1\", \"2\\n6 2\\n1 0\\n7 1\\n2\", \"2\\...
Read problems statements in Mandarin Chinese and Russian. Today is Chef's birthday. His mom gifted him a truly lovable gift, a permutation of first N positive integers. She placed the permutation on a very long table in front of Chef and left it for him to play with it. But as there was a lot of people coming and w...
0
{"tests": "{\"inputs\": [\"4\\nb\\naabbbabaa\\nabbb\\nabbaab\\n\", \"1\\naaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbab\\n\", \"1\\nabbabababbabababbababbbabbbbabbbabaabaabba\\n\", \"1\\nabbabababbabababbababbbabbbbabbbabaabaabba\\n\", \"4\\nb\\naabbbabaa\\nabbb\\nabbaab\\n\", \"1\\naaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb...
You are given a string $s$ of length $n$ consisting of characters a and/or b. Let $\operatorname{AB}(s)$ be the number of occurrences of string ab in $s$ as a substring. Analogically, $\operatorname{BA}(s)$ is the number of occurrences of ba in $s$ as a substring. In one step, you can choose any index $i$ and replace...
0.625
{"tests": "{\"inputs\": [\"2\\n5\\n1 2 3 4 5\\n7\\n3 2 4 5 1 6 7\\n\", \"4\\n6\\n1 5 3 4 2 6\\n6\\n5 1 3 4 2 6\\n6\\n1 5 3 4 6 2\\n6\\n5 1 3 4 6 2\\n\", \"3\\n3\\n1 2 3\\n4\\n3 1 2 4\\n7\\n6 4 1 7 3 5 2\\n\", \"3\\n6\\n6 2 5 1 4 3\\n6\\n3 5 1 4 2 6\\n2\\n1 2\\n\", \"1\\n2\\n1 2\\n\", \"1\\n7\\n3 2 4 1 7 6 5\\n\", \"1\\...
Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across $n$ sessions follow the identity permutation (ie. in the first game he scores $1$ point, in the second game he scores $2$ points and so on). However, when...
0
{"tests": "{\"inputs\": [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [139815, 122265], [496, 28], [8128, 8128]], \"outputs\": [[\"abundant deficient amicable\"], [\"abundant abundant not amicable\"], [\"abundant deficient amicable\"], [\"deficient abundant not...
For a given two numbers your mission is to derive a function that evaluates whether two given numbers are **abundant**, **deficient** or **perfect** and whether together they are **amicable**. ### Abundant Numbers An abundant number or excessive number is a number for which the sum of its proper divisors is greater ...
0
{"tests": "{\"inputs\": [[\"123?45*?=?\"], [\"?*123?45=?\"], [\"??605*-63=-73???5\"], [\"123?45+?=123?45\"], [\"?8?170-1?6256=7?2?14\"], [\"?38???+595???=833444\"], [\"123?45-?=123?45\"], [\"-7715?5--484?00=-28?9?5\"], [\"50685?--1?5630=652?8?\"], [\"??+??=??\"], [\"-?56373--9216=-?47157\"]], \"outputs\": [[0], [0], [1...
To give credit where credit is due: This problem was taken from the ACMICPC-Northwest Regional Programming Contest. Thank you problem writers. You are helping an archaeologist decipher some runes. He knows that this ancient society used a Base 10 system, and that they never start a number with a leading zero. He's fig...
0
{"tests": "{\"inputs\": [\"3 2\\n1 1\\n1 4\\n2 2\\n\", \"2 1\\n3 2\\n4 0\\n\", \"5 2\\n2 10\\n2 10\\n1 1\\n3 1\\n3 1\\n\", \"1 1\\n1 200000\\n\", \"1 2\\n1 100000\\n\", \"1 1\\n200000 0\\n\", \"9 4\\n3 10\\n4 11\\n4 2\\n1 3\\n1 7\\n2 5\\n2 6\\n3 4\\n1 7\\n\", \"3 3\\n4 154461\\n7 14431\\n3 186162\\n\", \"6 4\\n1 159371...
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\": [\"5 5\\n10\\n2 4 420\\n4 5 974\\n5 1 910\\n1 3 726\\n1 2 471\\n5 2 94\\n3 2 307\\n2 5 982\\n5 4 848\\n3 5 404\\n\", \"5 4\\n4\\n5 4 614\\n4 1 177\\n1 3 66\\n5 2 43\\n\", \"3 2\\n10\\n2 3 290\\n3 1 859\\n3 1 852\\n1 2 232\\n1 2 358\\n2 1 123\\n1 3 909\\n2 1 296\\n1 3 119\\n1 2 584\\n\", \"1 1\\n...
Bankopolis is an incredible city in which all the n crossroads are located on a straight line and numbered from 1 to n along it. On each crossroad there is a bank office. The crossroads are connected with m oriented bicycle lanes (the i-th lane goes from crossroad ui to crossroad vi), the difficulty of each of the lan...
0
{"tests": "{\"inputs\": [\"3 2 11\", \"3 0 11\", \"2 2 28\", \"3 5 28\", \"5 4 11\", \"5 3 17\", \"5 4 18\", \"6 4 12\", \"4 3 5\", \"4 8 5\", \"4 3 10\", \"11 3 9\", \"8 10 37\", \"8 6 37\", \"8 6 42\", \"8 6 39\", \"8 6 77\", \"8 9 77\", \"3 0 22\", \"3 1 22\", \"5 1 22\", \"5 0 22\", \"5 0 25\", \"3 0 25\", \"3 1 7\...
F: Grid number problem Ebi-chan is trying to write exactly one integer from 1 to 2 \ times n in a grid with n columns horizontally and 2 rows vertically. Only one integer can be written to each cell in the grid. It's not fun just to write normally, so I set the following rules. * The absolute value of the differen...
0
{"tests": "{\"inputs\": [\"10 1 1 1 2 0 10\\n1 1\\n2 1\\n3 0\\n4 0\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n10 1\\n\", \"10 1 1 1 2 0 10\\n1 1\\n2 1\\n3 0\\n4 0\\n5 1\\n6 1\\n14 1\\n8 1\\n9 1\\n10 1\\n\", \"5 1 1 1 4 0 5\\n1 0\\n2 1\\n3 1\\n4 0\\n5 0\\n\", \"1 1 2 1 2 1 2\\n1 1\\n\", \"5 1 1 0 4 0 5\\n1 0\\n2 1\\n3 1\\n4 0\\n5 ...
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by a and after each fashion show decreases by b (designers do too many experiments nowadays). Mor...
0.75
{"tests": "{\"inputs\": [\"4 4\\n4 3 1 6\\n\", \"5 2\\n3 2 0 2 7\\n\", \"3 3\\n2 3 1\\n\", \"10 3\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\\n\", \"5 4\\n0 554459682 978416312 784688178 954779973\\n\", \"5 2\\n1 554459683 978416312 784688178 95477997...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
0
{"tests": "{\"inputs\": [\"1\\n\", \"2\\n\", \"10\\n\", \"1000\\n\", \"2000\\n\", \"5000\\n\", \"10000\\n\", \"111199\\n\", \"101232812\\n\", \"1000000000\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"11\\n\", \"12\\n\", \"13\\n\", \"55\\n\", \"100\\n\", \"150\\n\", \"1200\\n\", \"999999...
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence s...
0
{"tests": "{\"inputs\": [\"3649596966777\\n4672433573317\\n9118992346175\\n9643871425498\\n7755542764533\\n1133557799246\", \"3649596966777\\n7685559208632\\n9118992346175\\n9643871425498\\n7755542764533\\n1133557799246\", \"3649596966777\\n4672433573317\\n9118992346175\\n7133209108608\\n7755542764533\\n704120058101\",...
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers. The conditions for completing the puzzle are * You must have one combination of the same numbers. * The remaining 12 numbers are 4 combinations of 3 numbers. The combination of three numbers i...
0
{"tests": "{\"inputs\": [\"11\\n\", \"0\\n\", \"17\\n\", \"18855321\\n\", \"34609610\\n\", \"25\\n\", \"9\\n\", \"40000000\\n\", \"17464436\\n\", \"38450759\\n\", \"395938\\n\", \"39099999\\n\", \"8\\n\", \"4\\n\", \"30426905\\n\", \"7\\n\", \"17082858\\n\", \"46341\\n\", \"46340\\n\", \"39999996\\n\", \"6\\n\", \"1282...
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
0
{"tests": "{\"inputs\": [\"3 3\\n3 2 1\\n1 2 3\\n4 5 6\\n\", \"4 3\\n1 2 3\\n4 5 6\\n7 8 9\\n10 11 12\\n\", \"3 4\\n1 6 3 4\\n5 10 7 8\\n9 2 11 12\\n\", \"3 4\\n45240 150726 140481 81046\\n5 6 7 169420\\n50454 36955 72876 12\\n\", \"3 4\\n5 6 7 8\\n9 10 11 12\\n1 2 3 4\\n\", \"3 6\\n155286 63165 3 174888 10886 6\\n8436...
You are given a rectangular matrix of size $n \times m$ consisting of integers from $1$ to $2 \cdot 10^5$. In one move, you can: choose any element of the matrix and change its value to any integer between $1$ and $n \cdot m$, inclusive; take any column and shift it one cell up cyclically (see the example of such cy...
0.125
{"tests": "{\"inputs\": [\"2\\n1\\n4\", \"2\\n1\\n3\", \"2\\n2\\n4\", \"2\\n2\\n8\", \"2\\n4\\n4\", \"2\\n2\\n7\", \"2\\n4\\n8\", \"2\\n2\\n13\", \"2\\n8\\n8\", \"2\\n2\\n26\", \"2\\n5\\n8\", \"2\\n1\\n26\", \"2\\n1\\n8\", \"2\\n1\\n41\", \"2\\n8\\n3\", \"2\\n6\\n4\", \"2\\n3\\n7\", \"2\\n4\\n13\", \"2\\n2\\n2\", \"2\\...
Read problems statements in Mandarin Chinese and Russian. Aditi recently discovered a new magic trick. First, she gives you an integer N and asks you to think an integer between 1 and N. Then she gives you a bundle of cards each having a sorted list (in ascending order) of some distinct integers written on it. The i...
0
{"tests": "{\"inputs\": [\"3 3 2\\n1 2 1\\n3 2 1\\n1 3 3\\n\", \"4 5 2\\n4 1 8\\n2 4 1\\n2 1 3\\n3 4 9\\n3 1 5\\n\", \"5 5 4\\n1 2 999999999\\n2 3 999999999\\n3 4 999999999\\n1 5 999999999\\n5 4 999999999\\n\", \"4 5 0\\n4 1 8\\n2 4 1\\n2 1 3\\n3 4 9\\n3 1 5\\n\", \"4 3 3\\n1 2 1000000000\\n2 3 1000000000\\n3 4 1000000...
You are given an undirected connected weighted graph consisting of $n$ vertices and $m$ edges. Let's denote the length of the shortest path from vertex $1$ to vertex $i$ as $d_i$. You have to erase some edges of the graph so that at most $k$ edges remain. Let's call a vertex $i$ good if there still exists a path from...
0
{"tests": "{\"inputs\": [\"4 3\\n2\\n3\\n4\\n\", \"13 4\\n10\\n5\\n4\\n8\\n\", \"2 2\\n1\\n2\\n\", \"1 1\\n1\\n\", \"3 3\\n3\\n2\\n1\\n\", \"12 12\\n9\\n11\\n5\\n3\\n7\\n2\\n8\\n6\\n4\\n10\\n12\\n1\\n\", \"2 2\\n1\\n2\\n\", \"1 1\\n1\\n\", \"12 12\\n9\\n11\\n5\\n3\\n7\\n2\\n8\\n6\\n4\\n10\\n12\\n1\\n\", \"3 3\\n3\\n2\\...
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm. Let's consider that i...
0
{"tests": "{\"inputs\": [\"4\\n100 0\\n0 100\\n-100 0\\n0 -100\\n\", \"7\\n0 2\\n1 0\\n-3 0\\n0 -2\\n-1 -1\\n-1 -3\\n-2 -3\\n\", \"5\\n0 0\\n0 -1\\n3 0\\n-2 0\\n-2 1\\n\", \"5\\n0 0\\n2 0\\n0 -1\\n-2 0\\n-2 1\\n\", \"2\\n1000000000 1000000000\\n-1000000000 -1000000000\\n\", \"22\\n-1000000000 -379241\\n993438994 -99343...
There are $n$ detachments on the surface, numbered from $1$ to $n$, the $i$-th detachment is placed in a point with coordinates $(x_i, y_i)$. All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one det...
0
{"tests": "{\"inputs\": [\"10 2\\nLWL?WWDDW?\\n\", \"10 3\\nDWD?DL??LL\\n\", \"10 1\\nD??W?WL?DW\\n\", \"5 3\\n??D??\\n\", \"5 5\\n?WDDD\\n\", \"1 1\\n?\\n\", \"10 1\\nLWL?WWDDW?\\n\", \"10 2\\nD??W?WL?DW\\n\", \"20 7\\n?LLLLLWWWWW?????????\\n\", \"10 3\\nDWDLDL???L\\n\", \"3 1\\n??W\\n\", \"20 6\\n?LLLLLWWWWW?????????...
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
0
{"tests": "{\"inputs\": [\"1 1 2 5\\n35\\nH L1 5\\nC1 D 6\\nC1 H 12\\nL1 D 10\\nC1 L1 20\\n2 1 4 6\\n100 70\\nH L1 5\\nC1 L1 12\\nC1 D 11\\nC2 L1 7\\nC2 D 10\\nL1 D 8\\n0 0 0 0\", \"1 1 2 5\\n35\\nH L1 5\\nC1 D 6\\nC1 H 12\\nL1 D 10\\nC1 L1 0\\n2 1 4 6\\n100 70\\nH L1 5\\nC1 L1 12\\nC1 D 11\\nC2 L1 7\\nC2 D 10\\nL1 D 8...
Mr. A loves sweets, but recently his wife has told him to go on a diet. One day, when Mr. A went out from his home to the city hall, his wife recommended that he go by bicycle. There, Mr. A reluctantly went out on a bicycle, but Mr. A, who likes sweets, came up with the idea of ​​stopping by a cake shop on the way to e...
0.125
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n\", \"4\\n0 0 0 2\\n\", \"3\\n1 1 3\\n\", \"7\\n0 0 2 2 5 5 6\\n\", \"10\\n1 2 3 4 4 4 7 7 7 10\\n\", \"1\\n1\\n\", \"1\\n0\\n\", \"7\\n0 0 2 2 5 5 6\\n\", \"1\\n1\\n\", \"10\\n1 2 3 4 4 4 7 7 7 10\\n\", \"1\\n0\\n\", \"3\\n1 1 1\\n\", \"4\\n0 0 0 3\\n\", \"4\\n0 0 0 1\\n\", \"3\\...
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----In...
0
{"tests": "{\"inputs\": [\"5\\n\\n2 2\\n1 2\\n3 4\\n\\n4 3\\n1 3 1\\n3 1 1\\n1 2 2\\n1 1 3\\n\\n2 3\\n5 3 4\\n2 5 1\\n\\n4 2\\n7 9\\n8 1\\n9 6\\n10 8\\n\\n2 4\\n6 5 2 1\\n7 9 7 2\\n\", \"5\\n\\n2 2\\n1 2\\n3 4\\n\\n4 3\\n1 3 1\\n3 1 1\\n1 2 2\\n1 1 3\\n\\n2 3\\n5 3 4\\n2 5 1\\n\\n4 2\\n7 9\\n8 1\\n9 6\\n10 8\\n\\n2 4\\...
Vlad has $n$ friends, for each of whom he wants to buy one gift for the New Year. There are $m$ shops in the city, in each of which he can buy a gift for any of his friends. If the $j$-th friend ($1 \le j \le n$) receives a gift bought in the shop with the number $i$ ($1 \le i \le m$), then the friend receives $p_{ij}...
0.375
{"tests": "{\"inputs\": [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]], \"outputs\": [[1], [10], [55], [220], [715], [2002], [5005], [92378], [10015005], [12565671261]]}", "source": "taco"}
An `non decreasing` number is one containing no two consecutive digits (left to right), whose the first is higer than the second. For example, 1235 is an non decreasing number, 1229 is too, but 123429 isn't. Write a function that finds the number of non decreasing numbers up to `10**N` (exclusive) where N is the input...
0.75
{"tests": "{\"inputs\": [\"8 3\\n3 3 1 2 2 1 1 3\\n3 1 1\\n\", \"6 5\\n1 2 4 2 4 3\\n0 0 1 0 0\\n\", \"1 1\\n1\\n1\\n\", \"2 1\\n1 1\\n1\\n\", \"2 1\\n1 1\\n2\\n\", \"2 2\\n1 2\\n1 1\\n\", \"2 2\\n2 2\\n1 1\\n\", \"3 3\\n3 3 2\\n0 0 1\\n\", \"4 4\\n4 4 4 4\\n0 1 1 1\\n\", \"2 2\\n1 1\\n1 0\\n\", \"3 3\\n3 3 3\\n0 0 1\\...
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
0.125
{"tests": "{\"inputs\": [\"6\\n2 1 4 6 2 2\\n\", \"7\\n3 3 3 1 3 3 3\\n\", \"7\\n5128 5672 5805 5452 5882 5567 5032\\n\", \"10\\n1 2 2 3 5 5 5 4 2 1\\n\", \"14\\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\\n\", \"50\\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4\\n\"...
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal i...
0
{"tests": "{\"inputs\": [[\"test\", 10], [\"test\", 10, \"x\"], [\"test\", 10, \"xO\"], [\"test\", 10, \"xO-\"], [\"some other test\", 10, \"nope\"], [\"some other test\", 10, \"> \"], [\"test\", 7, \">nope\"], [\"test\", 7, \"^more complex\"], [\"test\", 7, \"\"], [\"test\", 10, \"< \"], [\"test\", 3], [\"test\", 3, \...
In the wake of the npm's `left-pad` debacle, you decide to write a new super padding method that superceds the functionality of `left-pad`. Your version will provide the same functionality, but will additionally add right, and justified padding of string -- the `super_pad`. Your function `super_pad` should take three ...
0
{"tests": "{\"inputs\": [\"76 72\\n29 4 64 68 20 8 12 50 42 46 0 70 11 37 75 47 45 29 17 19 73 9 41 31 35 67 65 39 51 55\\n25 60 32 48 42 8 6 9 7 31 19 25 5 33 51 61 67 55 49 27 29 53 39 65 35 13\\n\", \"2 3\\n1 0\\n2 0 2\\n\", \"69 72\\n18 58 46 52 43 1 55 16 7 4 38 68 14 32 53 41 29 2 59\\n21 22 43 55 13 70 4 7 31 10...
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and...
0.625
{"tests": "{\"inputs\": [\"2\\n1 2\\n3 2\\n\", \"3\\n8 3\\n0 1\\n4 8\\n\", \"1\\n1 1\\n\", \"2\\n1 3\\n3 1\", \"1\\n0 0\", \"2\\n1 5\\n5 1\", \"3\\n8 3\\n-1 1\\n5 8\", \"2\\n0 2\\n3 1\", \"2\\n0 1\\n3 2\", \"2\\n1 4\\n5 2\", \"3\\n8 3\\n-1 0\\n4 8\", \"1\\n2 2\", \"1\\n-1 -1\", \"2\\n1 0\\n1 2\", \"2\\n2 3\\n2 1\", \"1...
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: - If A and B are equal sequences, term...
0
{"tests": "{\"inputs\": [\"1\\n28\\n13\", \"3\\n19 15 5\\n0 0 0\", \"3\\n23 10 14\\n0 3 4\", \"2\\n8 13\\n5 10\", \"1\\n28\\n11\", \"3\\n23 10 14\\n0 4 4\", \"1\\n28\\n3\", \"3\\n23 10 26\\n0 4 4\", \"2\\n8 13\\n0 2\", \"1\\n28\\n5\", \"3\\n6 10 26\\n0 4 4\", \"1\\n28\\n10\", \"3\\n6 12 26\\n0 4 4\", \"2\\n14 13\\n0 3\...
Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation : * Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regar...
0
{"tests": "{\"inputs\": [\"5\\n6\\n3 2 5 6\\n2 4 6\\n3 1 3 4\\n2 1 3\\n4 1 2 4 6\\n5\\n2 2 3\\n2 1 2\\n2 1 4\\n2 4 5\\n7\\n3 1 2 6\\n4 1 3 5 6\\n2 1 2\\n3 4 5 7\\n6 1 2 3 4 5 6\\n3 1 3 6\\n2\\n2 1 2\\n5\\n2 2 5\\n3 2 3 5\\n4 2 3 4 5\\n5 1 2 3 4 5\\n\", \"1\\n6\\n4 2 3 4 5\\n2 1 2\\n2 3 5\\n2 2 5\\n6 1 2 3 4 5 6\\n\", \...
We guessed a permutation $p$ consisting of $n$ integers. The permutation of length $n$ is the array of length $n$ where each element from $1$ to $n$ appears exactly once. This permutation is a secret for you. For each position $r$ from $2$ to $n$ we chose some other index $l$ ($l < r$) and gave you the segment $p_l, p...
0
{"tests": "{\"inputs\": [[\"Hello\"], [314159], [\"314159\"], [[]], [{}], [true], [[1, 2, 3]]], \"outputs\": [[\"olleH\"], [951413], [\"951413\"], [[]], [{}], [true], [[1, 2, 3]]]}", "source": "taco"}
You have to create a function named reverseIt. Write your function so that in the case a string or a number is passed in as the data , you will return the data in reverse order. If the data is any other type, return it as it is. Examples of inputs and subsequent outputs: ``` "Hello" -> "olleH" "314159" -> "951413" ...
0
{"tests": "{\"inputs\": [\"4\\n1 4 1 1\\n\", \"5\\n1 0 1 0 1\\n\", \"1\\n1000000000\\n\", \"4\\n3 3 3 3\\n\", \"4\\n3 3 2 3\\n\", \"16\\n1 1 2 3 3 4 5 6 6 6 4 3 2 1 1 1\\n\", \"1\\n1\\n\", \"20\\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\\n\", \"1\\n0\\n\", \"2\\n0 1\\n\", \"4\\n3 3 3 3\\n\", \"1\\n0\\n\", \"16\\n1 1 2 3...
You have a multiset containing several integers. Initially, it contains $a_1$ elements equal to $1$, $a_2$ elements equal to $2$, ..., $a_n$ elements equal to $n$. You may apply two types of operations: choose two integers $l$ and $r$ ($l \le r$), then remove one occurrence of $l$, one occurrence of $l + 1$, ..., one...
0
{"tests": "{\"inputs\": [\"2\\n1 1\\n\", \"3\\n3 4 2\\n\", \"1\\n1\\n\", \"1\\n1000000000\\n\", \"3\\n1 2 3\\n\", \"2\\n2 3\\n\", \"5\\n1 4 2 1 1\\n\", \"15\\n2 72 77 69 62 73 58 9 4 95 97 14 41 79 34\\n\", \"1\\n1\\n\", \"10\\n529280935 122195401 684409084 743180136 724768643 211207376 167236398 696535490 425348743 1\...
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the i-th board to the left is h_{i}. Today Vasily...
0
{"tests": "{\"inputs\": [\"-12 -35\\n\", \"-215 -996\\n\", \"-96 -556\\n\", \"-1000 0\\n\", \"20 -21\\n\", \"0 0\\n\", \"207 -224\\n\", \"-668 970\\n\", \"-496 -644\\n\", \"253 -204\\n\", \"-129 489\\n\", \"15 -8\\n\", \"-589 952\\n\", \"0 2\\n\", \"-216 -90\\n\", \"-72 -646\\n\", \"280 342\\n\", \"0 1000\\n\", \"875 -...
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond...
0
{"tests": "{\"inputs\": [\"2 0 0\\n1 2\\n2 3\\n\", \"2 1 0\\n1 2\\n2 2\\n\", \"2 5 7\\n3 4\\n14 4\\n\", \"2 0 1\\n1 2\\n2 2\\n\", \"2 1 1\\n0 0\\n1 1\\n\", \"5 5 5\\n0 0 0 0 0\\n0 0 0 0 0\\n\", \"3 4 5\\n1 2 3\\n3 2 1\\n\", \"3 1000 0\\n1 2 3\\n-1000 -1000 -1000\\n\", \"10 300 517\\n-6 -2 6 5 -3 8 9 -10 8 6\\n5 -9 -2 6...
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined $E = \sum_{i = 1}^{n}(a_{i} - b_{i})^{2}$. You have to perform exactly k_1 operations on array A and exactly k_2 operations on array B. In one operation, you have to choose one element of the array and increase or decrea...
0.375
{"tests": "{\"inputs\": [\"10 5\\nzlsssrxujq\\n4 5\\n0 0\\n0 0\\n10 9\\n0 0\\n0 3\\n0 6\\n0 0\\n8 7\\n0 2\\n\", \"50 50\\navzqjbotzkdbrhpknuxxcndqnnkfpthvjriridgnocygczqeyy\\n3 50\\n0 0\\n24 47\\n0 0\\n0 0\\n0 36\\n0 0\\n42 0\\n0 0\\n0 0\\n0 0\\n2 9\\n40 0\\n0 0\\n0 0\\n0 0\\n20 0\\n5 0\\n11 32\\n0 0\\n8 30\\n0 34\\n0 ...
A binary tree of n nodes is given. Nodes of the tree are numbered from 1 to n and the root is the node 1. Each node can have no child, only one left child, only one right child, or both children. For convenience, let's denote l_u and r_u as the left and the right child of the node u respectively, l_u = 0 if u does not ...
0
{"tests": "{\"inputs\": [\"3\\n1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0\\n1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9\\n1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\\n4\\n3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10\\n3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1\\n3335 10 10 10 10 10 10 10 10 10 10 10 10\\n3340 8 2 7 3...
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 ...
0.125
{"tests": "{\"inputs\": [\"abrakadabrabrakadabra\\n\", \"acacacaca\\n\", \"abcabc\\n\", \"abababab\\n\", \"tatbt\\n\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\n\", \"r\\n\", \"zaz\\n\", \"zaza\\n\", \"gg\\n\", \"gagaga\\n\", \"hhhh\\n\", \"sssss\\n\", \"nx...
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение мо...
0
{"tests": "{\"inputs\": [[\"\"], [\"FFFFF\"], [\"FFFFFLFFFFFLFFFFFLFFFFFL\"], [\"LFFFFFRFFFRFFFRFFFFFFF\"], [\"LF5RF3RF3RF7\"], [\"FFFLLFFFFFFRRFFFLFFFRRFFFFFFFF\"], [\"F3L2F6R2F3LF3R2F8\"], [\"F2FLLF3F3R2FFFLF2FRRF3F2F2F\"], [\"FFLFFFLFFFFLFFFFFLFFFFFFLFFFFFFFLFFFFFFFFLFFFFFFFFFLFFFFFFFFFF\"], [\"F2LF3LF4LF5LF6LF7LF8L...
# RoboScript #2 - Implement the RS1 Specification ## Disclaimer The story presented in this Kata Series is purely fictional; any resemblance to actual programming languages, products, organisations or people should be treated as purely coincidental. ## About this Kata Series This Kata Series is based on a fictional...
0
{"tests": "{\"inputs\": [\"2 3\\n\", \"1 2\\n\", \"1 1\\n\", \"2 1\\n\", \"1 3\\n\", \"3 1\\n\", \"2 5\\n\", \"3 6\\n\", \"2 2\\n\", \"1 100000\\n\", \"100000 1\\n\", \"91697 91697\\n\", \"86821 24538\\n\", \"100000 100000\\n\", \"99999 1\\n\", \"1 99999\\n\", \"1 99998\\n\", \"99998 1\\n\", \"1 88588\\n\", \"68869 1\\...
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area. To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $n$...
0
{"tests": "{\"inputs\": [[[]], [[\"cw\"]], [[\"CW\"]], [[\"cw\", \"CAT\"]], [[\"cw\", \"CAT\", \"DOG\"]], [[\"cw\", \"CAT\", \"cw=others\"]]], \"outputs\": [[0], [1], [2], [3], [\"You need extra sleep\"], [3]]}", "source": "taco"}
Everybody know that you passed to much time awake during night time... Your task here is to define how much coffee you need to stay awake after your night. You will have to complete a function that take an array of events in arguments, according to this list you will return the number of coffee you need to stay awake...
0