problem_id int64 0 4.75k | question stringlengths 146 5.9k | solutions stringlengths 181 1.12M | input_output stringlengths 236 35.4M | difficulty stringclasses 3
values | url stringlengths 47 54 | starter_code stringclasses 158
values | num_tests int64 16 16 |
|---|---|---|---|---|---|---|---|
1,605 | Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\operatorname{div}(x, b)}{\operatorname{mod}(x, b)} = k$, where k is some integer... | ["a,b=map(int,input().split())\nprint(((b-1)*a*b//2+(a+1)*a*b*b*(b-1)//4)%1000000007)", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n(a, b) = list(map(int, input().split()))\n\n# ans = a * a * (a - 1) * (a + 1) * b\n# ans //= 4\n# ans += a * (a - 1)\n\nans = a * (a + 1) * b * b * (b - 1)\nans //= 4\nans += a * b... | {"inputs": ["1 1\n", "3 4\n", "1 4\n", "2 10000000\n", "9999999 9999999\n", "10000 10000000\n", "3505377 9167664\n", "861392 6200826\n", "9832578 8599931\n", "9253578 1799941\n", "7835126 9883365\n", "6351267 7966789\n", "1 10000000\n", "1001 1500126\n", "191919 123123\n", "6340794 6874449\n"], "outputs": ["0\n", "162\... | interview | https://codeforces.com/problemset/problem/476/C | 16 | |
1,606 | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve... | ["l,r = map(int, input().split(\" \"))\nif l == r:\n print (l)\nelse:\n print (2)", "a, b = list(map(int, input().split()))\nif a != b:\n print(2)\nelse:\n print(a)\n", "l,r=map(int,input().split())\nif abs(l-r)>0:\n print(2)\nelse:\n print(l)", "L, R = [int(i) for i in input().split()]\n\nif L == R:... | {"inputs": ["19 29\n", "30 37\n", "760632746 850720703\n", "820844234 892579936\n", "252662256 252662260\n", "273072892 273072894\n", "6 8\n", "3 3\n", "5 100\n", "3 18\n", "5 10\n", "242 244\n", "5 15\n", "2 3\n", "29 29\n", "141650963 141650963\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n", ... | interview | https://codeforces.com/problemset/problem/805/A | 16 | |
1,607 | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!). $8$ illustration by 猫屋 https://twitter.com/nekoyaliu ... | ["s=input()\nans = 0\nfor i in range(len(s)):\n if s[i] == 'A':\n ans += s[:i].count('Q') * s[i:].count('Q')\nprint(ans)", "from sys import stdin, stdout\nfrom random import randrange\n\ns = stdin.readline().strip()\nn = len(s)\nans = 0\n\nfor i in range(n):\n for j in range(i + 1, n):\n for z in range(j ... | {"inputs": ["IAQVAQZLQBQVQFTQQQADAQJA\n", "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA\n", "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA\n", "W\n", "RQAWNACASAAKAGAAAAQ\n", "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ\n", "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQR... | interview | https://codeforces.com/problemset/problem/894/A | 16 | |
1,616 | In this kata we want to convert a string into an integer. The strings simply represent the numbers in words.
Examples:
* "one" => 1
* "twenty" => 20
* "two hundred forty-six" => 246
* "seven hundred eighty-three thousand nine hundred and nineteen" => 783919
Additional Notes:
* The minimum number is "zero" (inclusiv... | ["words = {w: n for n, w in enumerate('zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'.split())}\nwords.update({w: 10 * n for n, w in enumerate('twenty thirty forty fifty sixty seventy eighty ninety hundred'.split(), 2)})\nthousands = {w... | {"fn_name": "parse_int", "inputs": [["three"], ["four"], ["twenty"], ["thirty-seven"], ["seventy-two"], ["ninety-four"], ["one hundred one"], ["seven hundred thirty-six"], ["two thousand"], ["ten thousand"], ["twenty-six thousand three hundred and fifty-nine"], ["thirty-five thousand"], ["six hundred sixty-six thousand... | interview | https://www.codewars.com/kata/525c7c5ab6aecef16e0001a5 |
def parse_int(string):
| 16 |
1,620 | This kata generalizes [Twice Linear](https://www.codewars.com/kata/5672682212c8ecf83e000050). You may want to attempt that kata first.
## Sequence
Consider an integer sequence `U(m)` defined as:
1. `m` is a given non-empty set of positive integers.
2. `U(m)[0] = 1`, the first number is always 1.
3. For each `x` in `... | ["from heapq import *\n\ndef n_linear(ms, n):\n lst = [1] * (n+1)\n q = [(1+v,v,1) for v in ms]\n heapify(q)\n for i in range(1,n+1):\n v,x,j = heappop(q)\n lst[i] = v\n heappush(q, (lst[j]*x+1, x, j+1) )\n while q[0][0]==lst[i]:\n v,x,j = heappop(q)\n he... | {"fn_name": "n_linear", "inputs": [[["2", "3"], "0"], [["2", "3"], "14"], [["2", "3"], "19"], [["2", "3"], "20"], [["2", "3"], "200"], [["2", "3"], "1000"], [["2", "3", "4", "5"], "100"], [["1", "3"], "999"], [["14", "10"], "56"], [["3", "5"], "351"], [["5", "9"], "246"], [["8", "7"], "738"], [["4", "9", "6", "7", "19"... | interview | https://www.codewars.com/kata/5aa417aa4a6b344e2200009d |
def n_linear(m,n):
| 16 |
1,633 | Create a function that takes a Number as its argument and returns a Chinese numeral string. You don't need to validate the input argument, it will always be a Number in the range `[-99999.999, 99999.999]`, rounded to 8 decimal places.
Simplified Chinese numerals have characters representing each number from 0 to 9 and... | ["import re\n\nNEG, DOT, _, *DIGS = \"\u8d1f\u70b9 \u96f6\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\"\nPOWS = \" \u5341 \u767e \u5343 \u4e07\".split(' ')\nNUMS = {str(i):c for i,c in enumerate(DIGS)}\nfor n in range(10): NUMS[str(n+10)] = POWS[1] + DIGS[n]*bool(n)\n\n\ndef to_chinese_numeral(n):\n ss = s... | {"fn_name": "to_chinese_numeral", "inputs": [["99"], ["99999"], ["-543"], ["-5432"], ["-54321"], [0.25], ["18"], ["24"], ["50"], ["111"], ["-14"], ["-18"], ["-110"], ["10000"], ["10306"], [99999.999]], "outputs": [["九十九"], ["九万九千九百九十九"], ["负五百四十三"], ["负五千四百三十二"], ["负五万四千三百二十一"], ["零点二五"], ["十八"], ["二十四"], ["五十"], ["一百一... | interview | https://www.codewars.com/kata/52608f5345d4a19bed000b31 |
def to_chinese_numeral(n):
| 16 |
1,649 | Automatons, or Finite State Machines (FSM), are extremely useful to programmers when it comes to software design. You will be given a simplistic version of an FSM to code for a basic TCP session.
The outcome of this exercise will be to return the correct state of the TCP FSM based on the array of events given.
------... | ["STATE_TO_COMMANDS = {\n 'CLOSED': {\n 'APP_PASSIVE_OPEN': 'LISTEN',\n 'APP_ACTIVE_OPEN': 'SYN_SENT'\n },\n 'LISTEN': {\n 'RCV_SYN': 'SYN_RCVD',\n 'APP_SEND': 'SYN_SENT',\n 'APP_CLOSE': 'CLOSED'\n },\n 'SYN_RCVD': {\n 'APP_CLOSE': 'FIN_WAIT_1',\n 'RCV_ACK': 'ESTABLISHED'\n },\n 'SYN_SENT': ... | {"fn_name": "traverse_TCP_states", "inputs": [[["APP_PASSIVE_OPEN", "RCV_SYN", "RCV_ACK", "APP_CLOSE"]], [["APP_PASSIVE_OPEN", "RCV_SYN", "RCV_ACK"]], [["APP_ACTIVE_OPEN", "APP_CLOSE"]], [["APP_ACTIVE_OPEN", "RCV_SYN", "APP_CLOSE", "RCV_FIN", "RCV_ACK"]], [["APP_ACTIVE_OPEN", "RCV_SYN", "APP_CLOSE", "RCV_FIN", "RCV_ACK... | interview | https://www.codewars.com/kata/54acc128329e634e9a000362 |
def traverse_TCP_states(events):
| 16 |
1,658 | The aim is to calculate `exponential(x)` (written `exp(x)` in most math libraries) as an irreducible fraction, the numerator of this fraction having a given number of digits.
We call this function `expand`, it takes two parameters, `x` of which we want to evaluate the exponential, `digits` which is the required number... | ["from fractions import Fraction\n\ndef expand(x, digit):\n step = 0\n fact = 1\n expo = Fraction(1)\n n = 10 ** len(str(x).split('.')[-1])\n x = Fraction(int(x * n), n)\n while expo.numerator < 10 ** (digit - 1):\n step += 1\n fact *= step\n expo += x ** step / fact\n return [... | {"fn_name": "expand", "inputs": [["1", "2"], ["1", "5"], ["1", "6"], ["10", "3"], ["10", "4"], ["10", "40"], ["10", "39"], ["10", "38"], [1.5, "10"], [1.6, "10"], [1.7, "10"], [1.7, "12"], [1.7, "15"], [1.8, "20"], [2.0, "20"], [1.95, "60"]], "outputs": [[["65", "24"]], [["109601", "40320"]], [["109601", "40320"]], [["... | interview | https://www.codewars.com/kata/54f5f22a00ecc4184c000034 |
def expand(x, digit):
| 16 |
1,664 | # 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"], ["f3", "f2"], ["e1", "b4"], ["a4", "a6"], ["f5", "f7"], ["h3", "d8"], ["b6", "d5"], ["g4", "b4"], ["e7", "e5"], ["c3", "c6"], ["b1", "a4"], ["h1", "f3"], ["g3", "c8"], ["g6", "e8"], ["f4", "g6"], ["a8", "e5"]], "outputs": [[["0", "29", "1", "29"]], [["6", "11", ... | interview | https://www.codewars.com/kata/5897f30d948beb78580000b2 |
def amazon_check_mate(king, amazon):
| 16 |
1,668 | Write a function that takes a positive integer and returns the next smaller positive integer containing the same digits.
For example:
```python
next_smaller(21) == 12
next_smaller(531) == 513
next_smaller(2071) == 2017
```
Return -1 (for `Haskell`: return `Nothing`, for `Rust`: return `None`), when there is no small... | ["def next_smaller(n):\n s = list(str(n))\n i = j = len(s) - 1\n while i > 0 and s[i - 1] <= s[i]: i -= 1\n if i <= 0: return -1\n while s[j] >= s[i - 1]: j -= 1\n s[i - 1], s[j] = s[j], s[i - 1]\n s[i:] = reversed(s[i:])\n if s[0] == '0': return -1\n return int(''.join(s))", "def next_smalle... | {"fn_name": "next_smaller", "inputs": [["907"], ["531"], ["441"], ["123456798"], ["351"], ["315"], ["153"], ["100"], ["2071"], ["1207"], ["414"], ["29009"], ["1234567908"], ["9999999999"], ["202233445566"], ["506789"]], "outputs": [["790"], ["513"], ["414"], ["123456789"], ["315"], ["153"], ["135"], ["-1"], ["2017"], [... | interview | https://www.codewars.com/kata/5659c6d896bc135c4c00021e |
def next_smaller(n):
| 16 |
2,000 | 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 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 3 2770628\n1 3 3912422\n", "3 3 2566490 5132980... | competition | https://codeforces.com/problemset/problem/1149/D | 16 | |
2,001 | 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", "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", "15000 1\n", "1048576 1\n", "1000000 1\n", "10001 1\n"], "outputs": ["6\n1 1 1 7 13 19 ", "3\n1 1 4 ", "3\n1 1 3 ", "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 2... | competition | https://codeforces.com/problemset/problem/960/C | 16 | |
2,002 | 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", "khjcoijiicdkdianmdolmadobdkcmgifdnffddnjehhbldlkjffknficdcmokfacioiegjed... | competition | https://codeforces.com/problemset/problem/930/B | 16 | |
2,003 | In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the... | ["from bisect import *\nfrom math import *\n\nn = int(input())\na, b, c, d = list(map(int,input().replace('/',' ').split()))\n\nalpha = atan2(c,d) - atan2(a,b)\ntan_alpha = tan(alpha)\n\nlis = []\n\nfor x,y in sorted((y/tan_alpha - x,y) for x,y in [ (x,y) for x,y in [(b*x + a*y,-a*x + b*y) for x, y in [list(map(int,inp... | {"inputs": ["15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4\n", "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 5\n4 5\n1 6\n6 6\n", "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 6\n4 5\n1 6\n6 6\n", "15\n1/4 2/1\n3 1\n6 2\n9 ... | competition | https://codeforces.com/problemset/problem/249/D | 16 | |
2,004 | 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", "1111111110\n", "10100101011110101\n", "111010010111\n", "11110111011100000000\n", "11110010010100001110110101110011110110100111101\n", "1001011111010010100111111\n", "1111111111\n", "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101\n"... | competition | https://codeforces.com/problemset/problem/258/A | 16 |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 11