problem_id stringlengths 32 32 | name stringclasses 1
value | problem stringlengths 200 14k | solutions stringlengths 12 1.12M | test_cases stringlengths 37 74M | difficulty stringclasses 3
values | language stringclasses 1
value | source stringclasses 7
values | num_solutions int64 12 1.12M | starter_code stringlengths 0 956 |
|---|---|---|---|---|---|---|---|---|---|
3db3e02646b6175c6c10d36e55407f19 | UNKNOWN | Write a function that counts how many different ways you can make change for an amount of money, given an array of coin denominations. For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:
```
1+1+1+1, 1+1+2, 2+2.
```
The order of coins does not matter:
```
1+1+2 == 2+1+1
```
... | ["def count_change(money, coins):\n if money<0:\n return 0\n if money == 0:\n return 1\n if money>0 and not coins:\n return 0\n return count_change(money-coins[-1],coins) + count_change(money,coins[:-1])", "\n\ndef count_change(money, coins):\n\n ways = [1] + [0] * (money + 1)\n\n ... | {"fn_name": "count_change", "inputs": [[4, [1, 2]], [10, [5, 2, 3]], [11, [5, 7]], [98, [3, 14, 8]], [199, [3, 5, 9, 15]], [300, [5, 10, 20, 50, 100, 200, 500]], [301, [5, 10, 20, 50, 100, 200, 500]], [419, [2, 5, 10, 20, 50]]], "outputs": [[3], [4], [0], [19], [760], [1022], [0], [18515]]} | INTERVIEW | PYTHON3 | CODEWARS | 2,056 |
def count_change(money, coins):
|
c896bd88288e78d6571e1f26428629e8 | UNKNOWN | The number ```89``` is the first positive integer that has a particular, curious property:
The square of ```89``` is ```7921```; ```89² = 7921```
The reverse of ```7921``` is ```1297```, and ```1297``` is a prime number.
The cube of ```89``` is ```704969```; ```89³ = 704969```
The reverse of ```704969``` is ```9694... | ["sq_cub_rev_prime = (None, 89, 271, 325, 328, 890, 1025, 1055, 1081, 1129, 1169, 1241, 2657, 2710, 3112, 3121, 3149, 3244, 3250, 3263, 3280, 3335, 3346, 3403, 4193, 4222, 4231, 4289, 4291, 5531, 5584, 5653, 5678, 5716, 5791, 5795, 5836, 5837, 8882, 8900, 8926, 8942, 9664, 9794, 9875, 9962, 10178, 10250, 10393, 10429, ... | {"fn_name": "sq_cub_rev_prime", "inputs": [[1], [2], [3], [4]], "outputs": [[89], [271], [325], [328]]} | INTERVIEW | PYTHON3 | CODEWARS | 11,209 |
def sq_cub_rev_prime(n):
|
9c942814c41f0f9340f8f2649c716e64 | UNKNOWN | Consider the following array:
```
[1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 12345678910, 1234567891011...]
```
If we join these blocks of numbers, we come up with an infinite sequence which starts with `112123123412345123456...`. The list is infinite.
You will be given an number (`n`) and your ... | ["def solve(n):\n def length(n):\n s = 0\n for i in range(20):\n o = 10 ** i - 1\n if o > n: break\n s += (n - o) * (n - o + 1) // 2\n return s\n\n def binary_search(k):\n n = 0\n for p in range(63, -1, -1):\n if length(n + 2 ** p) < k... | {"fn_name": "solve", "inputs": [[1], [2], [3], [100], [2100], [31000], [55], [123456], [123456789], [999999999999999999], [1000000000000000000], [999999999999999993]], "outputs": [[1], [1], [2], [1], [2], [2], [1], [6], [3], [4], [1], [7]]} | INTERVIEW | PYTHON3 | CODEWARS | 14,851 |
def solve(n):
|
649cfef3b037f90088eb3fdacce6d2aa | UNKNOWN | # Task
Sorting is one of the most basic computational devices used in Computer Science.
Given a sequence (length ≤ 1000) of 3 different key values (7, 8, 9), your task is to find the minimum number of exchange operations necessary to make the sequence sorted.
One operation is the switching of 2 key values in th... | ["from collections import Counter\n\ndef exchange_sort(sequence):\n \"\"\"Greedy algorithm based on permutation cycle decomposition:\n 1. Search for transposition placing TWO elements correctly.\n 2. Search iteratively for transposition placing ONE elements correctly.\"\"\"\n swaps, cnt = 0, Counter()\n ... | {"fn_name": "exchange_sort", "inputs": [[[7, 7, 8, 8, 9, 9]], [[9, 7, 8, 8, 9, 7]], [[8, 8, 7, 9, 9, 9, 8, 9, 7]], [[9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7]], [[9, 9, 9, 7, 7, 8, 9, 7, 8, 9, 7, 9]], [[9, 9, 7, 7, 8, 8]], [[9, 7, 9]], [[8, 7, 8]], [[7, 8, 7, 8]], [[8, 8, 7, 8]], [[8, 8, 7, 7, 8]]], "outputs": [[0],... | INTERVIEW | PYTHON3 | CODEWARS | 5,680 |
def exchange_sort(sequence):
|
a2eeff924cbee5c35d8ee211778634c2 | UNKNOWN | Story:
In the realm of numbers, the apocalypse has arrived. Hordes of zombie numbers have infiltrated and are ready to turn everything into undead. The properties of zombies are truly apocalyptic: they reproduce themselves unlimitedly and freely interact with each other. Anyone who equals them is doomed. Out of an infi... | ["from functools import reduce\nfrom math import gcd\n\ndef survivor(a):\n \"\"\"Round Robin by Bocker & Liptak\"\"\"\n def __residue_table(a):\n n = [0] + [None] * (a[0] - 1)\n for i in range(1, len(a)):\n d = gcd(a[0], a[i])\n for r in range(d):\n try:\n ... | {"fn_name": "survivor", "inputs": [[[7, 11]], [[1, 7, 15]], [[2, 10]], [[687, 829, 998]], [[]], [[1]]], "outputs": [[59], [0], [-1], [45664], [-1], [0]]} | INTERVIEW | PYTHON3 | CODEWARS | 10,829 |
def survivor(zombies):
|
26ba4bda2f21f726d05543976bd7c891 | UNKNOWN | ## Snail Sort
Given an `n x n` array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.
```
array = [[1,2,3],
[4,5,6],
[7,8,9]]
snail(array) #=> [1,2,3,6,9,8,7,4,5]
```
For better understanding, please follow the numbers of the next array consecu... | ["def snail(array):\n ret = []\n if array and array[0]:\n size = len(array)\n for n in range((size + 1) // 2):\n for x in range(n, size - n):\n ret.append(array[n][x])\n for y in range(1 + n, size - n):\n ret.append(array[y][-1 - n])\n f... | {"fn_name": "snail", "inputs": [[[[]]], [[[1]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[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]]], [[[1, 2, 3, 4, 5, 6], [20, 21, 22, 23, 24, 7], [19, 32, 33, 34, 25, 8], [18, 31, 36, 35, 26, 9], [17, 30, 29, 28, 27, 10], [16, 1... | INTERVIEW | PYTHON3 | CODEWARS | 5,329 |
def snail(array):
|
39c70c86dfcf7f1a43409c91c8959800 | UNKNOWN | Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000)
return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both)
```
Example:
countOnes 4 7 should return 8, because:
4(dec) = 100(bin), which adds 1 to the result.
5(dec) = 101(bin), wh... | ["import math\n\ndef count(n):\n if n is 0: return 0\n x = int(math.log(n, 2))\n return x * 2 ** (x - 1) + n - 2 ** x + 1 + count(n - 2 ** x)\n\ndef countOnes(left, right):\n return count(right) - count(left - 1)", "def countOnes(left, right):\n \"\"\"\n Each number has a particular number of digits i... | {"fn_name": "countOnes", "inputs": [[1, 1000000000]], "outputs": [[14846928141]]} | INTERVIEW | PYTHON3 | CODEWARS | 8,585 |
def countOnes(left, right):
|
48a9e99ce68cf3e810ed352558f49d28 | UNKNOWN | Let's define `increasing` numbers as the numbers whose digits, read from left to right, are never less than the previous ones: 234559 is an example of increasing number.
Conversely, `decreasing` numbers have all the digits read from left to right so that no digits is bigger than the previous one: 97732 is an example o... | ["from math import factorial as fac\n\ndef xCy(x, y):\n return fac(x) // fac(y) // fac(x - y)\n \ndef total_inc_dec(x):\n return 1+sum([xCy(8+i,i) + xCy(9+i,i) - 10 for i in range(1,x+1)])\n", "inc = {}\ndec = {}\n\n\ndef total_inc(n, a):\n if n not in inc:\n inc[n] = {}\n if a not in inc[n]:\n ... | {"fn_name": "total_inc_dec", "inputs": [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]], "outputs": [[1], [10], [100], [475], [1675], [4954], [12952], [277033], [40059819], [87959698326]]} | INTERVIEW | PYTHON3 | CODEWARS | 7,649 |
def total_inc_dec(x):
|
1a61994a8af6f70a28d863c35d117dbd | UNKNOWN | # Task
You are given a string `s`. Every letter in `s` appears once.
Consider all strings formed by rearranging the letters in `s`. After ordering these strings in dictionary order, return the middle term. (If the sequence has a even length `n`, define its middle term to be the `(n/2)`th term.)
# Example
For `s... | ["def middle_permutation(string):\n s = sorted(string)\n if len(s) % 2 ==0: \n return s.pop(len(s)//2-1) +''.join(s[::-1])\n else:\n return s.pop(len(s)//2) + middle_permutation(s)", "def middle_permutation(s):\n s = ''.join(sorted(s))\n return s[len(s)//2-1:(len(s)+1)//2][::-1] + s[... | {"fn_name": "middle_permutation", "inputs": [["abc"], ["abcd"], ["abcdx"], ["abcdxg"], ["abcdxgz"]], "outputs": [["bac"], ["bdca"], ["cbxda"], ["cxgdba"], ["dczxgba"]]} | INTERVIEW | PYTHON3 | CODEWARS | 2,830 |
def middle_permutation(string):
|
48d0cbc5a3f24475e54f4172c8a6df0a | UNKNOWN | A product-sum number is a natural number N which can be expressed as both the product and the sum of the same set of numbers.
N = a1 × a2 × ... × ak = a1 + a2 + ... + ak
For example, 6 = 1 × 2 × 3 = 1 + 2 + 3.
For a given set of size, k, we shall call the smallest N with this property a minimal product-sum number. T... | ["def productsum(n):\n pass # Your code here\n \ndef productsum(kmax):\n def prodsum2(p, s, c, start):\n k = p - s + c # product - sum + number of factors\n if k < kmax:\n if p < n[k]: n[k] = p\n for i in range(start, kmax//p*2 + 1):\n prodsum2(p*i, s+i, c... | {"fn_name": "productsum", "inputs": [[3], [6], [12], [2]], "outputs": [[10], [30], [61], [4]]} | INTERVIEW | PYTHON3 | CODEWARS | 190,465 |
def productsum(n):
|
ecff42daacb38df47f2797bf1090218e | UNKNOWN | # Longest Palindromic Substring (Linear)
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,
'madam' or 'racecar'. Even the letter 'x' is considered a palindrome.
For this Kata, you are given a string ```s```. Write a function that returns the longest _contiguous_ palindromic s... | ["'''\n Write a function that returns the longest contiguous palindromic substring in s. \n In the event that there are multiple longest palindromic substrings, return the \n first to occur.\n'''\n\ndef longest_palindrome(s, sep=\" \"):\n # Interpolate some inert character between input characters\n # so... | {"fn_name": "longest_palindrome", "inputs": [["babad"], ["madam"], ["dde"], ["ababbab"], ["abababa"], ["banana"], ["abba"], ["cbbd"], ["zz"], ["dddd"], [""], ["abcdefghijklmnopqrstuvwxyz"], ["ttaaftffftfaafatf"], ["bbaaacc"], ["m"]], "outputs": [["bab"], ["madam"], ["dd"], ["babbab"], ["abababa"], ["anana"], ["abba"], ... | INTERVIEW | PYTHON3 | CODEWARS | 9,972 |
def longest_palindrome(s):
|
88f19ff94a26275950cd9cc8138a3a50 | UNKNOWN | We have three numbers: ```123489, 5, and 67```.
With these numbers we form the list from their digits in this order ```[1, 5, 6, 2, 7, 3, 4, 8, 9]```. It shouldn't take you long to figure out what to do to achieve this ordering.
Furthermore, we want to put a limit to the number of terms of the above list.
Instead of... | ["import math\n\ndef gta(limit, *args):\n return sum_up(limit, make_pattern(limit, *args)) \n\ndef binomial_coeff(n, k):\n \"\"\"N choose K\"\"\"\n return math.factorial(n) / math.factorial(n-k)\n\ndef sum_up(limit, items):\n \"\"\"\n Basic Idea: \n \n The number of cominations is simply N choose K... | {"fn_name": "gta", "inputs": [[7, 123489, 5, 67], [8, 12348, 47, 3639]], "outputs": [[328804], [3836040]]} | INTERVIEW | PYTHON3 | CODEWARS | 5,262 |
def gta(limit, *args):
|
9e99b89df9d1ab58ce23a56a3332f9dd | UNKNOWN | Given two strings s1 and s2, we want to visualize how different the two strings are.
We will only take into account the *lowercase* letters (a to z).
First let us count the frequency of each *lowercase* letters in s1 and s2.
`s1 = "A aaaa bb c"`
`s2 = "& aaa bbb c d"`
`s1 has 4 'a', 2 'b', 1 'c'`
`s2 has 3 'a', 3 '... | ["\ndef mix(s1, s2):\n hist = {}\n for ch in \"abcdefghijklmnopqrstuvwxyz\":\n val1, val2 = s1.count(ch), s2.count(ch)\n if max(val1, val2) > 1:\n which = \"1\" if val1 > val2 else \"2\" if val2 > val1 else \"=\"\n hist[ch] = (-max(val1, val2), which + \":\" + ch * max(val1, va... | {"fn_name": "mix", "inputs": [["Are they here", "yes, they are here"], ["looping is fun but dangerous", "less dangerous than coding"], [" In many languages", " there's a pair of functions"], ["Lords of the Fallen", "gamekult"], ["codewars", "codewars"], ["A generation must confront the looming ", "codewarrs"]], "output... | INTERVIEW | PYTHON3 | CODEWARS | 7,765 |
def mix(s1, s2):
|
b7c11934684a37ccd3dcf9fc8930b32b | UNKNOWN | # The Kata
Your task is to transform an input nested list into an hypercube list, which is a special kind of nested list where each level must have the very same size,
This Kata is an exercise on recursion and algorithms. You will need to visualize many aspects of this question to be able to solve it efficiently, as su... | ["from itertools import zip_longest\n\ndef normalize(lst, growing=0):\n \n def seeker(lst, d=1):\n yield len(lst), d\n for elt in lst:\n if isinstance(elt,list):\n yield from seeker(elt, d+1)\n \n def grower(lst, d=1):\n return [ grower(o if isinstance(o,list) ... | {"fn_name": "normalize", "inputs": [[[]]], "outputs": [[[]]]} | INTERVIEW | PYTHON3 | CODEWARS | 11,352 |
def normalize(nested_list, growing_value=0):
|
508caff58798082e8824ed1acc662a7d | UNKNOWN | ## Task
Given a positive integer, `n`, return the number of possible ways such that `k` positive integers multiply to `n`. Order matters.
**Examples**
```
n = 24
k = 2
(1, 24), (2, 12), (3, 8), (4, 6), (6, 4), (8, 3), (12, 2), (24, 1) -> 8
n = 100
k = 1
100 -> 1
n = 20
k = 3
(1, 1, 20), (1, 2, 10), (1, 4, 5), (1, 5... | ["from scipy.special import comb\n\ndef multiply(n, k):\n r, d = 1, 2\n while d * d <= n:\n i = 0\n while n % d == 0:\n i += 1\n n //= d\n r *= comb(i + k - 1, k - 1, exact=True)\n d += 1\n if n > 1: \n r *= k\n return r", "from scipy.special import c... | {"fn_name": "multiply", "inputs": [[24, 2], [100, 1], [20, 3], [1, 2], [1000000, 3], [10, 2], [36, 4]], "outputs": [[8], [1], [18], [1], [784], [4], [100]]} | INTERVIEW | PYTHON3 | CODEWARS | 10,018 |
def multiply(n, k):
|
cad5fb2bbb177dc7aad3b5c8cd666961 | UNKNOWN | You are given 2 numbers is `n` and `k`. You need to find the number of integers between 1 and n (inclusive) that contains exactly `k` non-zero digit.
Example1
`
almost_everywhere_zero(100, 1) return 19`
by following condition we have 19 numbers that have k = 1 digits( not count zero )
` [1,2,3,4,5,6,7,8,9,10,20,30... | ["from scipy.special import comb\n\ndef almost_everywhere_zero(n, k):\n if k == 0: return 1\n first, *rest = str(n)\n l = len(rest)\n return 9**k*comb(l, k, exact=True) +\\\n (int(first)-1)*9**(k-1)*comb(l, k-1, exact=True) +\\\n almost_everywhere_zero(int(\"\".join(rest) or 0), k-1)", "... | {"fn_name": "almost_everywhere_zero", "inputs": [[100, 1], [11, 2], [20, 2], [101, 2], [10001, 2], [10001000, 2], [500309160, 2], [10000000000000000000000, 3], [10000000000000000000000, 21], [1203, 4]], "outputs": [[19], [1], [9], [82], [487], [1729], [2604], [1122660], [2407217760893271902598], [81]]} | INTERVIEW | PYTHON3 | CODEWARS | 4,388 |
def almost_everywhere_zero(n, k):
|
7a58533e65c9171bd46399ba5093d15f | UNKNOWN | The task is simply stated. Given an integer n (3 < n < 10^(9)), find the length of the smallest list of [*perfect squares*](https://en.wikipedia.org/wiki/Square_number) which add up to n. Come up with the best algorithm you can; you'll need it!
Examples:
sum_of_squares(17) = 2 17 = 16 + 1 (4 and 1 are perfect square... | ["def one_square(n):\n return round(n ** .5) ** 2 == n\n\ndef two_squares(n):\n while n % 2 == 0: n //= 2\n p = 3\n while p * p <= n:\n while n % (p * p) == 0:\n n //= p * p\n while n % p == 0:\n if p % 4 == 3: return False\n n //= p\n p += 2\n return... | {"fn_name": "sum_of_squares", "inputs": [[15], [16], [17], [18], [19], [2017], [1008], [3456], [4000], [12321], [661915703], [999887641], [999950886], [999951173], [999998999]], "outputs": [[4], [1], [2], [2], [3], [2], [4], [3], [2], [1], [4], [1], [3], [2], [4]]} | INTERVIEW | PYTHON3 | CODEWARS | 4,410 |
def sum_of_squares(n):
|
fb98656a2784ce7df7006ef95ca287db | UNKNOWN | This is a very simply formulated task. Let's call an integer number `N` 'green' if `N²` ends with all of the digits of `N`. Some examples:
`5` is green, because `5² = 25` and `25` ends with `5`.
`11` is not green, because `11² = 121` and `121` does not end with `11`.
`376` is green, because `376² = 141376` and `1413... | ["out = [1, 5, 6]\n\ndef green(n):\n \n f = 5\n s = 6\n q = 1\n\n while n >= len(out):\n q = 10 * q\n f = f**2 % q\n s = (1 - (s - 1)**2) % q\n out.extend(sorted(j for j in [f, s] if j not in out))\n return out[n-1]", "def green(n):\n vec = [1, 5, 6]\n m1 = 5\n m2 = ... | {"fn_name": "green", "inputs": [[1], [2], [3], [4], [12], [13], [100], [110]], "outputs": [[1], [5], [6], [25], [2890625], [7109376], [6188999442576576769103890995893380022607743740081787109376], [9580863811000557423423230896109004106619977392256259918212890625]]} | INTERVIEW | PYTHON3 | CODEWARS | 34,467 |
def green(n):
|
bc34a7bde2eafbd48f0feee7c9f147fa | UNKNOWN | Create a function that takes a positive integer and returns the next bigger number that can be formed by rearranging its digits. For example:
```
12 ==> 21
513 ==> 531
2017 ==> 2071
```
If the digits can't be rearranged to form a bigger number, return `-1` (or `nil` in Swift):
```
9 ==> -1
111 ==> -1
531 ==> -1
``` | ["import itertools\ndef next_bigger(n):\n s = list(str(n))\n for i in range(len(s)-2,-1,-1):\n if s[i] < s[i+1]:\n t = s[i:]\n m = min([x for x in t if x>t[0]])\n t.remove(m)\n t.sort()\n s[i:] = [m] + t\n return int(\"\".join(s))\n retur... | {"fn_name": "next_bigger", "inputs": [[12], [513], [2017], [414], [144], [123456789], [1234567890], [9876543210], [9999999999], [59884848459853]], "outputs": [[21], [531], [2071], [441], [414], [123456798], [1234567908], [-1], [-1], [59884848483559]]} | INTERVIEW | PYTHON3 | CODEWARS | 3,391 |
def next_bigger(n):
|
464beff3314438700b2e82f397bab7eb | UNKNOWN | This is the performance version of [this kata](https://www.codewars.com/kata/59afff65f1c8274f270020f5).
---
Imagine two rings with numbers on them. The inner ring spins clockwise and the outer ring spins anti-clockwise. We start with both rings aligned on 0 at the top, and on each move we spin each ring by 1. How man... | ["def spinning_rings(inner_max, outer_max):\n p = inner_max + 1\n q = outer_max + 1\n move = 1\n while (-move) % p != move % q:\n if (-move) % p >= q:\n move = move // p * p + p - q + 1\n elif move % q >= p:\n move = move // q * q + q\n elif (-move) % p > move % q ... | {"fn_name": "spinning_rings", "inputs": [[5, 5], [2, 10], [10, 2], [7, 9], [1, 1], [16777216, 14348907]], "outputs": [[3], [13], [10], [4], [1], [23951671]]} | INTERVIEW | PYTHON3 | CODEWARS | 9,077 |
def spinning_rings(inner_max, outer_max):
|
7ac64a42c6efe245c2e0725ee935f37b | UNKNOWN | We want to generate all the numbers of three digits where:
- the sum of their digits is equal to 10.
- their digits are in increasing order (the numbers may have two or more equal contiguous digits)
The numbers that fulfill the two above constraints are: ```118, 127, 136, 145, 226, 235, 244, 334```
Make a function ... | ["from itertools import combinations_with_replacement\n\ndef find_all(sum_dig, digs):\n combs = combinations_with_replacement(list(range(1, 10)), digs)\n target = [''.join(str (x) for x in list(comb)) for comb in combs if sum(comb) == sum_dig]\n if not target:\n return []\n return [len(target), int(t... | {"fn_name": "find_all", "inputs": [[10, 3], [27, 3], [84, 4], [35, 6]], "outputs": [[[8, 118, 334]], [[1, 999, 999]], [[]], [[123, 116999, 566666]]]} | INTERVIEW | PYTHON3 | CODEWARS | 5,878 |
def find_all(sum_dig, digs):
|
2cb7999d8bdd30bc2ae8f8d06b07adb5 | UNKNOWN | A format for expressing an ordered list of integers is to use a comma separated list of either
* individual integers
* or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. The range includes all integers in the interval including both endpoints. It is not ... | ["def solution(args):\n out = []\n beg = end = args[0]\n \n for n in args[1:] + [\"\"]: \n if n != end + 1:\n if end == beg:\n out.append( str(beg) )\n elif end == beg + 1:\n out.extend( [str(beg), str(end)] )\n else:\n ... | {"fn_name": "solution", "inputs": [[[-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]], [[-3, -2, -1, 2, 10, 15, 16, 18, 19, 20]], [[1, 2, 3, 4, 5]]], "outputs": [["-6,-3-1,3-5,7-11,14,15,17-20"], ["-3--1,2,10,15,16,18-20"], ["1-5"]]} | INTERVIEW | PYTHON3 | CODEWARS | 5,489 |
def solution(args):
|
ce392f42f9dbb3a32ce10cca7ea5d4dc | UNKNOWN | Your task in order to complete this Kata is to write a function which formats a duration, given as a number of seconds, in a human-friendly way.
The function must accept a non-negative integer. If it is zero, it just returns `"now"`. Otherwise, the duration is expressed as a combination of `years`, `days`, `hours`, `... | ["times = [(\"year\", 365 * 24 * 60 * 60), \n (\"day\", 24 * 60 * 60),\n (\"hour\", 60 * 60),\n (\"minute\", 60),\n (\"second\", 1)]\n\ndef format_duration(seconds):\n\n if not seconds:\n return \"now\"\n\n chunks = []\n for name, secs in times:\n qty = seconds // ... | {"fn_name": "format_duration", "inputs": [[0], [1], [62], [120], [3600], [3662], [15731080], [132030240], [205851834], [253374061], [242062374], [101956166], [33243586]], "outputs": [["now"], ["1 second"], ["1 minute and 2 seconds"], ["2 minutes"], ["1 hour"], ["1 hour, 1 minute and 2 seconds"], ["182 days, 1 hour, 44 ... | INTERVIEW | PYTHON3 | CODEWARS | 36,205 |
def format_duration(seconds):
|
2c412e519a83ea58d8ba6d5a343e5228 | UNKNOWN | 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... | ["import re\n\ndef solve_runes(runes):\n for d in sorted(set(\"0123456789\") - set(runes)):\n toTest = runes.replace(\"?\",d)\n if re.search(r'([^\\d]|\\b)0\\d+', toTest): continue\n l,r = toTest.split(\"=\")\n if eval(l) == eval(r): return int(d)\n return -1", "def solve_runes(runes):... | {"fn_name": "solve_runes", "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], [0], [9]... | INTERVIEW | PYTHON3 | CODEWARS | 9,849 |
def solve_runes(runes):
|
bdc680a98580ed68e3c8c6452e371b3a | UNKNOWN | With your birthday coming up soon, your eccentric friend sent you a message to say "happy birthday":
hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu
hhapppyyyy biirtttthdaaay too youuu
happy birrrthdayy to youuu
happpyyyy birrtthdaaay tooooo youu
At first it looks like a song, but upon closer investigati... | ["def count_subsequences(needle, haystack):\n count = [1] + [0] * len(needle)\n for a in haystack:\n count = [1] + [count[i] + count[i-1] * (a == b)\n for i, b in enumerate(needle, 1)]\n return count[-1] % 10 ** 8", "from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef ... | {"fn_name": "count_subsequences", "inputs": [["happy birthday", "appyh appy birth day"], ["happy birthday", "hhaappyy bbiirrtthhddaayy"], ["happy birthday", "happy holidays"], ["happy birthday", "happy birthday"], ["happy", "hhhappy"], ["happy birthday", "hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu"]], "outputs": [[1]... | INTERVIEW | PYTHON3 | CODEWARS | 3,241 |
def count_subsequences(a, b):
|
09d6788456f5aed3aeb93067a058be37 | UNKNOWN | This kata is blatantly copied from inspired by This Kata
Welcome
this is the second in the series of the string iterations kata!
Here we go!
---------------------------------------------------------------------------------
We have a string s
Let's say you start with this: "String"
The first thing you do is reve... | ["def string_func(s, n):\n l, s = [s], list(s)\n while True:\n s[::2], s[1::2] = s[:len(s)//2-1:-1], s[:len(s)//2]\n l.append(''.join(s))\n if l[0] == l[-1]: del l[-1]; break\n return l[n % len(l)]", "# SOLUTION:\n# Actually doing the reversals repeatedly is slow. Through observeration\n# ... | {"fn_name": "string_func", "inputs": [["This is a string exemplification!", 0], ["String for test: incommensurability", 1], ["Ohh Man God Damn", 7], ["Ohh Man God Damnn", 19], ["I like it!", 1234], ["codingisfornerdsyounerd", 10101010], ["this_test_will_hurt_you", 12345678987654321]], "outputs": [["This is a string exe... | INTERVIEW | PYTHON3 | CODEWARS | 8,471 |
def string_func(s, n):
|
e174dbdca0e4806de2f2f095df7e235b | UNKNOWN | When we attended middle school were asked to simplify mathematical expressions like "3x-yx+2xy-x" (or usually bigger), and that was easy-peasy ("2x+xy"). But tell that to your pc and we'll see!
Write a function: `simplify`, that takes a string in input, representing a *multilinear non-constant polynomial in integers ... | ["def simplify(poly):\n # I'm feeling verbose today\n \n # get 3 parts (even if non-existent) of each term: (+/-, coefficient, variables)\n import re\n matches = re.findall(r'([+\\-]?)(\\d*)([a-z]+)', poly)\n \n # get the int equivalent of coefficient (including sign) and the sorted variables (for ... | {"fn_name": "simplify", "inputs": [["dc+dcba"], ["2xy-yx"], ["-a+5ab+3a-c-2a"], ["-abc+3a+2ac"], ["xyz-xz"], ["a+ca-ab"], ["xzy+zby"], ["-y+x"], ["y-x"], ["3a+b+4ac+bc-ab+3a-cb-a-a"], ["+n-5hn+7tjhn-4nh-3n-6hnjt+2jhn+9hn"], ["-8fk+5kv-4yk+7kf-qk+yqv-3vqy+4ky+4kf+yvqkf"]], "outputs": [["cd+abcd"], ["xy"], ["-c+5ab"], ["... | INTERVIEW | PYTHON3 | CODEWARS | 8,152 |
def simplify(poly):
|
25e7e171ac93f85db25220876b6718e1 | UNKNOWN | # RoboScript #3 - Implement the RS2 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... | ["from collections import deque\nimport re\n\nTOKENIZER = re.compile(r'(R+|F+|L+|\\)|\\()(\\d*)')\n\ndef parseCode(code):\n cmds = [[]]\n for cmd,n in TOKENIZER.findall(code):\n s,r = cmd[0], int(n or '1') + len(cmd)-1\n if cmd == '(': cmds.append([])\n elif cmd == ')': lst = cmds.pop() ; c... | {"fn_name": "execute", "inputs": [["LF5(RF3)(RF3R)F7"], ["(L(F5(RF3))(((R(F3R)F7))))"], ["F4L(F4RF4RF4LF4L)2F4RF4RF4"], ["F4L((F4R)2(F4L)2)2(F4R)2F4"], ["F2LF3L(F2)2LF5L(F3)2LF7L((F2)2)2L(F3)3L(F5)2"], ["F2LF3L(F2)2LF5L(F3)2LF7L(F4)2L((F3)1)3L(F5)2"], ["(F5RF5R(F3R)2)3"], ["((F5R)2(F3R)2)3"], ["((F3LF3R)2FRF6L)2"], ["(... | INTERVIEW | PYTHON3 | CODEWARS | 25,700 |
def execute(code):
|
21ee5f27c1c158a76d8de363d602f714 | UNKNOWN | You are given a binary tree:
```python
class Node:
def __init__(self, L, R, n):
self.left = L
self.right = R
self.value = n
```
Your task is to return the list with elements from tree sorted by levels, which means the root element goes first, then root children (from left to right) are sec... | ["from collections import deque\n\n\ndef tree_by_levels(node):\n if not node:\n return []\n res, queue = [], deque([node,])\n while queue:\n n = queue.popleft()\n res.append(n.value)\n if n.left is not None:\n queue.append(n.left)\n if n.right is not None:\n ... | {"fn_name": "tree_by_levels", "inputs": [[null]], "outputs": [[[]]]} | INTERVIEW | PYTHON3 | CODEWARS | 3,246 |
def tree_by_levels(node):
|
c00fd6b5b9e52673ebc2d96ba69af898 | UNKNOWN | In this Kata we focus on finding a sum S(n) which is the total number of divisors taken for all natural numbers less or equal to n. More formally, we investigate the sum of n components denoted by d(1) + d(2) + ... + d(n) in which for any i starting from 1 up to n the value of d(i) tells us how many distinct numbers di... | ["def count_divisors(n):\n \"\"\"Counts the integer points under the parabola xy = n.\n\n Because the region is symmetric about x = y, it is only necessary to sum up\n to that point (at n^{1/2}), and double it. By this method, a square region is\n counted twice, and thus subtracted off the total.\n \"\"\"\n r = i... | {"fn_name": "count_divisors", "inputs": [[5], [10], [20], [59], [105], [785], [1001], [8009], [9999999999999], [9999999999998], [9999999999995], [9999999949950]], "outputs": [[10], [27], [66], [249], [510], [5364], [7077], [73241], [300880375389561], [300880375389537], [300880375389493], [300880373832097]]} | INTERVIEW | PYTHON3 | CODEWARS | 1,832 |
def count_divisors(n):
|
a042ebfc33a1e3dd25410d780b65951e | UNKNOWN | # Task
An `amazon` (also known as a queen+knight compound) is an imaginary chess piece that can move like a `queen` or a `knight` (or, equivalently, like a `rook`, `bishop`, or `knight`). The diagram below shows all squares which the amazon attacks from e4 (circles represent knight-like moves while crosses correspond ... | ["from itertools import count\n\nALL_MOVES = [(1,1), (0,1), ( 1,0), (-1,0), (0,-1), (-1,1), ( 1,-1), (-1,-1)] # Natural directions of moves for king or queen (one step)\nAMA_MOVES = [(1,2), (2,1), (-1,2), (2,-1), (1,-2), (-2,1), (-1,-2), (-2,-1)] # Knight moves for amazon queen\n\n\ndef amazon_check_mate(... | {"fn_name": "amazon_check_mate", "inputs": [["a1", "g5"], ["a3", "e4"], ["f3", "f2"], ["b7", "a8"], ["f7", "d3"], ["g2", "c3"], ["f3", "c1"], ["d4", "h8"], ["h6", "a7"], ["a6", "g3"], ["e1", "b4"], ["f4", "c4"], ["c3", "e8"], ["b5", "e5"], ["c8", "g8"], ["a6", "b5"], ["b3", "e2"], ["b7", "c3"], ["b5", "b3"], ["a4", "a6... | INTERVIEW | PYTHON3 | CODEWARS | 46,915 |
def amazon_check_mate(king, amazon):
|
83947d02ee847950dc3d50e9644877f5 | UNKNOWN | Complete the function/method (depending on the language) to return `true`/`True` when its argument is an array that has the same nesting structures and same corresponding length of nested arrays as the first array.
For example:
```python
# should return True
same_structure_as([ 1, 1, 1 ], [ 2, 2, 2 ] )
same_structure... | ["def same_structure_as(original,other):\n if isinstance(original, list) and isinstance(other, list) and len(original) == len(other):\n for o1, o2 in zip(original, other):\n if not same_structure_as(o1, o2): return False\n else: return True\n else: return not isinstance(original, list) an... | {"fn_name": "same_structure_as", "inputs": [[[1, [1, 1]], [[2, 2], 2]], [[1, [1, 1]], [2, [2]]], [[[[], []]], [[[], []]]], [[[[], []]], [[1, 1]]], [[1, [[[1]]]], [2, [[[2]]]]], [[], 1], [[], {}], [[1, "[", "]"], ["[", "]", 1]]], "outputs": [[false], [false], [true], [false], [true], [false], [false], [true]]} | INTERVIEW | PYTHON3 | CODEWARS | 2,544 |
def same_structure_as(a, b):
|
bb5bebabe1da5893453903a69498fe15 | UNKNOWN | ## Description
Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required:
```if X[i] > X[j] then X[i] = X[i] - X[j]```
When no more transformations are possible, return its sum ("smallest possible sum").
For instance, the successiv... | ["from fractions import gcd\nfrom functools import reduce\n\ndef solution(a):\n return reduce(gcd, a) * len(a)", "def solution(a):\n a_len = len(a)\n a = set(a)\n while len(a) != 1:\n b = max(a)\n a.remove(b)\n a.add(b-max(a))\n return(max(a) * a_len)", "from fractions import gcd\nfr... | {"fn_name": "solution", "inputs": [[[6, 9, 21]], [[9]], [[30, 12]], [[11, 22]], [[1, 21, 55]], [[4, 16, 24]], [[3, 13, 23, 7, 83]], [[60, 12, 96, 48, 60, 24, 72, 36, 72, 72, 48]], [[71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71]]], "outputs": [[9], [9], [12], [22], [3], [12], [5], [132], [923]]} | INTERVIEW | PYTHON3 | CODEWARS | 1,941 |
def solution(a):
|
fed45bed3df924999639acaa5daa3212 | UNKNOWN | # Unflatten a list (Harder than easy)
This is the harder version of Unflatten a list (Easy)
So you have again to build a method, that creates new arrays, that can be flattened!
# Shorter: You have to unflatten a list/an array.
You get an array of integers and have to unflatten it by these rules:
```
- You have to d... | ["unflatten=lambda m,d,c=0:m if c==d else unflatten(parse(m,[0,1][c&1]),d,c+1)\n\ndef parse(ar, lr):\n sub, i = [], [0, len(ar) - 1][lr]\n while 0 <= i < len(ar):\n j, r = ar[i], lr == 1\n if isinstance(j, list):\n sub.append(parse(j, lr))\n i += [1, -1][r]\n ... | {"fn_name": "unflatten", "inputs": [[[4, 5, 1, 7, 1], 2], [[12, 1, 5, 3, 1, 55, 2, 3, 7, 8, 1], 3]], "outputs": [[[[4, [5, 1, 7]], 1]], [[12, 1, [5, [3, 1, 55], 2], [3, 7, 8], 1]]]} | INTERVIEW | PYTHON3 | CODEWARS | 11,289 |
def unflatten(flat_array, depth):
|
fee61fde8b9021b7f3ec6ebbad438d74 | UNKNOWN | Alice has a hand of cards, given as an array of integers.
Now she wants to rearrange the cards into groups so that each group is size W, and consists of W consecutive cards.
Return true if and only if she can.
Example 1:
Input: hand = [1,2,3,6,2,3,4,7,8], W = 3
Output: true
Explanation: Alice's hand can be rearrang... | ["class Solution:\n def isNStraightHand(self, hand: List[int], W: int) -> bool:\n # 1, 2, 2, 3, 3, 4, 6, 7, 8\n # 1 2 3\n # 2 3 4\n # 6 7 8\n \n # W length Q\n # how many opened\n # # of the element is current opened one\n \n q = deque()... | {"fn_name": "isNStraightHand", "inputs": [[[1, 2, 3, 6, 2, 3, 4, 7, 8], 3]], "outputs": [true]} | INTERVIEW | PYTHON3 | LEETCODE | 139,316 |
class Solution:
def isNStraightHand(self, hand: List[int], W: int) -> bool:
|
8d326de78f70251c37af059e0652ffe8 | UNKNOWN | Andre has very specific tastes. Recently he started falling in love with arrays.
Andre calls an nonempty array $b$ good, if sum of its elements is divisible by the length of this array. For example, array $[2, 3, 1]$ is good, as sum of its elements — $6$ — is divisible by $3$, but array $[1, 1, 2, 3]$ isn't good, as $... | ["# ------------------- fast io --------------------\nimport os\nimport sys\nfrom io import BytesIO, IOBase\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = \"x\" in file.mode or \"... | {"inputs": ["3\n1\n2\n4\n"], "outputs": ["4 \n4 4 \n4 4 4 4 \n"]} | INTERVIEW | PYTHON3 | CODEFORCES | 40,989 | |
70c820599a0de1dfb4ddee70905266b4 | UNKNOWN | per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicament... | ["f={}\n\nf[-40] = '-319993.68'\nf[-41] = '-344598.60'\nf[-42] = '-370433.52'\nf[-43] = '-397528.44'\nf[-44] = '-425913.37'\nf[-45] = '-455618.29'\nf[-46] = '-486673.22'\nf[-47] = '-519108.14'\nf[-48] = '-552953.07'\nf[-49] = '-588238.00'\nf[-50] = '-624992.93'\nf[-29] = '-121939.61'\nf[-30] = '-134994.52'\nf[-31] = '-... | {
"inputs": [
"0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10\n"
],
"outputs": [
""
]
} | INTERVIEW | PYTHON3 | CODEFORCES | 37,811 | |
bec518661022652456fc914fb352bea5 | UNKNOWN | Given a square grid of integers arr, a falling path with non-zero shifts is a choice of exactly one element from each row of arr, such that no two elements chosen in adjacent rows are in the same column.
Return the minimum sum of a falling path with non-zero shifts.
Example 1:
Input: arr = [[1,2,3],[4,5,6],[7,8,9]]
O... | ["class Solution:\n def minFallingPathSum(self, arr: List[List[int]]) -> int:\n dp = [0] * len(arr[0])\n for r, row in enumerate(arr):\n minNb = min(dp)\n min1 = dp.index(minNb)\n dp[min1] = float('inf')\n min2 = dp.index(min(dp))\n dp[min1] = minN... | {"fn_name": "minFallingPathSum", "inputs": [[[[1, 2, 3], [6, 6, 7], [7, 8, 9], [], []]]], "outputs": [13]} | INTERVIEW | PYTHON3 | LEETCODE | 128,779 |
class Solution:
def minFallingPathSum(self, arr: List[List[int]]) -> int:
|
0c1c0beaf5f22758b5006e95199a3d42 | UNKNOWN | Alex and Lee continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones.
Alex and Lee take turns, with Alex starting first. Initially, M = 1.
On each player's turn,... | ["from functools import *\nclass Solution:\n def stoneGameII(self, arr):\n a =[]\n s=0\n n = len(arr)\n for i in arr[::-1]:\n s+=i\n a.append(s)\n a=a[::-1]\n @lru_cache(None)\n def fun(i,m):\n if i+2*m>=n:return a[i]\n mn =... | {"fn_name": "stoneGameII", "inputs": [[[26, 24, 17, 8, 4]]], "outputs": [10]} | INTERVIEW | PYTHON3 | LEETCODE | 95,147 |
class Solution:
def stoneGameII(self, piles: List[int]) -> int:
|
19b2108b46aeba70e457a429259fd0e1 | UNKNOWN | You are given a set of points in the 2D plane. You start at the point with the least X and greatest Y value, and end at the point with the greatest X and least Y value. The rule for movement is that you can not move to a point with a lesser X value as compared to the X value of the point you are on. Also for points hav... | ["from math import sqrt\n\ndef get_distance(x1,y1,x2,y2):\n return sqrt((x1-x2)**2 + (y1-y2)**2)\n\nT = int(input())\nans = []\n\nfor _ in range(T):\n blank = input()\n N = int(input())\n\n C = [[] for i in range(10**4+1)]\n\n for i in range(N):\n x,y = [int(i) for i in input().split()]\n C... | {"inputs": [["3", "", "2", "0 0", "0 1", "", "3", "0 0", "1 1", "2 2", "", "4", "0 0", "1 10", "1 5", "2 2", "", ""]], "outputs": [["1.00", "2.83", "18.21", "", "For the third test case above, the following is the path you must take:", "0,0 -> 1,10 ", "1,10 -> 1,5", "1,5 -> 2,2", "= 18.21"]]} | INTERVIEW | PYTHON3 | CODECHEF | 16,943 | |
f7d1dcc83c831ec98717700763ae72a8 | UNKNOWN | Chef has found a new game and now he wants you to help him to get as much points as possible.
Rules of the game: There are different types of game pieces - geometric shapes composed of some amount of square blocks. In the picture below you can see all the types of figures and enumeration.
The playing field is 10 cel... | ["import sys\n\nblocks = {}\n\nfor i in range(1, 10):\n blocks[i] = [(0, 0)]\nfor i in range(2, 10, 2):\n for j in range(1, i / 2 + 1):\n blocks[i].append((j, 0))\n blocks[i + 1].append((0, j))\n# print blocks\nblocks[10] = [(0, 0), (0, 1), (1, 0), (1, 1)]\nblocks[11] = [(0, 0), (0, 1), (0, 2), (1, ... | {"inputs": [["8 3 11", "6 14 12", "5 10 11", "5 7 11", "16 19 1", "-1 -1 -1", "", ""]], "outputs": [["3 6 5 2 2 2 1 10 8", "1 4 8 2 6 1 3 7 2", "1 5 8 3 4 8 2 6 8", "3 9 8 2 10 7 1 1 6", "3 10 8 2 8 3 -1 -1 -1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 58,460 | |
1aed48de23c5e20fc2977621729eea0d | UNKNOWN | Indian National Olympiad in Informatics 2015
In this problem you are given two lists of N integers, a1, a2, ..., aN and b1, b2, ... bN. For any pair (i, j) with i, j ϵ {1, 2, ..., N} we define the segment from i to j, written as [i, j], to be i, i + 1, ..., j if i ≤ j and i, i + 1, ..., N, 1, 2, ...,j if i > j. Thus if... | ["#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\n#import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\nfrom collections import deque\r\ndef getmax(x,n,k):\r\n mx = ... | {"inputs": [["52 3 2 3 13 4 4 6 3"]], "outputs": [["18"]]} | INTERVIEW | PYTHON3 | CODECHEF | 31,067 | |
31df9c7f8ef790fd14927432ff080c24 | UNKNOWN | Chef has two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. You should choose $N+M-1$ pairs, each in the form $(A_x, B_y)$, such that the sums $A_x + B_y$ are all pairwise distinct.
It is guaranteed that under the given constraints, a solution always exists. If there are multiple solutions, you ... | ["# cook your dish here\nn,m = map(int, input().split())\narr1 = list(map(int, input().split()))\narr2 = list(map(int, input().split()))\nmax1 = arr1.index(max(arr1))\nmin2 = arr2.index(min(arr2))\narr = []\nfor i in range(m):\n arr.append([max1, i])\nfor i in range(n):\n if i!=max1:\n arr.append([i , min... | {"inputs": [["3 2", "10 1 100", "4 3", ""]], "outputs": [["2 1", "0 0", "1 0", "0 1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,894 | |
be5a71d324fb6f1eeb5297fdb5dde2c2 | UNKNOWN | Raavan gave a problem to his son, Indrajeet, and asked him to solve the problem to prove his intelligence and power. The Problem was like: Given 3 integers, $N$, $K$, and $X$, produce an array $A$ of length $N$, in which the XOR of all elements of each contiguous sub-array, of length $K$, is exactly equal to $X$. Indra... | ["# cook your dish here\nfor _ in range(int(input())):\n l,n,x=map(int,input().split())\n m=[]\n pw1 = (1 << 17); \n pw2 = (1 << 18); \n if (n == 1) : \n m.append(x)\n elif (n == 2 and x == 0) : \n m.append(-1)\n elif (n == 2) : \n m.append(x)\n m.append(0)\n else ... | {"inputs": [["3", "5 1 4", "5 2 4", "5 3 4", ""]], "outputs": [["4 4 4 4 4", "3 7 3 7 3", "11 6 9 11 6"]]} | INTERVIEW | PYTHON3 | CODECHEF | 18,719 | |
73aa144f164c63f8fa280ad5496806ec | UNKNOWN | -----Description-----
The Antique Comedians of India prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACI has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept int... | ["#include<stdio.h>\nint rev(int k)\n{\nint j,res=0;\nwhile(k)\n{\nres=res*10+k%10;\nk/=10;\n}\nreturn res;\n}\nint main()\n{\nint j,a,b,m,k;\nwhile(scanf(\"%d\",&m)!=EOF)\n{\nfor(j=1;j<=m;j++)\n{\nscanf(\"%d %d\",&a,&b);\nk=rev(a)+rev(b);\nprintf(\"%d\\n\",rev(k));\n}\n}\nreturn 0;\n}\n", "#include <stdio.h>\r\nint ma... | {"inputs": [["3", "24 1", "4358 754", "305 794"]], "outputs": [["34", "1998", "1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 13,527 | |
a28d4e3bc0b06b41f3af57d3ec8a90dd | UNKNOWN | You are given two integers N$N$ and M$M$. You have to construct a matrix with N$N$ rows and M$M$ columns. Consider a multiset S$S$ which contains N+M$N + M$ integers: for each row and each column of this matrix, the MEX of the elements of this row/column belongs to S$S$. Then, in the matrix you construct, the MEX of S$... | ["for _ in range(int(input())):\n x,y=map(int,input().split())\n if(x==y):\n if(x==1):\n print(1)\n else:\n n=0\n for i in range(x-1):\n n=i\n for _ in range(y):\n print(n,end=' ')\n n=(n+1)%x\n ... | {"inputs": [["2", "3 3", "4 2", ""]], "outputs": [["9 1 0", "1 0 2", "7 5 8", "2 2", "3 0", "1 1", "0 1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 42,359 | |
0246f4eb0a37fb07b5399dd716e630b9 | UNKNOWN | You are provided with an input containing a number. Implement a solution to find the largest sum of consecutive increasing digits , and present the output with the largest sum and the positon of start and end of the consecutive digits.
Example :
Input :> 8789651
Output :> 24:2-4
where 24 is the largest sum and 2-4 is s... | ["l=list(map(int,input()))\nt=-1\nx=-1\ny=-1\nfor i in range(len(l)):\n s=l[i]\n a=i+1\n b=i+1\n for j in range(i+1,len(l)):\n if l[i]<l[j]:\n s=s+l[j]\n b=j+1\n else:\n break\n if s>t:\n t=s\n x=a\n y=b\nprint(t,end=\":\")\nprint(x,y,se... | {"inputs": [[":", "Input :> 8789651"]], "outputs": [["where 24 is the largest sum and 2-4 is start and end of the consecutive increasing digits."]]} | INTERVIEW | PYTHON3 | CODECHEF | 14,106 | |
7669f928d6d6942fb6001104800da7a5 | UNKNOWN | Uttu got to know about an interesting two-player mobile game recently and invites his friend Gangwar to try it out with him. Gangwar, however, has been playing this game since it was out 5 years ago and is a Legendary Grandmaster at it. Uttu immediately thought of somehow cheating in this game to beat Gangwar.
But the ... | ["''' J A I ~ S H R E E ~ R A M '''\r\n\r\n# Title: cc-CKOJ20D.py\r\n# created on: 20-07-2020 at 20:46:04\r\n# Creator & Template : Udit Gupta \"@luctivud\"\r\n# https://github.com/luctivud\r\n# https://www.linkedin.com/in/udit-gupta-1b7863135/\r\n\r\n\r\nimport math; from collections import *\r\nimport sys; fr... | {"inputs": [["2", "10 10", "1 2"]], "outputs": [["First"]]} | INTERVIEW | PYTHON3 | CODECHEF | 2,195 | |
876339c613afdcfc36a899953e7f1f85 | UNKNOWN | Laxman, a great Mathematician and Thinker, gives Sugreev an integer, $N$, and asks him to make an array $A$ of length $N$, such that $\sum A$i$^3 = X^2$, to prove the purity of the bond of his friendship with Ram. Sugreev is facing difficulty in forming the array. So, help Sugreev to form this array.
-----Note:-----
... | ["# cook your dish here\nt = int(input())\n\nwhile(t>0):\n n = int(input())\n k=1\n while(k<=n):\n print(k, end=' ')\n k+=1\n print('\\n')\n t-=1", "from math import tan,sqrt,pi,floor,ceil\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n y=0\r\n for i in range(1,1001):\r\n ... | {"inputs": [["2", "1", "6", ""]], "outputs": [["4", "5 10 5 10 5 5"]]} | INTERVIEW | PYTHON3 | CODECHEF | 12,483 | |
c0e28542d2a495fcd5f6431d824aa9db | UNKNOWN | Anna Hazare is a well known social activist in India.
On 5th April, 2011 he started "Lokpal Bill movement".
Chef is very excited about this movement. He is thinking of contributing to it. He gathers his cook-herd and starts thinking about how our community can contribute to this.
All of them are excited about this t... | ["from collections import deque\nfrom sys import stdin\nimport psyco\npsyco.full()\n\ngraph = [[]]\nWHITE, GRAY, BLACK = 0, 1, 2\n\ndef notoriety(x, f_count):\n queue = deque([x])\n d = [0 for i in range(f_count+1)]\n p = [0 for i in range(f_count+1)]\n color = [WHITE for i in range(f_count+1)]\n while l... | {"inputs": [["1", "6", "3", "5", "1 4", "3 5 6", "2 4 6", "4 5", "", ""]], "outputs": [["4 1.166667"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,844 | |
85d02f4ca99194674af152fbf177818d | UNKNOWN | Indian National Olympiad in Informatics 2014
Due to resurfacing work, all north-south traffic on the highway is being diverted through the town of Siruseri. Siruseri is a modern, planned town and the section of roads used for the diversion forms a rectangular grid where all cars enter at the top-left intersection (nort... | ["class PathNode:\n\n def __init__(self, row, col, st_x, st_y, p_count=0):\n self.x = row\n self.y = col\n self.pathCount = p_count\n\n def __str__(self):\n return str(self.x) + \" | \" + str(self.y) + \" | \" + str(self.pathCount)\n\n\nclass GraphUtil:\n def __init__(self, mat, R,C... | {"inputs": [["3 4 2", "1 1 1 10 1 1 11 1 1 1"]], "outputs": [["5"]]} | INTERVIEW | PYTHON3 | CODECHEF | 47,767 | |
cd822a35265c231e604393c271b13749 | UNKNOWN | Salmon is playing a game!
He is given two integers $N$ and $K$. His goal is to output $K$ pairs $(x_i,y_i)$. He creates a function $f$ such that $f(x_i) = y_i$ and $f$ is undefined for all other values of $x$. His pairs must then meet the following conditions:
- All $x_i$ are distinct.
- All $y_i$ are distinct.
- All $... | ["for _ in range(int(input())):\n n,k=[int(x) for x in input().split()]\n if k%4==0:\n for i in range(0,k,4):\n print(i,i+1)\n print(i+1,i+2)\n print(i+2,i+3)\n print(i+3,i)\n elif k%4==1:\n for i in range(4,k-1,4):\n print(i,i+1)\n ... | {"inputs": [["2", "3 7", "4 6", ""]], "outputs": [["5 3", "1 7", "0 4", "2 5", "3 1", "4 2 ", "7 0", "1 10", "10 14", "15 1", "14 13", "5 15", "13 5"]]} | INTERVIEW | PYTHON3 | CODECHEF | 59,331 | |
e005f6ccc350947ce6be624be9d6af7d | UNKNOWN | Recently Chef learned about Longest Increasing Subsequence. To be precise, he means longest strictly increasing subsequence, when he talks of longest increasing subsequence. To check his understanding, he took his favorite n-digit number and for each of its n digits, he computed the length of the longest increasing su... | ["m=int(input())\nwhile m:\n m-=1\n n=int(input())\n t=[i for i in input().split()]\n print(''.join(t))", "t=int(input())\nwhile t:\n t-=1\n n=int(input())\n m=[i for i in input().split()]\n print(''.join(m))", "t = int(input())\nwhile t:\n t-=1\n n = int(input())\n x = [i for i in inpu... | {"inputs": [["5", "1 ", "1", "2 ", "1 2", "2 ", "1 1", "4", "1 2 2 1", "7 ", "1 2 2 1 3 2 4", "", ""]], "outputs": [["7", "36", "54", "1531", "1730418"]]} | INTERVIEW | PYTHON3 | CODECHEF | 21,362 | |
4584ee9d9579225f6b565ed1ab93f7d0 | UNKNOWN | Meanwhile, Candace and Stacy are busy planning to attend the concert of the famous Love Händel. Jeremy will also be attending the event. Therefore, Candace plans to offer the best possible gift to Jeremy.
Candace has $N$ strings, each of length $M$. Each character of each string can either be a lowercase English letter... | ["# import all important libraries and inbuilt functions\n\nfrom fractions import Fraction\nimport numpy as np\nimport sys,bisect,copyreg,copy,statistics,os\nfrom math import *\nfrom collections import Counter,defaultdict,deque,OrderedDict \nfrom itertools import combinations,permutations,accumulate \nfrom numpy.lina... | {"inputs": [["2", "3 3", "xab", "a#z", "caa", "5 4", "pyqs", "vcot", "qbiu", "lihj", "uvmz", ""]], "outputs": [["xabza", "pvcbihjz"]]} | INTERVIEW | PYTHON3 | CODECHEF | 37,987 | |
895dded7c68015e192e77a815ed28858 | UNKNOWN | Indian National Olympiad in Informatics 2013
N people live in Sequence Land. Instead of a name, each person is identified by a sequence of integers, called his or her id. Each id is a sequence with no duplicate elements. Two people are said to be each other’s relatives if their ids have at least K elements in common. T... | ["def check_relative(i,j):\n if is_relative[i]:return\n if len(land[i].intersection(land[j]))>=k:\n is_relative[i]=True\n for ii in range(n):\n check_relative(ii,i)\n\nn,k=map(int,input().split())\nland=[]\nis_relative=[True]+[False]*(n-1)\nfor i in range(n):\n p,*q=input().split()\n ... | {"inputs": [["4 2", "4 4 6 7 84 8 3 0 42 0 106 1 2 3 0 5 8"]], "outputs": [["3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 31,225 | |
69d9303aa3a83b43978b29e741f00b8f | UNKNOWN | Chef has a rectangular matrix A of nxm integers. Rows are numbered by integers from 1 to n from top to bottom, columns - from 1 to m from left to right. Ai, j denotes the j-th integer of the i-th row.
Chef wants you to guess his matrix. To guess integers, you can ask Chef questions of next type: "How many integers from... | ["# CHNGSS.py\n\nimport sys\nfrom random import *\n\nn,m,c = list(map(int,input().split()))\narr = [[1]*m for i in range(n)];\nsaved = 0;\nfor i in range(n):\n\tfor j in range(m):\n\t\tprint(1,(i+1),(i+1),(j+1),(j+1),1,25)\n\t\tsys.stdout.flush()\n\t\ta = int(input())\n\t\tif a == 1 :\n\t\t\tsaved += 1;\n\t\t\tarr[i][j... | {"inputs": [["3 3 10", "4", "0", "3", "1", "6", "", ""]], "outputs": [["1 1 2 1 2 1 3", "1 3 3 1 3 1 1", "1 3 3 1 3 2 2", "1 1 2 3 3 1 1", "2 3 3 1 3", "3", "2 2 1", "2 2 1", "2 2 2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 14,705 | |
d52596c449b5b409aa9d6be4d10b22fa | UNKNOWN | Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be equal either to $a$ or $b$ seconds. It's guaranteed that one can go bet... | ["import heapq\nn,m,a,b=map(int,input().split())\ngraph={i:[] for i in range(n)}\nfor i in range(m):\n u,v,w=map(int,input().split())\n graph[u-1].append((v-1,w))\n graph[v-1].append((u-1,w))\ncomponents=[-1]*n\ncomp=-1\nfor i in range(n):\n if components[i]==-1:\n comp+=1\n components[i]=comp... | {
"inputs": [
"5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\n5 1 20\n",
"6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 1 13\n",
"2 1 1 2\n2 1 1\n",
"2 1 9999999 10000000\n1 2 10000000\n",
"3 3 78422 6789101\n3 1 6789101\n2 1 78422\n2 3 78422\n",
"3 3 2770628 3912422\n1 2 2770628\n2... | COMPETITION | PYTHON3 | CODEFORCES | 2,300 | |
79e58d9923beed0539616e92fc19b6e4 | UNKNOWN | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequ... | ["X, D = list(map(int, input().split()))\ncn = 1\nadd0 = 1 if (X&1) else 0\nans = []\nfor i in range(30,0,-1):\n\tif not (X & (1<<i)): continue\n\tans += [cn]*i\n\tadd0 += 1\n\tcn += D\nfor i in range(add0):\n\tans.append(cn)\n\tcn += D\nprint(len(ans))\nprint(' '.join(map(str, ans)))\n", "x, d = list(map(int, input().... | {"inputs": ["10 5\n", "4 2\n", "4 1\n", "1 1\n", "63 1\n", "98 88\n", "746 173\n", "890 553\n", "883 1000\n", "1 1000\n", "695 188\n", "2060 697\n", "70 3321\n", "6358 1646\n", "15000 1\n", "1048576 1\n", "1000000 1\n", "10009 1\n", "10001 1\n"], "outputs": ["6\n1 1 1 7 13 19 ", "3\n1 1 4 ", "3\n1 1 3 ", "1\n1 ", "21\n... | COMPETITION | PYTHON3 | CODEFORCES | 1,252 | |
784ee0c25cd95a1bda65ba450a34d83b | UNKNOWN | Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ... | ["str = input()\nl = len(str)\na = [0] * (2 * l)\npos = [[] for i in range(26)]\nfor i, c in enumerate(str):\n t = ord(c) - ord('a')\n a[i] = t\n a[i + l] = t\n pos[t].append(i)\nans = 0\nfor c in range(26):\n cur = 0\n for k in range(1, l):\n cnt = [0] * 26\n for i in pos[c]:\n ... | {
"inputs": [
"technocup\n",
"tictictactac\n",
"bbaabaabbb\n",
"cbbbbcaaca\n",
"cadbcdddda\n",
"bababbdaee\n",
"fabbbhgedd\n",
"gaejllebhn\n",
"bbababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbb\n",
"eaaebccaeacdecaedcaabbbdeebc... | COMPETITION | PYTHON3 | CODEFORCES | 3,529 | |
3dc89197d0b97184f3419798c757b675 | UNKNOWN | The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ... | ["x = input ()\n\nflag = 0\ns = 0\n\nfor each_item in x:\n if each_item == '0':\n if flag == 0:\n flag = 1;\n continue\n else:\n print (each_item, end = '')\n else:\n if (s == len (x) - 1 and flag == 0) :\n continue\n print (each_item, end = ... | {
"inputs": [
"101\n",
"110010\n",
"10000\n",
"1111111110\n",
"10100101011110101\n",
"111010010111\n",
"11110111011100000000\n",
"11110010010100001110110101110011110110100111101\n",
"1001011111010010100111111\n",
"1111111111\n",
"11111111111111111111001111010011101101111110... | COMPETITION | PYTHON3 | CODEFORCES | 5,168 | |
14027d14d049d1b91f70fed704f84cdf | UNKNOWN | Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | ["X = [[], ['0', '1'], ['00', '01', '10', '11'], ['001', '010', '011', '100', '101', '110'], ['0010', '0011', '0100', '0101', '0110', '1001', '1010', '1011', '1100', '1101'], ['00100', '00101', '00110', '01001', '01011', '01100', '01101', '10010', '10011', '10100', '10110', '11001', '11010', '11011'], ['001001', '00101... | {
"inputs": [
"010101\n",
"11001100\n",
"0\n",
"00\n",
"01\n",
"000\n",
"100\n",
"001\n",
"101\n",
"0000\n",
"0100101110\n",
"1101111000011110111111110101100111111110111100001111011010111001101100010110000001010101101010111000\n",
"1000\n",
"0010\n",
"1010\n... | COMPETITION | PYTHON3 | CODEFORCES | 10,763 | |
95dd3c8d5540883a6da8f4559cde4a76 | UNKNOWN | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two di... | ["def gcd(a, b):\n while b > 0:\n a, b = b, a % b\n return a\n\nn = int(input())\nA = list(map(int, input().split()))\n\nGCD = A[0]\nfor x in A[1:]:\n GCD = gcd(GCD, x)\nnum = max(A) // GCD - n\nif num % 2 == 0:\n print(\"Bob\")\nelse:\n print(\"Alice\")\n\n", "from fractions import gcd\n\n\nn = i... | {
"inputs": [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n",
"10\n72 96 24 66 6 18 12 30 60 48\n",
"10\n78 66 6 60 18 84 36 96 72 48\n",
"10\n98 63 42 56 14 77 70 35 84 21\n",
"2\n1 1000000000\n",
"2\n1000000000 999999999\n",
"3\n2 4 6\n",
"2\n4 6\n",
"2\n2 6\n",
"2\n6 2\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 6,210 | |
abf305271b839e69eef3fee6c66c65cb | UNKNOWN | A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi... | ["from sys import stdin\n\n#stdin = open('input.txt')\n\nn = int(stdin.readline())\n\nseq = [int(x) for x in stdin.readline().split()]\ncarry = seq[0]\nresult = [carry]\n\nmark = False\ncur_len = 0\nmax_len = 0\n\ni = 1\nwhile i < len(seq) - 1:\n if mark:\n if seq[i] != seq[i + 1]:\n cur_len += 1\n... | {
"inputs": [
"4\n0 0 1 1\n",
"5\n0 1 0 1 0\n",
"3\n1 0 0\n",
"4\n1 0 0 1\n",
"7\n1 0 1 1 1 0 1\n",
"14\n0 1 0 0 0 1 1 0 1 0 1 0 1 0\n",
"3\n1 0 1\n",
"3\n0 0 1\n",
"3\n1 1 0\n",
"3\n1 1 1\n",
"4\n1 1 0 1\n",
"4\n1 0 1 1\n",
"10\n0 1 0 1 0 0 1 0 1 0\n",
"4\n0 1 ... | COMPETITION | PYTHON3 | CODEFORCES | 11,919 | |
ffb99083a3421b344c41a379510e0acf | UNKNOWN | For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th... | ["import random\n\nn = int(input())\nv = []\na = []\nfor i in range(n):\n a.append(i)\n\nfor _ in range(0, n):\n x, y = list(map(int, input().split()))\n v.append([x, y, x*x+y*y])\n\nwhile 1>0:\n x = 0\n y = 0\n ans = [0]*n\n random.shuffle(a)\n for i in range(n):\n if (x+v[a[i]][0])**2+(... | {
"inputs": [
"3\n999999 0\n0 999999\n999999 0\n",
"1\n-824590 246031\n",
"8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n",
"6\n1000000 0\n1000000 0\n-1000000 0\n0 1000000\n0 -1000000\n0 -1000000\n",
"8\n-411248 143802\n3003... | COMPETITION | PYTHON3 | CODEFORCES | 635 | |
70b53265451cf3a130f0d05c54a0e5e2 | UNKNOWN | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain posi... | ["n=int(input())\nq=[]\nfor i in range(max(0,n-100),n+1):\n\tj=i\n\tres=i\n\twhile j:\n\t\tres+=j%10\n\t\tj//=10\n\tif res==n:\n\t\tq.append(i)\nprint(len(q))\nfor i in q:\n\tprint(i)", "n = int(input())\nans = set()\nf = lambda x: sum(int(i) for i in str(x))\nfor i in range(max(0, n - 1000), n + 1):\n if i + f(i) =... | {
"inputs": [
"21\n",
"20\n",
"1\n",
"2\n",
"3\n",
"100000001\n",
"1000000000\n",
"999999979\n",
"9\n",
"10\n",
"11\n",
"39\n",
"66\n",
"75\n",
"100\n",
"101\n",
"2014\n",
"999999994\n"
],
"outputs": [
"1\n15\n",
"0\n",
"0\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 7,546 | |
74bd768aa9d521cb9e3727a6fdbd5868 | UNKNOWN | A permutation p of size n is the sequence p_1, p_2, ..., p_{n}, consisting of n distinct integers, each of them is from 1 to n (1 ≤ p_{i} ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition p_{p}_{i} = n - i + 1.
You have integer n. Find some lucky permutation p of siz... | ["n = int(input())\nif n%4 > 1:\n print(-1)\nelse:\n a = [n+1>>1]*n\n for i in range(n//4):\n j = i*2\n a[j], a[j+1], a[-2-j], a[-1-j] = j+2, n-j, j+1, n-1-j\n print(' '.join(map(str, a)))", "n=int(input())\n\nL=[0]*(n+1)\n\nX=[False]*(n+1)\n\nif(n%4!=0 and n%4!=1):\n print(-1)\n\nelse:\n for i in range... | {"inputs": ["1\n", "2\n", "4\n", "5\n", "3\n", "6\n", "7\n", "8\n", "9\n", "10002\n", "10003\n", "25\n", "29\n", "33\n", "9\n", "13\n", "17\n", "99999\n"], "outputs": ["1 \n", "-1\n", "2 4 1 3 \n", "2 5 3 1 4 \n", "-1\n", "-1\n", "-1\n", "2 8 4 6 3 5 1 7 \n", "2 9 4 7 5 3 6 1 8 \n", "-1\n", "-1\n", "2 25 4 23 6 21 8 19... | COMPETITION | PYTHON3 | CODEFORCES | 6,020 | |
5b17d60ffae17504720940547943c8b2 | UNKNOWN | You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' $\rightarrow$ 'y' $\rightarrow$ 'x' $\rightarrow \ldots \rightarrow$ 'b' $\rightarrow$ 'a' $\rightarrow$ 'z'. In other words, each character is replaced with th... | ["#!/usr/bin/env python3\n\nimport re\n\ntry:\n while True:\n s = input()\n m = re.search(r\"[^a]\", s)\n if m is None:\n print(s[:-1], end=\"z\\n\")\n else:\n j = s.find('a', m.end())\n if j == -1:\n j = len(s)\n print(end=s[:m.s... | {
"inputs": [
"codeforces\n",
"abacaba\n",
"babbbabaababbaa\n",
"bcbacaabcababaccccaaaabacbbcbbaa\n",
"cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda\n",
"a\n",
"eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdc... | COMPETITION | PYTHON3 | CODEFORCES | 12,834 | |
26b8b520bfff7e6df6c412e9878175dd | UNKNOWN | After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.
Form... | ["mod = 1000000007\n\ndef sum(x, y, k, add) :\n if k < add : return 0\n up = x + add\n if up > k : up = k\n add = add + 1\n return y * ( ( (add + up) * (up - add + 1) // 2 ) % mod ) % mod\n\ndef solve(x, y, k, add = 0) :\n if x == 0 or y == 0 : return 0\n if x > y :\n x, y = y, x\n pw = 1... | {
"inputs": [
"4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n",
"10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16\n",
"10\n1 1 2 2 8\n3 4 5 9 4\n2 10 5 10 6\n8 5 10 8 8\n1 2 8 2 20\n8 6 10 8 20\n6 7 6 7 9\n8 5 10 10 13\n1 8... | COMPETITION | PYTHON3 | CODEFORCES | 1,619 | |
423636933a163f8c813b5b654b080257 | UNKNOWN | Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with... | ["import sys\n\nn = int(input())\n\nv = [ list(map(int, input().split())) for i in range(n)]\n\nres = []\n\nfor i in range(n):\n\tif v[i][2] >= 0:\n\t\tres.append(i + 1)\n\t\tdec = 0\n\t\tfor j in range(i + 1, n):\n\t\t\tif v[j][2] >= 0:\n\t\t\t\tif v[i][0] > 0:\n\t\t\t\t\tv[j][2] -= v[i][0]\n\t\t\t\t\tv[i][0] -= 1\n\t... | {
"inputs": [
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n",
"10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24\n",
"10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5\n",
"10\n4 9 1\n8 2 14\n7 10... | COMPETITION | PYTHON3 | CODEFORCES | 10,992 | |
cfb6aa74d8d0cbc208c42b516a83a677 | UNKNOWN | Alex decided to go on a touristic trip over the country.
For simplicity let's assume that the country has $n$ cities and $m$ bidirectional roads connecting them. Alex lives in city $s$ and initially located in it. To compare different cities Alex assigned each city a score $w_i$ which is as high as interesting city se... | ["import sys\ninput = sys.stdin.readline\n\nn,m=list(map(int,input().split()))\nW=[0]+list(map(int,input().split()))\nE=[tuple(map(int,input().split())) for i in range(m)]\nS=int(input())\n\nELIST=[[] for i in range(n+1)]\nEW=[0]*(n+1)\n\nfor x,y in E:\n ELIST[x].append(y)\n ELIST[y].append(x)\n\n EW[x]+=1\n ... | {
"inputs": [
"5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2\n",
"10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6\n",
"1 0\n1000000000\n1\n",
"2 1\n999999999 2\n1 2\n2\n",
"3 2\n1 1335 2\n2 1\n3 2\n2\n",
"3 3\n1 1 1\n1 2\n3 2\n3 1\n3\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 5,693 | |
c25ee13c02bf7d15946fccc23071e6d4 | UNKNOWN | Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the pic... | ["n = int(input())\n\nxs = [int(x) for x in input().split()]\n\nseen = {}\n\nres = 0\n\nwhile xs:\n j = xs.index(xs[0], 1)\n res += j - 1\n xs = xs[1:j] + xs[j+1:]\n\nprint(res)\n", "n = int(input())\nt = list(map(int, input().split()))\n\nsw = 0\n\nwhile t != []:\n\tpr = 1 + t[1:].index(t[0])\n\t#print(pr)\n\... | {
"inputs": [
"4\n1 1 2 3 3 2 4 4\n",
"3\n1 1 2 2 3 3\n",
"3\n3 1 2 3 1 2\n",
"8\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\n",
"2\n1 2 1 2\n",
"3\n1 2 3 3 1 2\n",
"38\n26 28 23 34 33 14 38 15 35 36 30 1 19 17 18 28 22 15 9 27 11 16 17 32 7 21 6 8 32 26 33 23 18 4 2 25 29 3 35 8 38 37 31 37 12 25 3 ... | COMPETITION | PYTHON3 | CODEFORCES | 7,152 | |
414e6475ba20867fbc8096104cba22ce | UNKNOWN | This problem is the most boring one you've ever seen.
Given a sequence of integers a_1, a_2, ..., a_{n} and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements). Each element of the original sequence should be contained in exactly one o... | ["n,m=map(int,input().split());a=list(map(int,input().split()));p=0;t=[0]*3\nfor i in range(n):\n if(a[i]<a[p]):p=i \nif(n==2):print('0\\n1 1\\n')\nelse:\n a.sort();t[0]=min(a[0]+a[1]+m,a[1]+a[2]);t[1]=max(a[0]+a[n-1]+m,a[n-2]+a[n-1]);t[2]=(a[n-2]+a[n-1])-(a[0]+a[1])\n if(t[1]-t[0]>t[2]):p=n\n else:t[2]=t... | {
"inputs": [
"3 2\n1 2 3\n",
"5 10\n0 1 0 2 1\n",
"9 0\n11 22 33 44 55 66 77 88 99\n",
"10 100\n2705446 2705444 2705446 2705445 2705448 2705447 2705444 2705448 2705448 2705449\n",
"10 5\n5914099 5914094 5914099 5914097 5914100 5914101 5914097 5914095 5914101 5914102\n",
"12 3\n7878607 7878605... | COMPETITION | PYTHON3 | CODEFORCES | 1,144 | |
999bd8a2ab663c0510487650fc2a8c65 | UNKNOWN | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e. $u \in A$ or $v \i... | ["def main():\n n, m = list(map(int, input().split()))\n l = [[] for _ in range(n + 1)]\n for _ in range(m):\n u, v = list(map(int, input().split()))\n l[u].append(v)\n l[v].append(u)\n res = [0] * (n + 1)\n for u, x in enumerate(res):\n if not x:\n x, nxt = -1, [u]... | {
"inputs": [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n",
"5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5\n",
"10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8\n",
"10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1\n",
"10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n... | COMPETITION | PYTHON3 | CODEFORCES | 7,832 | |
1728bb3a662e5e38fab0d968dd9021bf | UNKNOWN | Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m col... | ["n,m=map(int,input().split())\nif n==1and m==1:print('YES\\n1')\nelif n==3and m==3:\n print('YES')\n print(6, 1, 8)\n print(7,5,3)\n print(2,9,4)\nelif n<4and m<4:print('NO')\nelif n==1 or m==1:\n t=max(n,m)\n a=[i for i in range(2,t+1,2)]\n a+=[i for i in range(1,t+1,2)]\n print('YES')\n fo... | {"inputs": ["2 4\n", "2 1\n", "1 1\n", "1 2\n", "1 3\n", "2 2\n", "2 3\n", "3 1\n", "3 2\n", "3 3\n", "1 4\n", "4 1\n", "4 2\n", "100 1\n", "1 100\n", "101 1\n", "1 101\n", "2 20\n"], "outputs": ["YES\n5 4 7 2 \n3 6 1 8 \n", "NO\n", "YES\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n6 1 8\n7 5 3\n2 9 4\n... | COMPETITION | PYTHON3 | CODEFORCES | 2,426 | |
ca8d10bddef0aa1caae61b6f015da4fc | UNKNOWN | Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!
The only thing Mrs. Smith remembered was that any permutation of $n$ can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.
The sequence of $n$ integers is call... | ["from math import sqrt\nn = int(input())\nk = int(sqrt(n))\nb = []\nlast = 0\nwhile last < n:\n b.append([last + j for j in range(k)])\n last = b[-1][-1] + 1\nk = len(b)\nfor i in range(k - 1, -1, -1):\n for j in b[i]:\n if j < n:\n print(1 + j, end=' ')\nprint()\n", "import math\n\nn = int(... | {"inputs": ["4\n", "2\n", "1\n", "3\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "20\n", "21\n", "22\n", "23\n", "24\n", "25\n", "100\n", "108\n"], "outputs": ["3 4 1 2\n", "2 1\n", "1\n", "3 2 1\n", "4 5 2 3 1\n", "5 6 3 4 1 2\n", "6 7 4 5 2 3 1\n", "7 8 5 6 3 4 1 2\n", "7 8 9 4 5 6 1 2 3\n", "8 9 10 5 6 7 2 3 4 1\n... | COMPETITION | PYTHON3 | CODEFORCES | 9,808 | |
faaadcbf2bdfa9528ce08e03d31d8a8e | UNKNOWN | You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of n characters "O" and "X".
Using the play sequence you can calculate the... | ["n = input()\nread = input()\np = []\nfor x in read.split():\n p.append((float)(x))\n \nv = 0.0\nl = 0.0\nfor item in p:\n v = v*(1-item) + item*(v + 2*l + 1)\n l = (l + 1)*item\nprint(v)\n", "n = input()\nread = input()\np = []\nfor x in read.split():\n p.append((float)(x))\n \nv = 0.0\nl = 0.0\nfor... | {
"inputs": [
"3\n0.5 0.5 0.5\n",
"4\n0.7 0.2 0.1 0.9\n",
"5\n1 1 1 1 1\n",
"10\n0.684846 0.156794 0.153696 0.714526 0.281868 0.628256 0.745339 0.123854 0.748936 0.856333\n",
"10\n0.684488 0.834971 0.834886 0.643646 0.162710 0.119851 0.659401 0.743950 0.220986 0.839665\n",
"10\n0.684416 0.1706... | COMPETITION | PYTHON3 | CODEFORCES | 2,740 | |
ac25363ec50aadbf7546225ef42382e4 | UNKNOWN | Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no ... | ["def main():\n n = int(input())\n result = []\n for i in range(2, n + 1):\n j = 2\n while j * j <= i:\n if i % j == 0:\n break\n j += 1\n else:\n j = i\n while j <= n:\n result.append(j)\n j *= i\n ... | {"inputs": ["4\n", "6\n", "1\n", "15\n", "19\n", "20\n", "37\n", "211\n", "557\n", "289\n", "400\n", "625\n", "31\n", "44\n", "160\n", "322\n", "30\n"], "outputs": ["3\n2 4 3 \n", "4\n2 4 3 5 \n", "0\n\n", "9\n2 4 8 3 9 5 7 11 13 \n", "12\n2 4 8 16 3 9 5 7 11 13 17 19 \n", "12\n2 4 8 16 3 9 5 7 11 13 17 19 \n", "19\n2 ... | COMPETITION | PYTHON3 | CODEFORCES | 12,738 | |
c877c477c95abb6f3f204d22faeb2155 | UNKNOWN | Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (x_{i}, y_{i}) of the plane. As the player visits station number i, he increases... | ["n, d = map(int, input().split())\na = [0] + list(map(int, input().split())) + [0]\nx = []\ny = []\nfor i in range(n):\n xx, yy = map(int, input().split())\n x += [xx]\n y += [yy]\nb = [-1] * n\nb[0] = 0\nc = True\nwhile c:\n c = False\n for i in range(n):\n for j in range(1, n):\n if i != j and b[i] != -... | {
"inputs": [
"3 1000\n1000\n0 0\n0 1\n0 3\n",
"3 1000\n1000\n1 0\n1 1\n1 2\n",
"5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67\n",
"6 1000\n142 712 254 869\n7 0\n95 38\n96 -20\n-7 93\n75 -45\n-80 -20\n",
"7 1288\n943 265 649 447 806\n-4 -51\n-26 32\n47 -28\n31 32\n61 65\n-45 -37\n82 4... | COMPETITION | PYTHON3 | CODEFORCES | 15,971 | |
5372aacc1f7cb1b2fd7bed96d764cdc8 | UNKNOWN | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order.
The stones always fall to the center of Liss's inter... | ["t = input()\na, b = [i for i, d in enumerate(t, 1) if d == 'l'], [i for i, d in enumerate(t, 1) if d == 'r']\na.reverse()\nprint('\\n'.join(map(str, b)))\nprint('\\n'.join(map(str, a)))", "inp = input()\nlength = len(inp)\nmin,max,dic1,dic2 = 1,length,[],[]\nfor i in range(0,length):\n if inp[i] == \"l\":\n ... | {
"inputs": [
"llrlr\n",
"rrlll\n",
"lrlrr\n",
"lllrlrllrl\n",
"llrlrrrlrr\n",
"rlrrrllrrr\n",
"lrrlrrllrrrrllllllrr\n",
"rlrrrlrrrllrrllrlrll\n",
"lllrrlrlrllrrrrrllrl\n",
"rrrllrrrlllrlllrlrrr\n",
"rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrrlrlrllrlr... | COMPETITION | PYTHON3 | CODEFORCES | 5,446 | |
e80478c46c16b17cfa6943ac25c6fd8e | UNKNOWN | 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... | ["\ndef solve(s):\n n = len(s)\n\n for i in range(n):\n s2 = s[i:] + s[:i]\n # print(s2)\n if s != s2 and s2[::-1] == s2:\n return 1\n\n for i in range( (n // 2) + 1, n):\n if s[i] != s[0]:\n return 2\n # print(s[i])\n return \"Impossible\"\n\ns = inp... | {
"inputs": [
"nolon\n",
"otto\n",
"qqqq\n",
"kinnikkinnik\n",
"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn... | COMPETITION | PYTHON3 | CODEFORCES | 6,153 | |
c87638713a73d6b46e88fc50da6aa578 | UNKNOWN | A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road.
A spanning tree is a set of roads containing exactly n - 1 roads such that it's possible to t... | ["from collections import defaultdict\nfrom collections import deque\nfrom functools import reduce\nn, x, y = [int(x) for x in input().split()]\nE = defaultdict(set)\nfor i in range(n-1):\n u, v = [int(x) for x in input().split()]\n E[u].add(v)\n E[v].add(u)\n\nif x > y:\n for v in E:\n if len(E[v]) ... | {
"inputs": [
"5 2 3\n1 2\n1 3\n3 4\n5 3\n",
"5 3 2\n1 2\n1 3\n3 4\n5 3\n",
"50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n32 3\n44 41\n50 31\n50 34\n5 14\n36 13\n22 40\n20 9\n9 43\n19 47\n48 40\n20 22\n33 45\n35 22\n33 24\n9 6\n13 1\n13 24\n49 20\n1 20\n29 38\n10 35\n25 23\n49 30\n42 8\n20 18\n32 1... | COMPETITION | PYTHON3 | CODEFORCES | 1,130 | |
e1b5b17e1a58f489d091b6bc54b00f94 | UNKNOWN | Dreamoon likes coloring cells very much.
There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$.
You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l_i \le n$)
Dreamoon will perform $m$ operations.
In $i$-th operation, Dre... | ["def main():\n import sys\n input = sys.stdin.readline\n\n N, M = list(map(int, input().split()))\n L = list(map(int, input().split()))\n\n if sum(L) < N:\n print(-1)\n return\n\n ans = [0] * M\n left = N\n for i in range(M-1, -1, -1):\n if left - L[i] >= i:\n an... | {
"inputs": [
"5 3\n3 2 2\n",
"10 1\n1\n",
"1 1\n1\n",
"2 2\n1 2\n",
"200 50\n49 35 42 47 134 118 14 148 58 159 33 33 8 123 99 126 75 94 1 141 61 79 122 31 48 7 66 97 141 43 25 141 7 56 120 55 49 37 154 56 13 59 153 133 18 1 141 24 151 125\n",
"3 3\n3 3 1\n",
"100000 1\n100000\n",
"200... | COMPETITION | PYTHON3 | CODEFORCES | 1,458 | |
d4e390e21c5438ebf3bcf6d08bf4f5e6 | UNKNOWN | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | ["h = int(input())\na = list(map(int, input().split()))\n\nw, q = [], []\np = r = 0\n\nfor i in a:\n for j in range(i):\n w.append(r)\n q.append(r - (j and p > 1))\n\n p = i\n r += i\n\nif w == q:\n print('perfect')\nelse:\n print('ambiguous')\n print(*w)\n print(*q)\n", "n=int(input(... | {"inputs": ["2\n1 1 1\n", "2\n1 2 2\n", "10\n1 1 1 1 1 1 1 1 1 1 1\n", "10\n1 1 1 1 1 2 1 1 1 1 1\n", "10\n1 1 1 1 2 2 1 1 1 1 1\n", "10\n1 1 1 1 1 1 1 2 1 1 2\n", "10\n1 1 1 3 2 1 2 4 1 3 1\n", "10\n1 1 1 4 1 1 2 1 5 1 2\n", "10\n1 1 21 1 20 1 14 1 19 1 20\n", "10\n1 1 262 1 232 1 245 1 1 254 1\n", "2\n1 1 199998\n", ... | COMPETITION | PYTHON3 | CODEFORCES | 1,130 | |
3eba8e275376e1b26dec85f9fc625b49 | UNKNOWN | Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universal ($\forall$) and existential ($\exists$). You can read more about them her... | ["import sys\n\nn, m = [int(x) for x in input().split()]\n\nadj_for = [[] for _ in range(n)]\nadj_back = [[] for _ in range(n)]\n\nfor _ in range(m):\n a, b = [int(x) for x in sys.stdin.readline().split()]\n a -= 1\n b -= 1\n adj_for[a].append(b)\n adj_back[b].append(a)\n\n\nlens = [len(adj_back[i]) for ... | {"inputs": ["2 1\n1 2\n", "4 3\n1 2\n2 3\n3 1\n", "3 2\n1 3\n2 3\n", "6 3\n1 3\n2 5\n4 6\n", "100 50\n55 13\n84 2\n22 63\n100 91\n2 18\n98 64\n1 86\n93 11\n17 6\n24 97\n14 35\n24 74\n22 3\n42 5\n63 79\n31 89\n81 22\n86 88\n77 51\n81 34\n19 55\n41 54\n34 57\n45 9\n55 72\n67 61\n41 84\n39 32\n51 89\n58 74\n32 79\n65 6\n8... | COMPETITION | PYTHON3 | CODEFORCES | 2,990 | |
2fd1aa234db816d319487838a88157d9 | UNKNOWN | Toad Zitz has an array of integers, each integer is between $0$ and $m-1$ inclusive. The integers are $a_1, a_2, \ldots, a_n$.
In one operation Zitz can choose an integer $k$ and $k$ indices $i_1, i_2, \ldots, i_k$ such that $1 \leq i_1 < i_2 < \ldots < i_k \leq n$. He should then change $a_{i_j}$ to $((a_{i_j}+1) \bm... | ["import sys\ninput = sys.stdin.readline\n\nn,m=list(map(int,input().split()))\nA=list(map(int,input().split()))\n\n\nMIN=0\nMAX=m\n\nwhile MIN!=MAX:\n x=(MIN+MAX)//2\n #print(x,MIN,MAX)\n #print()\n\n M=0\n for a in A:\n #print(a,M)\n if a<=M and a+x>=M:\n continue\n elif... | {
"inputs": [
"5 3\n0 0 0 1 2\n",
"5 7\n0 6 1 3 2\n",
"10 10\n5 0 5 9 4 6 4 5 0 0\n",
"4 6\n0 3 5 1\n",
"6 4\n1 3 0 2 1 0\n",
"10 1000\n981 824 688 537 969 72 39 734 929 718\n",
"10 300000\n111862 91787 271781 182224 260248 142019 30716 102643 141870 19206\n",
"100 10\n8 4 4 9 0 7 9 5 ... | COMPETITION | PYTHON3 | CODEFORCES | 16,054 | |
cef2085b0b4da8664b824be2a37820ac | UNKNOWN | The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied: t_{i} < t_{i} + 1 for each odd i < n; t_{i} > t_{i} + 1 for each even i < n.
For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), ... | ["def main():\n n, l = int(input()), list(map(int, input().split()))\n if not (n & 1):\n l.append(0)\n l.append(150001)\n i, b, c, fails0, fails1 = 0, 0, 150001, [], []\n try:\n while True:\n a, b, c = b, c, l[i]\n if a >= b or b <= c:\n if len(fails0) +... | {
"inputs": [
"5\n2 8 4 7 7\n",
"4\n200 150 100 50\n",
"10\n3 2 1 4 1 4 1 4 1 4\n",
"9\n1 2 3 4 5 6 7 8 9\n",
"5\n1 1 1 4 3\n",
"10\n7 7 8 10 5 10 1 5 2 6\n",
"50\n11836 28308 72527 92281 139289 93797 134555 148444 40866 111317 21564 87813 65466 20541 99238 2287 74647 128071 18163 61672 39... | COMPETITION | PYTHON3 | CODEFORCES | 16,076 | |
8707e9526b8ca05d6cbf5a4b673f9a98 | UNKNOWN | Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec... | ["def main():\n n, a, b, t = list(map(int, input().split()))\n a1 = a + 1\n b += a1\n l, res = [b if c == \"w\" else a1 for c in input()], []\n l[0] = x = l[0] - a\n if t <= x:\n print(int(t == x))\n return\n f = res.append\n for dr in 0, 1:\n if dr:\n l[1:] = l[-... | {
"inputs": [
"4 2 3 10\nwwhw\n",
"5 2 4 13\nhhwhh\n",
"5 2 4 1000\nhhwhh\n",
"3 1 100 10\nwhw\n",
"10 2 3 32\nhhwwhwhwwh\n",
"1 2 3 3\nw\n",
"100 20 100 10202\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwhwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwww\n",
"20 10 10 1\nhwhwhwh... | COMPETITION | PYTHON3 | CODEFORCES | 4,242 | |
644fc95041d3b50e2e7d022da0dc43ed | UNKNOWN | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | ["n, m = map(int, input().split())\np, d = [0] * (n + 2), [0] * (n + 2)\nfor i in range(m):\n l, r, x = map(int, input().split())\n while l < x:\n if d[l]:\n k = d[l]\n d[l] = x - l\n l += k\n else:\n d[l], p[l] = x - l, x\n l += 1\n l += 1\n... | {
"inputs": [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n",
"2 1\n1 2 1\n",
"2 1\n1 2 2\n",
"3 1\n1 3 1\n",
"3 1\n1 3 2\n",
"3 1\n1 3 3\n",
"3 2\n1 2 1\n1 3 3\n",
"3 2\n1 2 2\n1 3 2\n",
"3 2\n2 3 3\n1 3 3\n",
"11 6\n1 2 2\n7 8 7\n3 4 4\n6 9 6\n5 10 10\n... | COMPETITION | PYTHON3 | CODEFORCES | 34,075 | |
3972e6aa15fc6e1b7b221d5738de7880 | UNKNOWN | Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a_1, a_2, ..., a_{n} of positive integers: Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates. The progra... | ["n = int(input())\nt = [0, 0] + list(map(int, input().split()))\na, b = [0] * (n + 1), [0] * (n + 1)\na[1] = b[1] = -1\n \ndef f(s, a, b, l):\n nonlocal t\n l.reverse()\n j, n = 0, len(l)\n while True:\n s += t[l[j]]\n a[l[j]] = s\n j += 1\n if j == n: return\n s += t[... | {"inputs": ["4\n2 4 1\n", "3\n1 2\n", "5\n2 2 1 3\n", "2\n1\n", "8\n7 6 2 6 2 6 6\n", "8\n4 5 3 2 3 3 3\n", "3\n1 1\n", "5\n3 2 4 2\n", "10\n6 7 5 3 1 5 2 4 6\n", "8\n6 311942309 3 1 3 2 2\n", "8\n2 3 1 2 2 3 3\n", "6\n2 1 2 2 3\n", "23\n20 1 3 3 13 11 9 7 5 3 1 7 2 4 6 8 10 12 14 16 12 5\n", "71\n28 11 39 275858941 64... | COMPETITION | PYTHON3 | CODEFORCES | 3,846 | |
dc08c83d60a5d46f6083a9b5cc436286 | UNKNOWN | We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekoland, each person has c_{i} coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it t... | ["import sys\n\nn, k = map(int, sys.stdin.readline().split())\nnums = list(map(int, sys.stdin.readline().split()))\ntotal = sum(nums)\navg = int(total / n)\n\ndef check1(nums, target, K):\n for x in nums:\n if K < 0:\n return False\n if x < target:\n K -= target - x\n return K ... | {
"inputs": [
"4 1\n1 1 4 2\n",
"3 1\n2 2 2\n",
"10 20\n6 4 7 10 4 5 5 3 7 10\n",
"30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2\n",
"2 0\n182 2\n",
"123 54564\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94 57 65 85 64 47 24 20 34 86 26 91 98 12 36 96 80 4 70 40 95 38 70 22 5... | COMPETITION | PYTHON3 | CODEFORCES | 9,746 | |
891f1695a785aa15e12eabec1bdf6ce3 | UNKNOWN | Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.
Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, ... | ["import sys\ndef calc(b0, b1, q):\n if q == 0:\n return b0 ^ b1\n if q == 1:\n return b0 | b1\n if q == 2:\n return b0 & b1\nn, m = list(map(int,sys.stdin.readline().split()))\narr1 = {}\nopt = ['XOR', 'OR', 'AND']\narr2 = []\nfor j in range(n):\n a, b = list(map(str,sys.stdin.readline... | {
"inputs": [
"3 3\na := 101\nb := 011\nc := ? XOR b\n",
"5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n",
"2 10\nb := 0100101101\na := ? XOR b\n",
"1 10\na := 0110110011\n",
"1 6\na := ? OR ?\n",
"13 6\na := 111010\nb := 100100\nc := 001110\nd := b AND b\ne := c AND ?\nf :=... | COMPETITION | PYTHON3 | CODEFORCES | 2,792 | |
e0088b6b295ba16b97ed8cbbdff8fbf5 | UNKNOWN | Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.
Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the re... | ["\"\"\"\nCodeforces Contest 260 Div 1 Problem B\n\nAuthor : chaotic_iak\nLanguage: Python 3.3.4\n\"\"\"\n\ndef main():\n n,k = read()\n s = set()\n for i in range(n): s.add(read(0))\n s = list(s)\n s.sort()\n s = treeify(s)\n res = solve(s)\n if res == 0: # neither: second player win\n ... | {
"inputs": [
"2 3\na\nb\n",
"3 1\na\nb\nc\n",
"1 2\nab\n",
"5 6\nabas\ndsfdf\nabacaba\ndartsidius\nkolobok\n",
"4 2\naaaa\nbbbb\nccccc\ndumbavumba\n",
"3 8\nso\nbad\ntest\n",
"5 2\nwelcome\nto\nthe\nmatrix\nneo\n",
"6 4\ndog\ncat\ncow\nhot\nice\nlol\n",
"4 8\nla\na\nz\nka\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 8,439 | |
54af54c80fd4fb5feca7e54b8e68077a | UNKNOWN | Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is e... | ["from heapq import heappush,heappop,heapify\nn,k=map(int,input().split())\n*l,=map(int,input().split())\nq=[(-l[i],i)for i in range(k)];heapify(q)\na=[0]*n\ns=0\nfor i in range(k,n):\n heappush(q,(-l[i],i))\n x,j=heappop(q)\n s-=x*(i-j)\n a[j]=i+1\nfor i in range(n,n+k):\n x,j=heappop(q)\n s-=x*(i-j)... | {
"inputs": [
"5 2\n4 2 1 10 2\n",
"3 2\n3 1 2\n",
"5 5\n5 5 9 100 3\n",
"1 1\n1\n",
"1 1\n10000000\n",
"6 4\n85666 52319 21890 51912 90704 10358\n",
"10 5\n66220 81797 38439 54881 86879 94346 8802 59094 57095 41949\n",
"8 1\n3669 11274 87693 33658 58862 78334 42958 30572\n",
"2 2\... | COMPETITION | PYTHON3 | CODEFORCES | 1,697 | |
cf639b3344b822194ddf02cd564963db | UNKNOWN | Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original... | ["n, m = list(map(int, input().split()))\nused = [1] * 2 * n\nfor i in range(m):\n\tx, y = list(map(int, input().split()))\n\tused[x - 1] = used[n + y - 1] = 0\n\t\nif n % 2 and used[n // 2]:\n\tused[n // 2 + n] = 0\nres = sum(used)\nfor i in [0, n - 1, n, 2 * n - 1]:\n\tres -= used[i]\nprint(res)\n\n", "import sys\nn,... | {
"inputs": [
"3 1\n2 2\n",
"3 0\n",
"4 3\n3 1\n3 2\n3 3\n",
"2 1\n1 1\n",
"2 3\n1 2\n2 1\n2 2\n",
"5 1\n3 2\n",
"5 1\n2 3\n",
"1000 0\n",
"999 0\n",
"5 5\n3 2\n5 4\n3 3\n2 3\n1 2\n",
"5 5\n3 2\n1 4\n5 1\n4 5\n3 1\n",
"5 5\n2 2\n5 3\n2 3\n5 1\n4 4\n",
"6 5\n2 6\n6 5... | COMPETITION | PYTHON3 | CODEFORCES | 7,430 | |
3df0adfc1eef8be8f47a88179e1111c2 | UNKNOWN | $n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i \leq n$ the minimal number of sweets, which $i$-th boy presented to some g... | ["n,m=map(int,input().split())\nb=list(map(int,input().split()))\ng=list(map(int,input().split()))\nif max(b)>min(g):\n print(-1)\nelse:\n maxi=0\n maxi2=0\n for guy in b:\n if guy>maxi:\n maxi2,maxi=maxi,guy\n elif guy>maxi2:\n maxi2=guy\n sumi=m*sum(b)+sum(g)-m*maxi+... | {
"inputs": [
"3 2\n1 2 1\n3 4\n",
"2 2\n0 1\n1 0\n",
"2 3\n1 0\n1 1 2\n",
"2 2\n0 0\n100000000 100000000\n",
"2 2\n14419485 34715515\n45193875 34715515\n",
"2 2\n4114169 4536507\n58439428 4536507\n",
"2 2\n89164828 36174769\n90570286 89164829\n",
"2 2\n23720786 67248252\n89244428 6724... | COMPETITION | PYTHON3 | CODEFORCES | 11,108 | |
9f52a96703e625bd7b9a90a08321b52f | UNKNOWN | Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color c_{i}.
Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some ve... | ["def main():\n n = int(input())\n edges = []\n for _ in range(n - 1):\n u, v = list(map(int, input().split()))\n u -= 1\n v -= 1\n edges.append((u, v))\n\n colors = list(map(int, input().split()))\n suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]]\n\n if le... | {
"inputs": [
"4\n1 2\n2 3\n3 4\n1 2 1 1\n",
"3\n1 2\n2 3\n1 2 3\n",
"4\n1 2\n2 3\n3 4\n1 2 1 2\n",
"3\n2 1\n2 3\n1 2 3\n",
"4\n1 2\n2 4\n4 3\n1 1 3 2\n",
"2\n1 2\n1 1\n",
"10\n5 7\n4 5\n10 2\n3 6\n1 2\n3 4\n8 5\n4 9\n2 3\n15 15 15 15 5 15 26 18 15 15\n",
"8\n1 2\n1 3\n3 5\n3 6\n1 4\n4... | COMPETITION | PYTHON3 | CODEFORCES | 13,270 | |
730006d0f77caaaa303612f8f6a5e0b5 | UNKNOWN | Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "d_{i} → t_{i}", that means "replace all digits d_{i} in string s with substrings equal to t_{i}". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query ... | ["MOD = 10**9+7\n\ns = input()\nn = int(input())\nqs = [['',s]]+[input().split('->') for i in range(n)]\n\nds = {}\nfor i in range(10):\n ds[str(i)] = (10,i)\n\nfor i in range(n,-1,-1):\n out = 0\n mul = 1\n for d in qs[i][1]:\n out = (out * ds[d][0] + ds[d][1]) % MOD\n mul = (mul * ds[d][0]) ... | {
"inputs": [
"123123\n1\n2->00\n",
"123123\n1\n3->\n",
"222\n2\n2->0\n0->7\n",
"1000000008\n0\n",
"100\n5\n1->301\n0->013\n1->013\n0->103\n0->103\n",
"21222\n10\n1->\n2->1\n1->1\n1->1\n1->1\n1->22\n2->2\n2->1\n1->21\n1->\n",
"21122\n10\n1->\n2->12\n1->\n2->21\n2->\n1->21\n1->\n2->12\n2->\... | COMPETITION | PYTHON3 | CODEFORCES | 4,519 | |
47b07f3a5db7e906888470befbdbfc83 | UNKNOWN | 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... | ["# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\ntry :\n #raise ModuleNotFoundError\n import numpy\n def dprint(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n dprint('debug ... | {
"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\n001001000011000100101101101111100100011000100010011111001001000110011001... | COMPETITION | PYTHON3 | CODEFORCES | 11,108 | |
39e4405a30629e9c8ab9bea4f9e29a9a | UNKNOWN | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 10^9 + ... | ["\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\n# so the ending sequence is b...ba...a\n\n# find length of ending sequence\n\nextra=0\nneed=0\nfor ch in input().strip():\n if ch=='a':\n need=(need*2+1)%1000000007\n else:\n extra=(extra+need)%1000000007\n\nprint(extra)", "M... | {
"inputs": [
"ab\n",
"aab\n",
"aaaaabaabababaaaaaba\n",
"abaabaaabbabaabab\n",
"abbaa\n",
"abbaaabaabaaaaabbbbaababaaaaabaabbaaaaabbaabbaaaabbbabbbabb\n",
"aababbaaaabbaabbbbbbbbabbababbbaaabbaaabbabbba\n",
"aabbaababbabbbaabbaababaaaabbaaaabaaaaaababbaaaabaababbabbbb\n",
"aaabaaa... | COMPETITION | PYTHON3 | CODEFORCES | 6,267 | |
a86473960497f52ed4e404f28860ce37 | UNKNOWN | Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati... | ["import heapq\nn = int(input())\nd = list(map(int,input().split()))\npq = [-d[0]]\nheapq.heapify(pq)\nans = 0\nfor i in range(1,n):\n temp = i - d[i]\n heapq.heappush(pq,temp)\n if heapq.nsmallest(1,pq)[0] < temp:\n ans += temp - heapq.nsmallest(1,pq)[0]\n heapq.heappushpop(pq,temp)\nprint(ans)\... | {
"inputs": [
"7\n2 1 5 11 5 9 11\n",
"5\n5 4 3 2 1\n",
"2\n1 1000\n",
"2\n1000 1\n",
"5\n100 80 60 70 90\n",
"10\n10 16 17 11 1213 1216 1216 1209 3061 3062\n",
"20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158\n",
"1\n1\n",
"5\n1 1 1 2 3\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 4,548 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.