info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"16\\n10 8\\n2 2\\n2 5\\n2 7\\n3 3\\n3 8\\n4 2\\n4 5\\n4 8\\n6 4\\n6 7\\n7 5\\n7 8\\n8 1\\n8 4\\n9 6\\n10 3\\n4 3\\n8\\n6 4\\n1 2\\n2 1\\n2 4\\n3 4\\n4 2\\n5 3\\n6 1\\n3 2\\n3 2\\n0\", \"16\\n10 8\\n2 2\\n2 5\\n2 7\\n3 3\\n3 8\\n4 2\\n4 5\\n4 8\\n6 4\\n6 7\\n7 5\\n7 8\\n8 1\\n8 4\\n9 6\\n10 3\...
Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Ai...
0
{"tests": "{\"inputs\": [[\"int main(int argc, char *argv[]) { return 0; }\"], [\" Yo - What's Good?! \"], [\" df af asd \"], [\"global hash\"], [\"section .text\"], [\"hash:\"], [\" xor eax, eax\"], [\" ret\"], [\"; -----> end of hash <-----\"], [\"int hash(const char *str);\"], [\"\"], [\" \"], [\" \"], [\" ...
Implement a function which takes a string, and returns its hash value. Algorithm steps: * `a` := sum of the ascii values of the input characters * `b` := sum of every difference between the consecutive characters of the input (second char minus first char, third minus second, ...) * `c` := (`a` OR `b`) AND ((NOT `a`)...
0
{"tests": "{\"inputs\": [\"5\\n0 0 1 1 2\\n2 0 1 0 0\\n\", \"4\\n0 0 2 0\\n1 1 1 1\\n\", \"3\\n0 0 0\\n0 0 0\\n\", \"1\\n0\\n0\\n\", \"5\\n0 0 0 0 0\\n0 0 0 0 0\\n\", \"3\\n0 0 1\\n1 0 0\\n\", \"20\\n0 1 1 1 1 1 4 4 4 4 4 0 5 5 5 5 5 5 5 5\\n0 4 4 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0\\n\", \"30\\n0 0 0 2 0 1 1 1 6 0 7 7 0...
There are $n$ children numbered from $1$ to $n$ in a kindergarten. Kindergarten teacher gave $a_i$ ($1 \leq a_i \leq n$) candies to the $i$-th child. Children were seated in a row in order from $1$ to $n$ from left to right and started eating candies. While the $i$-th child was eating candies, he calculated two numbe...
0
{"tests": "{\"inputs\": [[100, 0.1, 1], [100, 0.1, 2], [100, 0.1, 10], [100, 0, 10], [0, 0.1, 10], [100, 0.1, 0]], \"outputs\": [[[110, 110]], [[120, 121]], [[200, 259]], [[100, 100]], [[0, 0]], [[100, 100]]]}", "source": "taco"}
Simple interest on a loan is calculated by simply taking the initial amount (the principal, p) and multiplying it by a rate of interest (r) and the number of time periods (n). Compound interest is calculated by adding the interest after each time period to the amount owed, then calculating the next interest payment b...
0
{"tests": "{\"inputs\": [\"8\\n2 2\\n1 4\\n2 3\\n3 1\\n3 4\\n1 1\\n4 3\\n1 2\\n\", \"5\\n2 1\\n1 0\\n2 0\\n3 2\\n0 3\\n\", \"9\\n1 1\\n3 4\\n4 3\\n1 4\\n1 2\\n3 1\\n2 3\\n2 2\\n1 5\\n\", \"9\\n1 4\\n2 3\\n3 4\\n4 3\\n2 2\\n1 2\\n1 1\\n3 1\\n5 3\\n\", \"1\\n1000000000 1000000000\\n\", \"39\\n27 47\\n30 9\\n18 28\\n49 16...
Maksim walks on a Cartesian plane. Initially, he stands at the point $(0, 0)$ and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point $(0, 0)$, he can go to any of the following points in one move: $(1, 0)$; $(0, 1)$; $(-1, 0)$; $(0, -1)$. ...
0
{"tests": "{\"inputs\": [\"5\\n2\\n1 2\\n2 1\\n3\\n1 2 3\\n1 2 3\\n3\\n1 2 4\\n1 3 4\\n4\\n1 2 3 2\\n3 1 2 2\\n3\\n1 2 3\\n1 3 2\\n\", \"1\\n1\\n1\\n1\\n\", \"2\\n2\\n2 1\\n1 2\\n2\\n2 1\\n2 1\\n\", \"6\\n3\\n3 2 1\\n1 2 3\\n3\\n3 2 1\\n1 3 2\\n3\\n3 2 1\\n2 1 3\\n3\\n3 2 1\\n2 3 1\\n3\\n3 2 1\\n3 1 2\\n3\\n3 2 1\\n3 2...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
0
{"tests": "{\"inputs\": [\"4\\n1 2\\n2 3\\n3 4\\n\", \"2\\n1 2\\n\", \"5\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"5\\n1 2\\n1 3\\n2 4\\n2 5\\n\", \"4\\n1 3\\n2 3\\n3 4\\n\", \"5\\n1 2\\n1 3\\n2 4\\n1 5\\n\", \"4\\n1 3\\n2 4\\n3 4\\n\", \"4\\n1 2\\n2 3\\n2 4\\n\", \"5\\n1 2\\n2 3\\n1 4\\n1 5\\n\", \"4\\n1 2\\n1 3\\n2 4\\n\", \"4...
You are given a tree consisting of n nodes. You generate an array from the tree by marking nodes one by one. Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree. After that, until all nodes are marked, a node is equiprobably chosen and marked from the set of unmarked no...
0
{"tests": "{\"inputs\": [\"3 3\\n4 3 5\\n\", \"3 4\\n5 3 4\\n\", \"3 7\\n1 2 3\\n\", \"1 1\\n1\\n\", \"1 2\\n1\\n\", \"5 10\\n10 10 10 10 10\\n\", \"1 1000000000\\n1000000000\\n\", \"1 1000000000000\\n42\\n\", \"3 2\\n1 1 5\\n\", \"2 1\\n1 100\\n\", \"3 1\\n5 10 15\\n\", \"2 1\\n1 1000\\n\", \"3 3\\n2 4 4\\n\", \"10 1\...
The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by $s$ liters of k...
0.375
{"tests": "{\"inputs\": [\"3\\n1 3 3\\n1 2 2\\n1 3 2\\n\", \"5\\n6 3 2 5 0\\n1 2 10\\n2 3 3\\n2 4 1\\n1 5 1\\n\", \"1\\n42\\n\", \"10\\n11 43 11 96 18 53 25 89 31 41\\n2 4 41\\n7 1 88\\n3 2 19\\n10 3 38\\n8 4 97\\n7 5 21\\n7 2 71\\n3 6 69\\n9 5 19\\n\", \"10\\n28 8 0 1 5 2 9 1 2 81\\n10 1 9\\n6 5 78\\n8 4 38\\n3 10 74\...
The Fair Nut is going to travel to the Tree Country, in which there are $n$ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city $u$ and go by a simple path to city $v$. He hasn't determined t...
0
{"tests": "{\"inputs\": [\"1\\n1000000000\\n\", \"2\\n5 8\\n\", \"5\\n52 67 72 25 79\\n\", \"2\\n8 8\", \"1\\n1000010000\", \"5\\n20 67 72 25 79\", \"2\\n8 6\", \"1\\n1000000010\", \"5\\n2 67 72 25 79\", \"1\\n1000000110\", \"5\\n2 67 72 25 55\", \"2\\n11 0\", \"1\\n1000000111\", \"5\\n2 67 16 25 55\", \"1\\n1000000101...
For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows: - Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations. - Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \time...
0
{"tests": "{\"inputs\": [\"2 2\\n\", \"123 456789\\n\", \"250 1000000000\\n\", \"250 1\\n\", \"1 3\\n\", \"3 497285769\\n\", \"3 212096267\\n\", \"4 221874066\\n\", \"244 315404017\\n\", \"218 325181815\\n\", \"246 629926913\\n\", \"216 639704712\\n\", \"244 22597665\\n\", \"218 737408162\\n\", \"242 747185961\\n\", \"...
You have $n \times n$ square grid and an integer $k$. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between $1$ and $k$ inclusive. Minimum number of the $i$-th row is $1$ ($1 \le i \le n$). Minimum number of the $j$-th column is $1$ ($1 \le j \le n$). Find the...
0.625
{"tests": "{\"inputs\": [\"5\\n1 2 1 2 1\\n\", \"4\\n1 1 1 1\\n\", \"4\\n1 2 1 2\\n\", \"8\\n2 1 2 1 1 1 1 1\\n\", \"14\\n2 1 2 1 1 1 1 2 1 1 2 1 2 1\\n\", \"10\\n1 1 2 2 1 1 2 2 1 1\\n\", \"20\\n1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1\\n\", \"186\\n2 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 1 ...
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the ne...
0.25
{"tests": "{\"inputs\": [[\"3\", \"1 1 1 1\", \"2 2 1 1\", \"2 3 1 1\"], \"3\\n0 1 1 1\\n2 2 1 1\\n2 3 1 1\", \"3\\n0 1 1 1\\n4 2 1 1\\n2 3 1 1\", \"3\\n0 1 1 1\\n4 1 1 1\\n2 3 1 1\", \"3\\n-1 1 1 0\\n4 1 1 1\\n2 3 0 1\", \"3\\n-1 1 1 0\\n4 1 1 1\\n2 3 -1 1\", \"3\\n-1 1 1 0\\n4 1 1 2\\n2 0 -1 2\", \"3\\n-2 1 1 0\\n8 1...
-----Problem Statement----- Sereja has a sequence of n integers a[1], a[2], ..., a[n]. Sereja can do following transformation of the array: - create a new sequence of n integers b[1], b[2], ..., b[n]in this way: (1 ≤ i ≤ n) - Replace the sequence a by b, i.e., a[i] = b[i] for all i in [1, n] Sereja decided to us...
0
{"tests": "{\"inputs\": [[\"In 2015, I want to know how much does iPhone 6+ cost?\"], [\"1+1=2\"], [\"e=mc^2\"], [\"aHR0cDovL3d3dy5jb2Rld2Fycy5jb20va2F0YS9uZXcvamF2YXNjcmlwdA==\"], [\"a30561ff4fb19170aa598b1431b52edad1fcc3e0\"], [\"x1KT CmZ__\\rYouOY8Uqu-ETtz\"], [\"x1KT-8&*@\\\"CmZ__\\rYouO __Y8Uq\\\\u-ETtz\"], [\"...
Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string. Note: - Consecutive integers should be treated as a single number. eg, `2015` should be treated as a single number `2015`, NOT four numbers - All the numbers should be treaded as positive integer. eg, `11-14`...
0
{"tests": "{\"inputs\": [\"12\\n1052\\n8888\\n6\\n75\\n128\\n1\\n301\\n12048\\n1504\\n6656\\n1000000000\\n687194767\\n\", \"1\\n1\\n\", \"2\\n1\\n1\\n\", \"3\\n1\\n1\\n1\\n\", \"1\\n99999\\n\", \"1\\n1\\n\", \"1\\n99999\\n\", \"3\\n1\\n1\\n1\\n\", \"2\\n1\\n1\\n\", \"1\\n196536\\n\", \"3\\n1\\n2\\n1\\n\", \"12\\n825\\n...
You are given an integer $n$. In $1$ move, you can do one of the following actions: erase any digit of the number (it's acceptable that the number before the operation has exactly one digit and after the operation, it is "empty"); add one digit to the right. The actions may be performed in any order any number of ti...
0
{"tests": "{\"inputs\": [[\"hello\", \"world\", \"l\"], [\"coding\", \"anywhere\", \"n\"], [\"jason\", \"samson\", \"s\"], [\"wonderful\", \"people\", \"e\"], [\"person\", \"here\", \"e\"], [\"apowiejfoiajsf\", \"iwahfeijouh\", \"j\"], [\"abcdefxxxyzz\", \"abcxxxyyyxyzz\", \"x\"], [\"12345654321\", \"123456789\", \"6\"...
Given two words and a letter, return a single word that's a combination of both words, merged at the point where the given letter first appears in each word. The returned word should have the beginning of the first word and the ending of the second, with the dividing letter in the middle. You can assume both words will...
0
{"tests": "{\"inputs\": [\"3 6\", \"1 0\", \"1 -1\", \"1 -2\", \"1 -4\", \"1 -3\", \"1 -7\", \"1 -12\", \"1 -5\", \"1 -10\", \"1 -20\", \"1 -33\", \"1 -36\", \"1 -26\", \"1 -9\", \"1 -6\", \"1 -8\", \"1 -16\", \"1 2\", \"6 6\", \"0 2\", \"5 6\", \"-1 2\", \"7 6\", \"0 1\", \"8 6\", \"8 11\", \"0 3\", \"1 3\", \"4 6\", ...
Given are positive integers N and K. Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one of those triples. * For every integer i from 1 to N, a_...
0.125
{"tests": "{\"inputs\": [\"3 11\\n2 3 1 2 2 2 3 2 2 3 1\\n\", \"4 8\\n4 1 3 3 2 3 3 3\\n\", \"5 20\\n1 4 4 2 1 1 3 5 4 2 2 4 5 2 3 3 4 5 1 4\\n\", \"1 1\\n1\\n\", \"1 20\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n\", \"10 1\\n1\\n\", \"10000 10\\n10000 9999 9998 9997 9996 9995 9994 9993 9992 9991\\n\", \"5 2\\n3 3\\n\...
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features $n$ problems of distinct difficulty, the difficulties are numbered from $1$ to $n$. To hold a round Arkady needs $n$ new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the ...
0.875
{"tests": "{\"inputs\": [\"1 1 1\\n1 1\\n\", \"5 10 30\\n5 3\\n5 5\\n5 10\\n1 2\\n5 7\\n1 8\\n4 9\\n2 3\\n4 10\\n3 1\\n4 5\\n3 8\\n1 7\\n2 2\\n1 5\\n2 3\\n3 2\\n3 10\\n3 2\\n2 7\\n2 4\\n1 4\\n4 8\\n2 6\\n4 1\\n5 3\\n4 6\\n5 8\\n4 5\\n1 1\\n\", \"3 3 10\\n1 2\\n1 3\\n2 2\\n2 2\\n2 2\\n3 2\\n2 2\\n3 2\\n2 3\\n3 1\\n\", \...
You are given a matrix, consisting of n rows and m columns. The rows are numbered top to bottom, the columns are numbered left to right. Each cell of the matrix can be either free or locked. Let's call a path in the matrix a staircase if it: * starts and ends in the free cell; * visits only free cells; * ha...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 6 6\\n4\\n1 1\\n3 1\\n1 1\\n4 3\\n\", \"3\\n1 2 3\\n2\\n1 1\\n3 1\\n\", \"1\\n1\\n5\\n1 2\\n1 10\\n1 10\\n1 10\\n1 10\\n\", \"8\\n6 10 18 23 30 31 31 33\\n1\\n5 3\\n\", \"7\\n8 13 19 21 25 30 32\\n3\\n5 4\\n6 5\\n1 2\\n\", \"5\\n4 7 10 12 12\\n9\\n3 9\\n2 1\\n3 5\\n4 7\\n1 1\\n5 1\\...
Dima's got a staircase that consists of n stairs. The first stair is at height a_1, the second one is at a_2, the last one is at a_{n} (1 ≤ a_1 ≤ a_2 ≤ ... ≤ a_{n}). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width w_{i} and height h_{i}....
0.625
{"tests": "{\"inputs\": [\"4\\n5 2 2 1\\n\", \"8\\n4 5 2 2 1 3 5 5\\n\", \"1\\n4\\n\", \"4\\n4 4 4 4\\n\", \"2\\n3166 2658\\n\", \"19\\n26 26 26 26 26 26 26 26 26 26 26 63 63 68 68 68 81 81 81\\n\", \"29\\n4763 4743 4742 4752 4739 4740 4753 4738 4744 4741 4746 4737 4757 4764 4750 4745 4755 4761 4749 4759 4747 4736 4756...
You are given a line of $n$ colored squares in a row, numbered from $1$ to $n$ from left to right. The $i$-th square initially has the color $c_i$. Let's say, that two squares $i$ and $j$ belong to the same connected component if $c_i = c_j$, and $c_i = c_k$ for all $k$ satisfying $i < k < j$. In other words, all squa...
0
{"tests": "{\"inputs\": [\"3 2\\n353\\n\", \"4 2\\n1234\\n\", \"5 4\\n99999\\n\", \"5 4\\n41242\\n\", \"5 2\\n16161\\n\", \"2 1\\n33\\n\", \"2 1\\n99\\n\", \"2 1\\n31\\n\", \"2 1\\n33\\n\", \"5 1\\n99999\\n\", \"5 1\\n26550\\n\", \"5 1\\n22222\\n\", \"5 2\\n99999\\n\", \"5 2\\n16137\\n\", \"5 3\\n99999\\n\", \"5 3\\n91...
You are given an integer $x$ of $n$ digits $a_1, a_2, \ldots, a_n$, which make up its decimal notation in order from left to right. Also, you are given a positive integer $k < n$. Let's call integer $b_1, b_2, \ldots, b_m$ beautiful if $b_i = b_{i+k}$ for each $i$, such that $1 \leq i \leq m - k$. You need to find t...
0.625
{"tests": "{\"inputs\": [\"8\\nbacabcab\\n\", \"4\\nbcda\\n\", \"6\\nabbbbb\\n\", \"1\\na\\n\", \"1\\nt\\n\", \"100\\nciftajmzqbfkvbhnyugneialytrkwjlhzwltylptheadmypbjxdzkxnqovimgmzkwpuelzbbhciinfiyspfatgoexeezolulnliu\\n\", \"100\\nyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
You are given a string $s$ consisting of lowercase Latin letters. Let the length of $s$ be $|s|$. You may perform several operations on this string. In one operation, you can choose some index $i$ and remove the $i$-th character of $s$ ($s_i$) if at least one of its adjacent characters is the previous letter in the La...
0
{"tests": "{\"inputs\": [\"1 3\\n1 -1 0\\n0 0 5\\n1 0 0\", \"3 5\\n0 0 1\\n0 1 2\\n0 2 3\\n1 0 2\\n1 1 4\", \"1 3\\n1 -1 0\\n0 0 9\\n1 0 0\", \"3 5\\n0 0 1\\n0 2 2\\n0 2 3\\n1 0 2\\n1 1 2\", \"1 3\\n1 -1 0\\n0 0 5\\n0 0 0\", \"1 3\\n1 -1 0\\n0 0 15\\n1 0 0\", \"3 5\\n0 0 1\\n0 2 2\\n0 2 3\\n1 0 2\\n0 1 2\", \"3 5\\n0 0...
Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 10000...
0
{"tests": "{\"inputs\": [[\"1123\"], [\"1\"], [\"11\"], [\"a\"], [\"a123\"], [\"21\"], [\"1211\"], [\"12322212223443\"], [\"\"], [\"123a\"]], \"outputs\": [[\"211213\"], [\"11\"], [\"21\"], [\"\"], [\"\"], [\"1211\"], [\"111221\"], [\"111213321132132413\"], [\"\"], [\"\"]]}", "source": "taco"}
Given a string of integers, count how many times that integer repeats itself, then return a string showing the count and the integer. Example: `countMe('1123')` (`count_me` in Ruby) - Here 1 comes twice so `` will be `"21"` - then 2 comes once so `` will be `"12"` - then 3 comes once so `` will be `"13"` hence outp...
0.5
{"tests": "{\"inputs\": [\"9\\n4 1 8 6 7 5 2 9 3\\n\", \"95\\n68 56 24 89 79 20 74 69 49 59 85 67 95 66 15 34 2 13 92 25 84 77 70 71 17 93 62 81 1 87 76 38 75 31 63 51 35 33 37 11 36 52 23 10 27 90 12 6 45 32 86 26 60 47 91 65 58 80 78 88 50 9 44 4 28 29 22 8 48 7 19 57 14 54 55 83 5 30 72 18 82 94 43 46 41 3 61 53 73 ...
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace...
0
{"tests": "{\"inputs\": [[[0, 0, 0], 0], [[3, 2, 10, 4, 1, 6, 9], 15], [[2, 10, 4, 1, 6, 9], 15], [[3, 2, 10, 4, 1, 6], 15], [[1, 1, 8, 3, 1, 1], 15], [[1, 1, 8, 3, 1, 1], 11], [[1, 1, 8, 3, 1, 1], 13], [[9, 0, 6], 0], [[], 25], [[25], 25], [[25, 26, 23, 24], 0], [[2, 1, 2], 0], [[1, 1, 15, -1, -1], 15], [[1, 1, 15, -1...
An array is called `centered-N` if some `consecutive sequence` of elements of the array sum to `N` and this sequence is preceded and followed by the same number of elements. Example: ``` [3,2,10,4,1,6,9] is centered-15 because the sequence 10,4,1 sums to 15 and the sequence is preceded by two elements [3,2] and foll...
0
{"tests": "{\"inputs\": [\"2 4\\n\", \"2 9999999\\n\", \"10000000 2\\n\", \"6407688 3000816\\n\", \"861392 6200826\\n\", \"999999 92321\\n\", \"4108931 211273\\n\", \"999999 999999\\n\", \"1507925 5483803\\n\", \"4 1\\n\", \"1001 1500126\\n\", \"1 10000000\\n\", \"9900111 1082917\\n\", \"31623 10000000\\n\", \"191919 1...
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a]. By <image> we denote the quotient of integer division of...
0
{"tests": "{\"inputs\": [\"5 5\\n%#... ...#%\\n.#.#. .#.#.\\n.#.#. .#.#.\\n.#.#. .#.#.\\n...#L R#...\\n3 2\\n.L. .R#\\n%.. .&.\\n4 1\\nL.%. %..R\\n0 0\", \"5 5\\n%#... .%.#.\\n.#.#. .#.#.\\n.#.#. .#.#.\\n.#.#. .#.#.\\n...#L R#...\\n3 2\\n.L. .R#\\n%.. .&.\\n4 1\\nL.%. %..R\\n0 0\", \"5 5\\n%#... ...#%\\n.#.#. .#.#.\\n....
Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room. For convenience, each of the two rooms is considered to have W × H cells arranged in a grid pattern. The outside of the room is s...
0
{"tests": "{\"inputs\": [\"3\\n5 3\\n1 2 3 4 5\\n3 2 5\\n4 3\\n4 3 2 1\\n4 3 1\\n7 4\\n1 4 7 3 6 2 5\\n3 2 4 5\\n\", \"6\\n2 1\\n2 1\\n1\\n3 2\\n1 3 2\\n1 3\\n4 2\\n4 1 3 2\\n1 2\\n5 3\\n4 3 2 5 1\\n1 4 5\\n6 3\\n2 4 5 6 1 3\\n2 4 5\\n7 3\\n7 6 4 3 2 1 5\\n1 2 6\\n\", \"6\\n2 1\\n2 1\\n1\\n3 2\\n1 3 2\\n1 3\\n4 2\\n4 1...
We start with a permutation $a_1, a_2, \ldots, a_n$ and with an empty array $b$. We apply the following operation $k$ times. On the $i$-th iteration, we select an index $t_i$ ($1 \le t_i \le n-i+1$), remove $a_{t_i}$ from the array, and append one of the numbers $a_{t_i-1}$ or $a_{t_i+1}$ (if $t_i-1$ or $t_i+1$ are wi...
0
{"tests": "{\"inputs\": [\"3 5\\n123\\n52\\n82\\n84\\n70\\n2 4\\n10\\n30\\n40\\n60\\n0 0\", \"3 5\\n123\\n52\\n82\\n84\\n124\\n2 4\\n18\\n30\\n40\\n60\\n0 0\", \"1 5\\n90\\n52\\n82\\n84\\n70\\n2 4\\n10\\n30\\n40\\n60\\n0 0\", \"1 5\\n90\\n52\\n82\\n84\\n70\\n2 4\\n10\\n43\\n22\\n60\\n0 0\", \"3 5\\n123\\n52\\n82\\n87\\...
There are various parking lots such as three-dimensional type and tower type in the city to improve the utilization efficiency of the parking lot. In some parking lots, a "two-stage parking device" as shown in the figure is installed in one parking space to secure a parking space for two cars. This two-stage parking de...
0
{"tests": "{\"inputs\": [\"4\\n2 5\\n10 10\\n2 5\\n3 3\\n4 5\\n5 2 4 9\\n8 8\\n5 3 3 6 10 100 9 15\\n\", \"1\\n10 243864180\\n886547706 549473499 522487623 522487623 522487623 694839856 347419928 5067 79578125 636625000\\n\", \"1\\n2 1000000000\\n1000000000 1000000000\\n\", \"3\\n2 1000000000\\n5 5\\n2 1000000000\\n4 7...
You are given an array $a$ of $n$ ($n \geq 2$) positive integers and an integer $p$. Consider an undirected weighted graph of $n$ vertices numbered from $1$ to $n$ for which the edges between the vertices $i$ and $j$ ($i<j$) are added in the following manner: If $gcd(a_i, a_{i+1}, a_{i+2}, \dots, a_{j}) = min(a_i, a_{...
0
{"tests": "{\"inputs\": [[\"din\"], [\"recede\"], [\"Success\"], [\"CodeWarrior\"], [\"Supralapsarian\"], [\"iiiiii\"], [\"(( @\"], [\" ( ( )\"]], \"outputs\": [[\"(((\"], [\"()()()\"], [\")())())\"], [\"()(((())())\"], [\")()))()))))()(\"], [\"))))))\"], [\"))((\"], [\")))))(\"]]}", "source": "taco"}
The goal of this exercise is to convert a string to a new string where each character in the new string is `"("` if that character appears only once in the original string, or `")"` if that character appears more than once in the original string. Ignore capitalization when determining if a character is a duplicate. ##...
0
{"tests": "{\"inputs\": [\"3 1 100 100\\n1 3 8\\n\", \"3 100 1 100\\n1 3 8\\n\", \"3 100 100 1\\n1 3 8\\n\", \"5 1 2 4\\n5 5 3 6 5\\n\", \"5 1 2 2\\n5 5 3 6 5\\n\", \"10 7 8 3\\n3 10 4 9 2 7 6 10 4 8\\n\", \"10 7122 8827 3205\\n452685204 144160553 743427456 403576146 888744473 313727757 22025193 886601085 576370788 787...
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You are allowed the following operations: put a brick on top of one p...
0
{"tests": "{\"inputs\": [\"3\\n2\\n1 5 10\\n2 15 5\\n3\\n2 93 78\\n1 71 59\\n3 57 96\\n19\\n19 23 16\\n5 90 13\\n12 85 70\\n19 67 78\\n12 16 16\\n18 48 28\\n5 4 24\\n12 97 97\\n4 57 87\\n19 91 74\\n18 100 76\\n7 86 46\\n9 100 57\\n3 76 73\\n6 84 93\\n1 6 84\\n11 75 94\\n19 15 3\\n12 11 34\", \"3\\n2\\n1 5 10\\n2 15 5\\...
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row. The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise. Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel. Solve this probl...
0
{"tests": "{\"inputs\": [\"5\\n2 3\\n1 7\\n5 5\\n3 1\\n8 15\", \"5\\n2 3\\n1 7\\n4 5\\n3 1\\n8 15\", \"5\\n2 3\\n1 7\\n4 6\\n4 1\\n8 15\", \"5\\n1 3\\n1 7\\n4 6\\n4 1\\n8 25\", \"5\\n1 3\\n1 8\\n12 6\\n4 1\\n5 25\", \"5\\n1 3\\n1 8\\n12 6\\n4 0\\n5 25\", \"5\\n1 3\\n1 8\\n12 11\\n4 0\\n5 25\", \"5\\n0 3\\n0 2\\n12 11\\...
The executive chef is trying to bring some competitive spirit into his kitchen. He wants to split the chefs into two teams based on their age - he'll form the young and the old team. To make it fair, he will split them evenly or give the young team one person advantage when there is an odd number of chefs. Ages of all ...
0
{"tests": "{\"inputs\": [[[[2, 2, 2], [4, 2, 6], [8, 8, 2]]], [[[7, 2, 2], [4, 2, 6], [1, 8, 1]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 2, 2, 5, 1], [4, 1, 6, 1, 1], [1, 8, 5, 6, 2], [1, 5, 2, 1, 2], [1, 8, 2, 6, 1]]], [[[88, 2, 2, 5, 1, 1, 2, 2, 5, 1], [4, 1, 6, 1, 1, 1, 2, 2, 7, 1], [1, 8, 1, 6, 2, 1, 2, 1, 5, ...
**Principal Diagonal** -- The principal diagonal in a matrix identifies those elements of the matrix running from North-West to South-East. **Secondary Diagonal** -- the secondary diagonal of a matrix identifies those elements of the matrix running from North-East to South-West. For example: ``` matrix: [...
0
{"tests": "{\"inputs\": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20]], \"outputs\": [[1], [2], [6], [12], [60], [60], [420], [840], [2520], [2520], [27720], [27720], [360360], [360360], [360360], [720720], [12252240], [12252240], [232792560], [232792560]...
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Task: Write ``` smallest(n) ``` that will find the smallest positive number that is evenly divisible by all of the numbers from 1 to n (n <= 40). E.g ```python smallest(5) == 60 # 1 to 5 can all divide evenly int...
0.875
{"tests": "{\"inputs\": [\"6 2 3\\n2 2 2 2 1 1\\n\", \"2 5 1\\n5 8\\n\", \"1 1 1\\n1\\n\", \"3 2 3\\n999999998 999999998 999999998\\n\", \"10 8 3\\n499 498 497 497 497 497 497 497 498 499\\n\", \"11 18 8\\n4996 4993 4988 4982 4982 4982 4982 4982 4986 4989 4994\\n\", \"1 100000 1\\n1000000000\\n\", \"4 100 3\\n1 100000 ...
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti...
0.125
{"tests": "{\"inputs\": [\"1 0\\n1 1 100 100\\n\", \"11 8\\n9 1 11 5\\n2 2 8 12\\n3 8 23 10\\n2 1 10 5\\n7 1 19 5\\n1 8 3 10\\n1 5 3 9\\n1 2 3 4\\n1 2 3 4\\n4 2 12 16\\n8 5 12 9\\n\", \"1 0\\n1 1 1000000000 1000000000\\n\", \"2 1\\n1 1 1000000000 1000000000\\n100 200 200 300\\n\", \"1 0\\n1 1 4 4\\n\", \"2 1\\n1 1 1000...
Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit...
0
{"tests": "{\"inputs\": [\"CD 51 1\\nDB 30 1\", \"CD 51 0\\nDB 55 1\", \"CD 51 1\\nDB 55 1\", \"CD 51 1\\nDB 19 1\", \"CD 51 1\\nDB 55 0\", \"CD 51 0\\nDB 56 1\", \"CD 14 1\\nDB 55 0\", \"CD 20 1\\nDB 55 0\", \"CD 30 1\\nDB 30 2\", \"CD 51 0\\nDB 54 1\", \"CD 51 1\\nDB 19 0\", \"CD 51 1\\nDB 56 1\", \"CD 14 1\\nDB 61 0...
Problem G Rendezvous on a Tetrahedron One day, you found two worms $P$ and $Q$ crawling on the surface of a regular tetrahedron with four vertices $A$, $B$, $C$ and $D$. Both worms started from the vertex $A$, went straight ahead, and stopped crawling after a while. When a worm reached one of the edges of the tetrahe...
0
{"tests": "{\"inputs\": [[1], [7], [9], [23], [32], [79], [98], [987654322]], \"outputs\": [[\"Jumping!!\"], [\"Jumping!!\"], [\"Jumping!!\"], [\"Jumping!!\"], [\"Jumping!!\"], [\"Not!!\"], [\"Jumping!!\"], [\"Not!!\"]]}", "source": "taco"}
# Definition **_Jumping number_** is the number that *All adjacent digits in it differ by 1*. ____ # Task **_Given_** a number, **_Find if it is Jumping or not_** . ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers) ___ # Notes * **_N...
0
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n2 3 -1\\n\", \"2\\n-1 100\\n2 -1\\n\", \"10\\n-10 -1 2 2 5 -2 -3 -4 2 -6\\n-1 -1 2 2 -1 5 5 7 7 9\\n\", \"10\\n-10 -1 2 2 5 -2 -3 -4 2 -6\\n-1 -1 2 2 -1 5 5 7 7 9\\n\", \"10\\n-10 -1 2 3 5 -2 -3 -4 2 -6\\n-1 -1 2 2 -1 5 5 7 7 9\\n\", \"2\\n-1 000\\n2 -1\\n\", \"10\\n-10 -1 2 3 5 -...
Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an absurdly high reward: one day off. The problem itself sounds like t...
0
{"tests": "{\"inputs\": [[10, [2, 1, 3], 6], [10, [2, 1, 3], 15], [10, [2, 1, 3], 50], [10, [2, 1, 3], 78], [10, [2, 1, 3], 157], [10, [2, 2, 5, 8], 6], [10, [2, 2, 5, 8], 15], [10, [2, 2, 5, 8], 50], [10, [2, 2, 5, 8], 78], [10, [2, 2, 5, 8], 157], [100, [2, 2, 5, 8], 6], [100, [2, 2, 5, 8], 15], [100, [2, 2, 5, 8], 5...
We have the first value of a certain sequence, we will name it ```initVal```. We define pattern list, ```patternL```, an array that has the differences between contiguous terms of the sequence. ``` E.g: patternL = [k1, k2, k3, k4]``` The terms of the sequence will be such values that: ```python term1 = initVal term2...
0
{"tests": "{\"inputs\": [[-12], [0, -1], [0, 12], [0], [1], [1, 5], [1, 9], [1632, 2], [5000], [5001], [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11]], \"outputs\": [[\"NaR\"], [\"NaR\"], [\"NaR\"], [\"N\"], [\"I\"], [\"I:.:\"], [\"IS:.\"], [\"MDCXXXII:\"], [\"MMMMM\"],...
We all know about Roman Numerals, and if not, here's a nice [introduction kata](http://www.codewars.com/kata/5580d8dc8e4ee9ffcb000050). And if you were anything like me, you 'knew' that the numerals were not used for zeroes or fractions; but not so! I learned something new today: the [Romans did use fractions](https:/...
0
{"tests": "{\"inputs\": [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]], \"outputs\": [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, 4, 7, 13, ...
Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :( ...
0
{"tests": "{\"inputs\": [\"10\\nmihail\\noolyana\\nkooooper\\nhoon\\nulyana\\nkoouper\\nmikhail\\nkhun\\nkuooper\\nkkkhoon\\n\", \"9\\nhariton\\nhkariton\\nbuoi\\nkkkhariton\\nboooi\\nbui\\nkhariton\\nboui\\nboi\\n\", \"2\\nalex\\nalex\\n\", \"40\\nuok\\nkuu\\nku\\no\\nkku\\nuh\\nu\\nu\\nhh\\nk\\nkh\\nh\\nh\\nou\\nokh\...
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
0
{"tests": "{\"inputs\": [\"6 3\\n12 10 20 20 25 30\\n10 20 30\\n\", \"4 2\\n1 3 3 7\\n3 7\\n\", \"8 2\\n1 2 2 2 2 2 2 2\\n1 2\\n\", \"18 10\\n8 1 2 3 4 9 9 5 1 6 6 7 8 6 2 9 10 7\\n1 2 3 4 5 6 7 8 9 10\\n\", \"1 1\\n1000000000\\n1000000000\\n\", \"1 1\\n1\\n1\\n\", \"5 1\\n7 10 3 11 3\\n3\\n\", \"5 1\\n7 10 3 11 2\\n3\...
You are given two arrays $a_1, a_2, \dots , a_n$ and $b_1, b_2, \dots , b_m$. Array $b$ is sorted in ascending order ($b_i < b_{i + 1}$ for each $i$ from $1$ to $m - 1$). You have to divide the array $a$ into $m$ consecutive subarrays so that, for each $i$ from $1$ to $m$, the minimum on the $i$-th subarray is equal t...
0.125
{"tests": "{\"inputs\": [\"3 20\\n2 80\\n5 120\\n16 1\", \"3 20\\n2 1\\n9 120\\n16 1\", \"3 20\\n0 80\\n9 1\\n16 120\", \"1 100100000000000\\n50000000000000 1\", \"15 10000000000\\n400000000 1000000000\\n800000000 1000000000\\n1900000000 1000000000\\n2400000000 1000000000\\n2900000000 1000000000\\n3300000000 1000000000...
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on...
0
{"tests": "{\"inputs\": [[[2, 3], 1, 3], [[1, 3, 5], 1, 1], [[1, 3, 5], 1, 10], [[], 1, 10], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1, 10], [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 1, 10], [[5, 4, 7, 8, 9, 6, 3, 2, 10, 1], 1, 10], [[-2], -1, 3], [[-2, 2], -1, 3], [[-2, 3], -1, 3], [[2, -3], -1, 3], [[2, 4, 7], -100, 100], [[2, 4, ...
Write a function `sumTimesTables` which sums the result of the sums of the elements specified in `tables` multiplied by all the numbers in between `min` and `max` including themselves. For example, for `sumTimesTables([2,5],1,3)` the result should be the same as ``` 2*1 + 2*2 + 2*3 + 5*1 + 5*2 + 5*3 ``` i.e. the table...
0.125
{"tests": "{\"inputs\": [\"10 3 2\\n\", \"7 1 2\\n\", \"1 1 1\\n\", \"5814 31 7\\n\", \"94268 813 766\\n\", \"262610 5583 4717\\n\", \"3898439 96326 71937\\n\", \"257593781689876390 32561717 4411677\\n\", \"111319886766128339 7862842484895022 3003994959686829\\n\", \"413850294331656955 570110918058849723 40985373566174...
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. [Image] Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner....
0
{"tests": "{\"inputs\": [\"3\\n4 7 8\\n\", \"2\\n2 7\\n\", \"1\\n1\\n\", \"1\\n1000000000\\n\", \"2\\n1000000000 1\\n\", \"2\\n9 6\\n\", \"2\\n948507270 461613425\\n\", \"5\\n8 7 4 8 3\\n\", \"5\\n11703 91351 99 16279 50449\\n\", \"20\\n3 2 1 1 1 2 2 2 3 3 1 1 3 2 3 3 2 3 3 2\\n\", \"20\\n895 8894 6182 5852 9830 7562 8...
There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains a_{i} balls, all of which have color i. You have to write a program that will divide all balls into sets such that: each ball belongs to exactly one of the sets, there are no empty sets, there is no set containing t...
0
{"tests": "{\"inputs\": [\"50 50\\n+ 14\\n+ 4\\n+ 20\\n+ 37\\n+ 50\\n+ 46\\n+ 19\\n- 20\\n+ 25\\n+ 47\\n+ 10\\n+ 6\\n+ 34\\n+ 12\\n+ 41\\n- 47\\n+ 9\\n+ 22\\n+ 28\\n- 41\\n- 34\\n+ 47\\n+ 40\\n- 12\\n+ 42\\n- 9\\n- 4\\n+ 15\\n- 15\\n+ 27\\n+ 8\\n+ 38\\n+ 9\\n+ 4\\n+ 17\\n- 8\\n+ 13\\n- 47\\n+ 7\\n- 9\\n- 38\\n+ 30\\n+ ...
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated. In 2312 there was a startling discovery:...
0
{"tests": "{\"inputs\": [[\"Your girlscout cookies are ready to ship. Your total comes to tree fiddy\"], [\"Howdy Pardner. Name's Pete Lexington. I reckon you're the kinda stiff who carries about tree fiddy?\"], [\"I'm from Scottland. I moved here to be with my family sir. Please, $3.50 would go a long way to help me f...
You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to shift octaves by 8 pitches or something silly like that, it dawns ...
0
{"tests": "{\"inputs\": [\"3\\n3 10\\n6 3\\n8 2\\n1 4\\n4 10\\n4 1\\n3 2\\n2 6\\n1 100\\n2 15\\n10 11\\n14 100\\n\", \"7\\n5 1000000000\\n2 1\\n1 10\\n1 1\\n4 1000000000\\n3 3\\n1 1000000000\\n5 1\\n2 999999999\\n3 1\\n2 10000000\\n4 10000000\\n10000000 999999999\\n9999900 12\\n9999999 55\\n9999999 1\\n2 1000000\\n1000...
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! $m$ Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $cur...
0.125
{"tests": "{\"inputs\": [[\"5*4+6\"], [\"5+4*6\"], [\"3*8+6*5\"], [\"5*8+6*3*2\"], [\"5.4*4.0+6.2+8.0\"], [\"0.5*1.2*56+9.6*5*81+1\"], [\"1\"], [\"1.333333333*1.23456789+0.003*0.002\"]], \"outputs\": [[\"2.60000e+01\"], [\"2.90000e+01\"], [\"5.40000e+01\"], [\"7.60000e+01\"], [\"3.58000e+01\"], [\"3.92260e+03\"], [\"1....
Write a function that solves an algebraic expression given as a string. * The expression can include only sums and products. * The numbers in the expression are in standard notation (NOT scientific). * In contrast, the function should return a string with the calculated value given in scientific notation with 5 de...
0.25
{"tests": "{\"inputs\": [\"2\\n4\\nBegin on Road A\\nRight on Road B\\nRight on Road C\\nLeft on Road D\\n6\\nBegin on Old Madras Road\\nLeft on Domlur Flyover\\nLeft on 100 Feet Road\\nRight on Sarjapur Road\\nRight on Hosur Road\\nRight on Ganapathi Temple Road\", \"2\\n4\\nBegin on Road A\\nRight on Road B\\nRight o...
Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant. A set of directions consists of several instructions. The first instruction is of the form "Begin on XXX", i...
0
{"tests": "{\"inputs\": [[15], [18], [19], [false], [\"wow doge\"], [0.0435]], \"outputs\": [[8], [6], [18], [0], [0], [0]]}", "source": "taco"}
In number theory, Euler's totient is an arithmetic function, introduced in 1763 by Euler, that counts the positive integers less than or equal to `n` that are relatively prime to `n`. Thus, if `n` is a positive integer, then `φ(n)`, notation introduced by Gauss in 1801, is the number of positive integers `k ≤ n` for wh...
0
{"tests": "{\"inputs\": [[[1, 2], [2, 1]], [[1, -2], [2, 1]], [[7, 8], [7, -6]], [[-13, -26], [-8, 4]], [[1, 2, 3], [0, -3, 2]], [[3, 4, 5], [6, 7, -8]], [[3, -4, -5], [-4, -3, 0]], [[1, -2, 3, -4], [-4, 3, 2, -1]], [[2, 4, 5, 6, 7], [-14, -12, 0, 8, 4]], [[5, 10, 1, 20, 2], [-2, -20, -1, 10, 5]]], \"outputs\": [[false...
Suppose I have two vectors: `(a1, a2, a3, ..., aN)` and `(b1, b2, b3, ..., bN)`. The dot product between these two vectors is defined as: ``` a1*b1 + a2*b2 + a3*b3 + ... + aN*bN ``` The vectors are classified as orthogonal if the dot product equals zero. Complete the function that accepts two sequences as inputs an...
0
{"tests": "{\"inputs\": [\"4\\n3 2 2 3\\n\", \"6\\n4 5 6 3 2 1\\n\", \"10\\n6 8 4 6 7 1 6 3 4 5\\n\", \"6\\n5 5 5 6 4 6\\n\", \"50\\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\\n\", \"50\\n1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 ...
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers fr...
0
{"tests": "{\"inputs\": [\"[[r-i]-[m-e]]\\ne 0\\nr 1\\ni 1\\nn 2\", \"[[m-y]-[a-o]]\\nn 0\\na 1\\ny 2\\nm 0\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\ni 1\\nn 2\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\ni 1\\nn 3\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\nh 1\\nn 3\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\ng 1\\nn 3\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\ng 1\\nm...
In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, t...
0
{"tests": "{\"inputs\": [\"3\\n2 4 8\\n\", \"4\\n1 -7 -2 3\\n\", \"10\\n35 11 35 28 48 25 2 43 23 10\\n\", \"100\\n437 89 481 95 29 326 10 304 97 414 52 46 106 181 385 173 337 148 437 133 52 136 86 250 289 61 480 314 166 69 275 486 117 129 353 412 382 469 290 479 388 231 7 462 247 432 488 146 466 422 369 336 148 460 41...
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them. The game they came up with has the following rules. In...
0
{"tests": "{\"inputs\": [\"16\\n.**.*..*.***.**.\\n\", \"11\\n.*.*...*.*.\\n\", \"53\\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.\\n\", \"71\\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**\\n\", \"56\\n**.*..*...***.*.**.**..**.*.*.*.**...*.**.**....*...**..\\n\", \"64\\n***.*...*.....
In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. [Image] An interesting feature of the game is that you can design your own levels...
0.125
{"tests": "{\"inputs\": [\"AIZV\", \"W\\\\AG\", \"[VIA\", \"BEW]\", \"VZIA\", \"V[IA\", \"W[IA\", \"AI[W\", \"AH[W\", \"HA[W\", \"HA[V\", \"GA[V\", \"GA\\\\V\", \"GA\\\\W\", \"W\\\\BG\", \"W\\\\BF\", \"FB\\\\W\", \"GB\\\\W\", \"WFB\\\\\", \"WF\\\\B\", \"B\\\\FW\", \"A\\\\FW\", \"A[FW\", \"AIZT\", \"AHZV\", \"VAI[\", \"...
A: A-Z- problem There is a circular board of 26 squares, each square with one capital letter of the alphabet written clockwise in alphabetical order. That is, the clockwise side of the'A'square is the'B' square, the next side of the'B'square is the'C'square, and ..., the clockwise side of the'Z'square is the'A'. It's...
0.125
{"tests": "{\"inputs\": [[0], [1], [4], [30], [1000], [1000000], [\"a\"], [-1], [[\"a\"]]], \"outputs\": [[[]], [[1, 1]], [[3, 8]], [[27, 112]], [[871, 179]], [[837799, 525]], [[]], [[]], [[]]]}", "source": "taco"}
The Collatz conjecture is one of the most famous one. Take any positive integer n, if it is even divide it by 2, if it is odd multiply it by 3 and add 1 and continue indefinitely.The conjecture is that whatever is n the sequence will reach 1. There is many ways to approach this problem, each one of them had given beaut...
0.875
{"tests": "{\"inputs\": [\"4\\n6\\n1 1 1 2 2 1 2 1 2 1 1 2\\n2\\n1 2 1 2\\n3\\n1 1 1 1 1 1\\n2\\n2 1 1 1\\n\", \"4\\n6\\n1 1 1 1 2 1 2 1 2 1 1 2\\n2\\n1 2 1 2\\n3\\n1 1 1 1 1 1\\n2\\n2 1 1 1\\n\", \"4\\n6\\n1 1 1 1 2 1 2 1 2 1 1 2\\n2\\n2 2 1 2\\n3\\n1 1 1 1 1 1\\n2\\n2 1 1 1\\n\", \"4\\n6\\n1 1 1 1 2 1 2 1 2 1 1 2\\n2...
Karlsson has recently discovered a huge stock of berry jam jars in the basement of the house. More specifically, there were $2n$ jars of strawberry and blueberry jam. All the $2n$ jars are arranged in a row. The stairs to the basement are exactly in the middle of that row. So when Karlsson enters the basement, he sees...
0
{"tests": "{\"inputs\": [\"6\\n2 1\\n2 1\\n1\\n3 2\\n1 3 2\\n1 3\\n4 2\\n4 1 3 2\\n1 2\\n5 3\\n4 3 2 5 1\\n1 4 5\\n6 3\\n2 4 5 6 1 3\\n2 4 5\\n7 3\\n7 6 4 3 2 1 5\\n1 2 6\\n\", \"6\\n2 1\\n2 1\\n1\\n3 2\\n1 3 2\\n1 3\\n4 2\\n4 1 3 2\\n1 2\\n5 3\\n4 4 2 5 1\\n1 4 5\\n6 3\\n2 4 5 6 1 3\\n2 4 5\\n7 3\\n7 6 4 3 2 1 5\\n1 2...
We start with a permutation a_1, a_2, …, a_n and with an empty array b. We apply the following operation k times. On the i-th iteration, we select an index t_i (1 ≤ t_i ≤ n-i+1), remove a_{t_i} from the array, and append one of the numbers a_{t_i-1} or a_{t_i+1} (if t_i-1 or t_i+1 are within the array bounds) to the r...
0
{"tests": "{\"inputs\": [\"5 5\\n-38 -71 -293 75 1\\n-158 -38 -405 66 1\\n-236 -303 157 266 1\\n316 26 411 190 1\\n207 -312 -27 196 1\\n-50 292 -375 -401 389 -389\\n460 278 409 -329 -303 411\\n215 -220 -200 309 -474 300\\n310 -494 -87 -300 123 -463\\n386 378 486 -443 -64 299\", \"5 1\\n0 10 0 5 2\\n0 20 0 6 12\\n0 30 0...
In 20XX AD, a school competition was held. The tournament has finally left only the final competition. You are one of the athletes in the competition. The competition you participate in is to compete for the time it takes to destroy all the blue objects placed in the space. Athletes are allowed to bring in competition...
0.125
{"tests": "{\"inputs\": [\"5\\n3 10\\n6 4\\n1 9\\n5 8\\n2 7\\n\", \"2\\n1 2\\n3 4\\n\", \"3\\n1 2\\n3 6\\n4 5\\n\", \"1\\n1 2\\n\", \"3\\n3 5\\n4 1\\n2 6\\n\", \"4\\n5 4\\n6 2\\n7 1\\n8 3\\n\", \"5\\n8 5\\n10 3\\n4 7\\n6 9\\n1 2\\n\", \"6\\n9 8\\n10 7\\n4 6\\n12 11\\n5 3\\n2 1\\n\", \"10\\n11 16\\n15 14\\n7 5\\n13 9\\n...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
0
{"tests": "{\"inputs\": [\"8\\n2\\n0\\n1\\n6\\n1\\n8\\n2\\n1\", \"4\\n4\\n0\\n3\\n1\", \"8\\n2\\n0\\n1\\n9\\n1\\n8\\n2\\n1\", \"4\\n3\\n0\\n3\\n1\", \"4\\n0\\n0\\n3\\n1\", \"8\\n1\\n0\\n1\\n9\\n1\\n5\\n2\\n1\", \"8\\n1\\n0\\n1\\n1\\n1\\n5\\n1\\n1\", \"8\\n0\\n0\\n1\\n4\\n1\\n5\\n1\\n1\", \"8\\n0\\n0\\n1\\n4\\n1\\n5\\n2...
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1. Snuke wants to create the maximum number of pairs from his card...
0
{"tests": "{\"inputs\": [\"10 4\\n1 5 2 9 1 3 4 2 1 7\\n2 4\\n3 8\\n7 10\\n1 9\\n\", \"7 6\\n5 7 7 4 6 6 2\\n1 2\\n2 3\\n2 6\\n1 7\\n4 7\\n3 5\\n\", \"2 2\\n0 0\\n1 2\\n1 2\\n\", \"2 2\\n0 100000000\\n1 2\\n1 2\\n\", \"4 6\\n1 2 3 2\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n3 4\\n\", \"3 6\\n10 20 30\\n1 2\\n1 3\\n2 3\\n1 2\\n2 ...
A function $f : R \rightarrow R$ is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all $x, y \in R$. We'll deal with a more... discrete version of this term. For an array $h [ 1 . . n ]$, we define it's Lipschitz constant $L(h)$ as follows: if n ...
0.5
{"tests": "{\"inputs\": [\"2 3 1 4 0 1 1 1\\n4 2 3 2 2 2 1 1\", \"2 3 1 2 0 1 1 1\\n4 2 3 2 2 2 1 1\", \"0 3 1 3 0 0 -1 2\\n1 1 5 2 -1 3 0 0\", \"0 3 1 1 0 1 -1 2\\n1 1 5 2 -1 3 0 0\", \"0 3 1 1 0 -1 -1 2\\n1 1 5 3 -1 3 0 -1\", \"0 2 0 1 0 -1 -1 2\\n1 1 5 3 -1 3 0 -1\", \"0 2 1 1 0 -1 -1 2\\n1 1 5 3 -1 0 0 -1\", \"0 4 ...
<image> You know the merry-go-round in the amusement park. Vehicles such as horses and carriages are fixed on a large disk, and it is a standard playset that the vehicle swings up and down at the same time as the disk rotates. A merry-go-round in an amusement park has two four-seater carriages, two two-seater cars, f...
0
{"tests": "{\"inputs\": [\"5 10 3\\n3 9\\n2 8\\n2 1\", \"8 10 1\\n6 6\", \"5 10 3\\n3 9\\n2 8\\n1 1\", \"10 10 3\\n3 9\\n2 8\\n1 1\", \"5 10 3\\n1 9\\n2 8\\n5 1\", \"10 10 1\\n6 2\", \"13 10 3\\n3 9\\n2 6\\n1 1\", \"5 19 3\\n2 9\\n2 8\\n1 1\", \"26 10 3\\n3 9\\n2 6\\n1 1\", \"10 19 3\\n1 9\\n0 4\\n1 1\", \"24 4 1\\n6 2...
Problem There are $ N $ streetlights on a two-dimensional square of $ W \ times H $. Gaccho wants to start with $ (1,1) $ and go to $ (W, H) $. Gaccho is afraid of dark places, so he only wants to walk in the squares that are brightened by the streetlights. Initially, all streetlights only brighten the squares with th...
0
{"tests": "{\"inputs\": [\"10 11\", \"4 3\", \"2 2\", \"314159 217986\", \"10 10\", \"1 3\", \"2 4\", \"180944 217986\", \"1 11\", \"0 3\", \"2 8\", \"180944 374453\", \"1 19\", \"1 8\", \"180944 99984\", \"1 35\", \"180944 102049\", \"1 12\", \"180944 191217\", \"1 18\", \"1 6\", \"-1 9\", \"180944 138776\", \"1 33\",...
We have a square grid with N rows and M columns. Takahashi will write an integer in each of the squares, as follows: * First, write 0 in every square. * For each i=1,2,...,N, choose an integer k_i (0\leq k_i\leq M), and add 1 to each of the leftmost k_i squares in the i-th row. * For each j=1,2,...,M, choose an intege...
0
{"tests": "{\"inputs\": [\"3\\n2 1 1\\n\", \"4\\n1 1 1 1\\n\", \"1\\n0\\n\", \"1\\n1\\n\", \"1\\n1\\n\", \"1\\n0\\n\", \"1\\n2\\n\", \"4\\n1 1 2 1\\n\", \"3\\n2 2 1\\n\", \"4\\n1 0 2 1\\n\", \"4\\n-2 1 5 0\\n\", \"1\\n-1\\n\", \"1\\n3\\n\", \"1\\n4\\n\", \"4\\n1 0 1 1\\n\", \"3\\n0 2 1\\n\", \"1\\n-2\\n\", \"1\\n6\\n\"...
The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 > 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not. A sequence of integers is called good if it can be divided into a positive number of ...
0
{"tests": "{\"inputs\": [[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]], \"outputs\": [[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89], [144], [233], [377], [610], [987], [1597], [2584], [4181], [6765], [10946]...
I love Fibonacci numbers in general, but I must admit I love some more than others. I would like for you to write me a function that when given a number (n) returns the n-th number in the Fibonacci Sequence. For example: ```python nth_fib(4) == 2 ``` Because 2 is the 4th number in the Fibonacci Sequence. For ...
0
{"tests": "{\"inputs\": [\"3 5\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"3 1\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"2 5\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"4 2\\n.....\\n.#.#/\\n.###.\\n.#.#.\\n.....\", \"0 1\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"4 1\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \...
problem Given the squares of $ R * C $. Each square is either an empty square or a square with a hole. The given square meets the following conditions. * The cells with holes are connected. (You can move a square with a hole in the cross direction to any square with a hole) * Empty cells are connected. You can gen...
0.875
{"tests": "{\"inputs\": [\"4 6\\n1 2 5 2\\n2 3 3 4\\n\", \"2 3\\n5 6\\n5 5\\n\", \"24 3\\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\\n\", \"43 5\\n6 7 15 12 15 7 22 33 38 15 7 23 31 21 26 41 25 14 26 33 5 28 22 6 35 17 19 32 41 27 20 25 5 32 37 1...
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c_1, c_2, ..., c_{n}. The Old Peykan wants to travel from city c_1 to c_{n} using roads. There are (n - 1) one way roads, the i-th road goes from city c_{i} to city c_{i} + ...
0
{"tests": "{\"inputs\": [[2, [1, 2]], [10, [10, 10]], [5, [5, 5]], [0, [0, 0]], [1, [0, 0]], [1, [0, 1]], [1, [1, 1]], [3, [3, 3]], [3, [1, 3]], [100, [100, 100]]], \"outputs\": [[3], [2], [2], [6], [5], [4], [5], [3], [1], [2]]}", "source": "taco"}
# Task You are a lifelong fan of your local football club, and proud to say you rarely miss a game. Even though you're a superfan, you still hate boring games. Luckily, boring games often end in a draw, at which point the winner is determined by a penalty shoot-out, which brings some excitement to the viewing experienc...
0
{"tests": "{\"inputs\": [\"13\\n2 3 4 5 6 7 8 5 10 11 12 13 12\", \"13\\n2 3 4 0 6 7 8 5 4 11 12 13 12\", \"13\\n2 3 4 0 6 2 8 5 4 11 13 13 12\", \"4\\n2 3 4 0\", \"13\\n2 3 4 5 6 7 4 9 10 11 12 13 12\", \"13\\n1 3 4 0 6 7 8 5 4 11 12 13 12\", \"13\\n2 3 4 0 9 2 8 5 4 11 12 13 12\", \"13\\n2 3 4 5 6 7 4 9 10 11 13 13 1...
Niwango has N cards, numbered 1,2,\ldots,N. He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangeme...
0
{"tests": "{\"inputs\": [\"7\\n1\\n2\\n3\\n6\\n100\\n25\\n3000000000000\\n\", \"7\\n1\\n2\\n3\\n6\\n100\\n25\\n3000000000000\\n\", \"7\\n1\\n2\\n3\\n4\\n100\\n25\\n3000000000000\\n\", \"7\\n1\\n2\\n3\\n6\\n110\\n25\\n3000000000000\\n\", \"7\\n1\\n2\\n3\\n4\\n100\\n25\\n1991556943611\\n\", \"7\\n1\\n1\\n3\\n6\\n110\\n25...
Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese). You are given an integer $n$. You need to find two integers $l$ and $r$ such that $-10^{18} \le l < r \le 10^{18}$ and $l + (l + 1) + \ldots + (r - 1) + r = n$. -----Input----- The firs...
0
{"tests": "{\"inputs\": [\"2 0\\n\", \"4 2\\n3 2\\n1 4\\n\", \"3 3\\n1 2\\n3 1\\n2 3\\n\", \"10 10\\n1 5\\n1 8\\n1 9\\n5 8\\n8 9\\n4 7\\n2 3\\n3 10\\n2 6\\n2 10\\n\", \"100000 0\\n\", \"3 1\\n2 3\\n\", \"2 1\\n1 2\\n\", \"6 9\\n1 2\\n1 4\\n1 5\\n2 3\\n2 5\\n2 6\\n3 5\\n4 6\\n5 6\\n\", \"1 0\\n\", \"15 10\\n2 3\\n5 4\\n...
Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph. It is an undirected weighted graph on n vertices. It is a complete graph: each pair of vertices is conne...
0
{"tests": "{\"inputs\": [\"6 5\\n3 4 U\\n6 1 L\\n2 5 L\\n1 6 U\\n4 3 U\\n\", \"10 6\\n2 9 U\\n10 1 U\\n1 10 U\\n8 3 L\\n10 1 L\\n6 5 U\\n\", \"1 2\\n1 1 L\\n1 1 U\\n\", \"1000000000 1\\n117117117 882882884 U\\n\", \"10 10\\n5 6 U\\n4 7 U\\n8 3 L\\n8 3 L\\n1 10 U\\n9 2 U\\n10 1 L\\n10 1 L\\n8 3 U\\n8 3 U\\n\", \"15 7\\n...
Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom. A bar of chocolate can be presented as an n × n table, where each cell represents one piece of chocolate. The columns of the table are numbered from 1 to n from left to right and the rows are ...
0
{"tests": "{\"inputs\": [\"2\\n1 2 3 4 7 6 7 8\\n5 6 4 8 3 2 3 4\\n0\", \"2\\n1 2 3 4 7 6 14 8\\n5 6 4 8 3 2 3 4\\n0\", \"2\\n1 3 3 4 7 6 14 8\\n5 6 4 8 3 2 3 4\\n0\", \"2\\n1 3 3 4 7 6 14 8\\n5 11 4 8 3 2 3 4\\n0\", \"2\\n1 3 3 7 7 6 14 8\\n5 11 4 8 3 2 3 4\\n0\", \"2\\n1 3 3 7 7 6 14 8\\n5 11 4 5 3 2 3 4\\n0\", \"2\\...
An extension of a complex number is called a quaternion. It is a convenient number that can be used to control the arm of a robot because it is convenient for expressing the rotation of an object. Quaternions are $ using four real numbers $ x $, $ y $, $ z $, $ w $ and special numbers (extended imaginary numbers) $ i $...
0.75
{"tests": "{\"inputs\": [\"26\\nabcdefghijklmnopqrstuvwxyzfgvnsltvvohywvqhuhtydghtthgdythuhqvwyhovvtlsnvgfzyxwvutsrqponmlkjihgfedcba\\n\", \"26\\n?b????g????l?????rs???????s?f?ceiww??ok????u??qwm???q?fu??wkkoh??wie??f???yx?vuts?q??nm?????g??dc??\\n\", \"2\\nababaaaababaaaababbaaabaabaaaabbbabaababababaaaaaaaaaaaabababa...
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first k Latin letters and not contain...
0
{"tests": "{\"inputs\": [\"31415 9265 4472\", \"2 30 23\", \"60899 9265 4472\", \"2 30 9\", \"60899 6796 4472\", \"2 30 14\", \"60899 6796 8504\", \"2 22 14\", \"118261 6796 8504\", \"2 22 26\", \"2 44 26\", \"2 60 26\", \"118261 3351 8683\", \"2 7 26\", \"194739 3351 8683\", \"2 1 26\", \"2 2 26\", \"2 4 26\", \"38818...
There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet. He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square: * Let M and m be the m...
0
{"tests": "{\"inputs\": [\"? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? - ?...
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds. Input The only line of the input contains a re...
0
{"tests": "{\"inputs\": [\"5 5 2\\n1 1 1 1 1\\n1 1 1 1 1\\n1 1 0 1 1\\n1 1 1 1 1\\n1 1 1 1 1\\n\", \"3 4 1\\n1 0 0 0\\n0 1 1 1\\n1 1 1 0\\n\", \"3 4 1\\n1 0 0 1\\n0 1 1 0\\n1 0 0 1\\n\", \"8 1 4\\n0\\n0\\n0\\n1\\n0\\n1\\n1\\n0\\n\", \"3 10 7\\n0 1 0 0 1 0 1 0 0 0\\n0 0 1 1 0 0 0 1 0 1\\n1 0 1 1 1 0 1 1 0 0\\n\", \"4 9 ...
Sereja has an n × m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a co...
0
{"tests": "{\"inputs\": [\"100\\n79 79 79 97 97 97 64 64 64 2 2 2 38 38 38 65 65 65 10 10 10 25 25 25 53 53 53 73 73 73 11 11 11 29 29 29 93 93 93 73 73 73 89 89 89 72 72 72 49 49 49 78 78 78 92 92 92 90 90 90 95 95 95 92 92 92 12 12 12 65 65 65 81 81 81 5 5 5 21 21 21 94 94 94 51 51 51 44 44 44 55 55 55 47 47 47 24 24...
You are given an array a consisting of n integers. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, ..., a_r] (1 ≤ l ≤ r ≤ n). A subarray is considered good if every integer that occurs in this subarray occurs there exactly thrice. For example, the array [1, 2, 2, 2, 1, 1, 2, 2, 2] has three good subarrays...
0
{"tests": "{\"inputs\": [\"9\\n1500\\n1212\\n1500\\n1221\\n1500\\n122\\n1500\\n12121\\n1500\\n22\\n1500\\n1111112111111112\\n1500\\n1111111111221111111\\n1500\\n111111122\\n1500\\n11111121111121111111\\n\", \"1\\n1000000\\n22\\n\", \"1\\n941759\\n1223231111\\n\", \"1\\n1000000\\n2211\\n\", \"1\\n1000000\\n221\\n\", \"1...
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i. There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning: * If ℓ = 0, then the cursor...
0
{"tests": "{\"inputs\": [[[\"abc\", \"aaa\", \"aba\", \"bab\"], \"bbb\"], [[\"aacccc\", \"bbcccc\"], \"abdddd\"], [[\"a\", \"b\", \"c\", \"d\", \"e\"], \"c\"], [[\"aa\", \"ab\", \"ba\"], \"bb\"], [[\"a\", \"b\", \"c\", \"d\", \"e\"], \"f\"], [[\"aaa\", \"aaa\"], \"aaa\"]], \"outputs\": [[2], [0], [4], [1], [0], [1]]}",...
# Task Define crossover operation over two equal-length strings A and B as follows: the result of that operation is a string of the same length as the input strings result[i] is chosen at random between A[i] and B[i]. Given array of strings `arr` and a string result, find for how many pairs of strings from `arr`...
0
{"tests": "{\"inputs\": [\"6 5\\n1 2\\n2 3\\n3 4\\n4 5\\n4 6\", \"5 5\\n1 2\\n2 3\\n3 1\\n5 3\\n5 1\", \"6 5\\n1 2\\n2 2\\n3 4\\n4 5\\n5 6\", \"5 5\\n1 2\\n2 3\\n3 2\\n5 4\\n5 1\", \"6 5\\n1 2\\n2 3\\n3 4\\n4 5\\n3 6\", \"12 5\\n1 2\\n2 3\\n3 3\\n0 5\\n4 6\", \"9 5\\n1 2\\n2 3\\n3 3\\n0 5\\n4 6\", \"15 5\\n1 2\\n2 3\\n...
Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly thr...
0
{"tests": "{\"inputs\": [\"3 3\\n9 3 8\\n6\\n6\\n5\", \"3 3\\n9 3 10\\n6\\n6\\n5\", \"3 3\\n9 3 8\\n4\\n6\\n3\", \"3 3\\n9 3 8\\n6\\n6\\n2\", \"3 2\\n1 3 8\\n4\\n6\\n3\", \"3 3\\n9 2 8\\n4\\n6\\n5\", \"3 3\\n12 3 8\\n6\\n6\\n5\", \"3 3\\n9 3 8\\n4\\n6\\n1\", \"3 3\\n9 3 8\\n12\\n6\\n2\", \"3 2\\n1 3 11\\n4\\n6\\n3\", \...
Give you N cards. Only one natural number is written on each card. However, the same number is never written. From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the number on the card you have by the number I said. For example, suppose you...
0
{"tests": "{\"inputs\": [\"C0DEFESTIVAL2O61\", \"EDOC6102LAVITSEF\", \"C0DEFERTIVAL2O61\", \"C0DEGERTIVAL2O61\", \"CTDEGER0IVAL2O61\", \"CT/EGERDIVAL2O61\", \"CT0EGERDIVAK2O61\", \"1DO2LAVI6REGE0TC\", \"VT0EGER6ICAL2OD0\", \"VV1EFFR7ICAK2OD0\", \"VW1EFFR7ICAK3OD0\", \"107DFFRV3CALWODI\", \"D6OV>JT1DJEC20DQ\", \"16O2LAV...
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a ce...
0.875
{"tests": "{\"inputs\": [\"1\\n4\\n\", \"1\\n2\\n\", \"1\\n7\\n\", \"1\\n5\\n\", \"1\\n6\\n\", \"1\\n9\\n\", \"1\\n11\\n\", \"1\\n12\\n\", \"1\\n13\\n\", \"1\\n18\\n\", \"1\\n24\\n\", \"1\\n23\\n\", \"1\\n31\\n\", \"1\\n27\\n\", \"1\\n39\\n\", \"1\\n54\\n\", \"1\\n50\\n\", \"1\\n44\\n\", \"1\\n108\\n\", \"1\\n14\\n\", ...
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of pe...
0
{"tests": "{\"inputs\": [\"6 1\\nBWBBWW\\n\", \"7 3\\nWBWBWBW\\n\", \"6 4\\nBWBWBW\\n\", \"4 5\\nBWBB\\n\", \"16 7\\nWBBWBWWBBWBWWBWW\\n\", \"16 19\\nBWWWBBBWWBWBBBWB\\n\", \"10 1000000000\\nBBWWBBWWBB\\n\", \"12 1000000000\\nBBWWBBWWBBWW\\n\", \"3 1000000000\\nWWB\\n\", \"3 1\\nBWB\\n\", \"16 1000000000\\nBWBWBWBWBWBW...
There are $n$ chips arranged in a circle, numbered from $1$ to $n$. Initially each chip has black or white color. Then $k$ iterations occur. During each iteration the chips change their colors according to the following rules. For each chip $i$, three chips are considered: chip $i$ itself and two its neighbours. If t...
0.75
{"tests": "{\"inputs\": [\"1\\n6 9 0 0\\n4\\n3 2 0 4\\n1 3 0 0\\n4 4 2 1\\n4 2 0 0\\n0\", \"1\\n6 9 0 0\\n4\\n3 2 0 4\\n1 3 0 0\\n4 4 2 1\\n4 1 0 0\\n0\", \"1\\n6 9 0 0\\n4\\n3 1 0 4\\n1 3 0 0\\n5 4 2 1\\n4 1 0 0\\n0\", \"1\\n6 9 0 0\\n4\\n3 2 0 4\\n1 3 0 0\\n4 8 2 1\\n4 2 0 0\\n0\", \"1\\n6 9 0 0\\n4\\n3 3 0 4\\n1 3 0...
problem Mobiles are widely known as moving works of art. The IOI Japan Committee has decided to create mobiles to publicize JOI. JOI public relations mobiles are sticks, strings, and weights. It is constructed as follows using the three types of elements of. * One end of the bar is painted blue and the other end is p...
0
{"tests": "{\"inputs\": [\"nolon\\n\", \"otto\\n\", \"qqqq\\n\", \"kinnikkinnik\\n\", \"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in t...
0.625
{"tests": "{\"inputs\": [\"4\\ns\\nf\\nf\\ns\\n\", \"4\\nf\\ns\\nf\\ns\\n\", \"156\\nf\\ns\\nf\\ns\\nf\\ns\\ns\\ns\\ns\\nf\\ns\\ns\\nf\\nf\\ns\\nf\\nf\\nf\\nf\\ns\\ns\\ns\\nf\\ns\\ns\\nf\\nf\\nf\\nf\\nf\\nf\\ns\\ns\\ns\\ns\\nf\\ns\\nf\\ns\\nf\\ns\\nf\\nf\\nf\\nf\\ns\\ns\\nf\\nf\\ns\\ns\\ns\\ns\\nf\\ns\\nf\\ns\\nf\\ns\\...
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An ex...
0
{"tests": "{\"inputs\": [[[1, 3, 1]], [[4, 7, 5, 7]], [[4, 8, 1, 4]], [[5, 7, 9, 5, 7]], [[6, 7, 8, 7, 6, 6]], [[5, 6, 9, 9, 7, 6, 4]], [[1, 9, 1, 3, 7, 4, 6, 6, 7]], [[3, 6, 5, 5, 9, 8, 7, 6, 3, 5, 9]]], \"outputs\": [[13], [457], [148], [579], [678], [45679], [134679], [356789]]}", "source": "taco"}
# Task **_Given_** a **_list of digits_**, *return the **_smallest number_** that could be formed from these digits, using the digits only once (ignore duplicates).* ___ # Notes: * Only **_positive integers_** *will be passed to the function (> 0 ), no negatives or zeros.* ___ # Input >> Output Examples ``` minVa...
0.5