Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
int64
80
5k
question
stringlengths
170
10.1k
solutions
stringlengths
0
675k
input_output
stringlengths
0
33.5k
difficulty
stringclasses
3 values
url
stringlengths
38
68
starter_code
stringlengths
0
315
80
While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute $1 + 3$ using the calculator, he gets $2$ instead of $4$. But when he tries computing $1 + 4$, he gets the correct answer, $5$. Puzzled by this mystery, he opened up his ...
["def solve(L, R):\n res = 0\n for i in range(32):\n for j in range(32):\n l = (L >> i) << i\n r = (R >> j) << j\n #print(l, r)\n if l>>i&1==0 or r>>j&1==0:\n continue\n l -= 1<<i\n r -= 1<<j\n if l & r:\n ...
{ "inputs": [ "3\n1 4\n323 323\n1 1000000\n" ], "outputs": [ "8\n0\n3439863766\n" ] }
interview
https://codeforces.com/problemset/problem/1245/F
756
Farmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum of potatoes he harvests from the three fields is a prime number (http://en...
["# cook your dish here\nimport math\ntry:\n def prime(n):\n for i in range(2, int(math.sqrt(n)) + 1):\n if n % i == 0:\n return False\n return True\n \n for t in range(int(input())):\n x, y = list(map(int, input().split()))\n s = x + y \n i = s\n while(1):\n if prime(s + 1):\n ans = s + 1\n break...
{"inputs": [["2", "1 3", "4 3"]], "outputs": [["1", "4"]]}
interview
https://www.codechef.com/problems/POTATOES
849
We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguous) of the given array with the maximum possible GCD (Greatest Common Divis...
["n=eval(input())\na=list(map(int,input().split()))\nc=m=0\nmaxi=max(a)\nfor i in range(n):\n if a[i]==maxi:\n c+=1\n m=max(c,m)\n else:\n c=0\nprint(m) ", "from fractions import gcd as G\nn=eval(input())\nflag=1\narr=list(map(int,input().split()))\na=max(arr)\nbest = 0\nI_I = 0\nwhile I_I<n:\n if arr[I_I]==a:\n k=...
{"inputs": [["4", "2 4 8 3"]], "outputs": [["1"]]}
interview
https://www.codechef.com/BYTE2016/problems/BYTES11
1,215
Two friends David and Rojer were preparing for their weekly class-test. The are preparing for the math test, but because of continuously adding big integers and solving equations they got exhausted. They decided to take break and play a game. They play a game which will help them in both(for having fun and will also he...
["def isSolvable( W, R):\r\n LW, LR, F, ML, AW, V, LMap = len(W), len(R), set([w[0] for w in W+[R]]), max(map(len, W+[R])), W+[R], set(), {}\r\n if LR < ML: return False\r\n def dfs(d,i,c):\r\n if d == ML: return c == 0\r\n if i == len(W) + 1:\r\n s = sum(LMap[w...
{"inputs": [["3", "THIS", "IS", "TOO", "FUNNY"]], "outputs": [["true"]]}
interview
https://www.codechef.com/CHLG2020/problems/MATH88
1,232
AND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if at least one input is 1, otherwise the output is 0. You are given a digita...
["# cook your dish here\nclass node:\n\tdef __init__(self,a,b=0,c=0):\n\t\tself.val=a\n\t\tself.a=b\n\t\tself.b=c\n\narr=[]\n\ndef finder(node,val):\n\tif(arr[node].val==0):\n\t\treturn val\n\telse:\n\t\ta=finder(arr[node].a,val)\n\t\tb=finder(arr[node].b,val)\n\t\tif(arr[node].val==1):\n\t\t\treturn a+b-a*b\n\t\telse:...
{"inputs": [["4", "", "1", "0", "", "3", "0", "0", "1 1 2", "", "3", "0", "0", "2 1 2", "", "5", "0", "0", "0", "2 1 2", "1 3 4", "", ""]], "outputs": [["0.50000", "0.29289", "0.70711", "0.40303"]]}
interview
https://www.codechef.com/problems/CIRCUITS
1,436
Harrenhal is the largest castle in the Seven Kingdoms and is the seat of House Whent in the Riverlands, on the north shore of the Gods Eye lake. Since the War of Conquest, however, it has become a dark and ruinous place. (c) A Wiki of Ice and Fire Now Harrenhal is too dangerous since it's a nice place for bandits to h...
["# cook your dish here\nfor _ in range(int(input())):\n g=input()\n h=g[::-1]\n if h==g :\n print(1)\n else:\n print(2)\n ", "# cook your dish here\nfor _ in range(int(input())):\n string = input()\n if string == string[::-1]:\n print('1')\n else:\n print('2')\n "...
{"inputs": [["1", "abbabaab", "", ""]], "outputs": [["2"]]}
interview
https://www.codechef.com/problems/HHAL
1,603
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[...
["# Bartek Kostka\n# You are not prepared!\n\n#include \"bits/stdc++.h\"\n\nn = int(input())\nW = {}\nfor i in range(n):\n adr = input()\n adr = adr.split(\"/\")\n if adr[-1] == '':\n adr[-1] = '?'\n domena = \"/\".join(adr[:3])\n adres = \"/\".join(adr[3:])\n #print(domena, adres)\n if dom...
{ "inputs": [ "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a...
interview
https://codeforces.com/problemset/problem/644/C
1,604
You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, while moving down takes you to the cell $(x + 1, y)$. Some cells of the la...
["def getSum(dp, pos, s, e, type_):\n if e < s:\n return 0\n \n if type_=='D':\n if e==m-1:\n return dp[pos][s]\n return dp[pos][s]-dp[pos][e+1]\n else:\n if e==n-1:\n return dp[s][pos]\n return dp[s][pos]-dp[e+1][pos]\n\nmod = 10**9+7\nn, m =...
{ "inputs": [ "1 1\n.\n", "2 3\n...\n..R\n", "4 4\n...R\n.RR.\n.RR.\nR...\n", "1 3\n.R.\n", "2 2\n.R\nR.\n", "10 10\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n" ], "outputs": [ "1\n", "0\n", "4\n", ...
interview
https://codeforces.com/problemset/problem/1225/E
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", "2 2\n", "4 1\n", "4 2\n", "4 3\n", "4 4\n", "3 4\n", "2 4\n", "1 4\n", "1000 1000\n", "10000000 10000000\n", "10000000 9999999\n", "2 10000000\n", "10000000 2\n", "9999999 2\n", "9999999 9999999\n", "10000000 10000\n", "10...
interview
https://codeforces.com/problemset/problem/476/C
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", "3 6\n", "39 91\n", "76 134\n", "93 95\n", "17 35\n", "94 95\n", "51 52\n", "47 52\n", "38 98\n", "30 37\n", "56 92\n", "900000000 1000000000\n", "37622224 162971117\n", "760632746 850720703\n", "908580370 968054552\n", "9515...
interview
https://codeforces.com/problemset/problem/805/A
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": [ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n", "QA\n", "IAQVAQZLQBQVQFTQQQADAQJA\n", "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ\n", "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ\n", "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQ...
interview
https://codeforces.com/problemset/problem/894/A
1,611
# 'Magic' recursion call depth number This Kata was designed as a Fork to the one from donaldsebleung Roboscript series with a reference to: https://www.codewars.com/collections/roboscript It is not more than an extension of Roboscript infinite "single-" mutual recursion handling to a "multiple-" case. One can supp...
["from collections import defaultdict\nfrom itertools import chain\nimport re\n\nPARSE = re.compile(r'[pP]\\d+|q')\n\ndef magic_call_depth_number(prog):\n \n def parse(it, p=''):\n for m in it:\n if m[0].startswith('p'): parse(it, m[0])\n elif m[0]=='q': return\n e...
{"fn_name": "magic_call_depth_number", "inputs": [["p0F2LF2RqP0"], ["p1P2P3qp2P1qp3P1qP3"], ["p1P2qp2P3qP4p3P4qp4P1q"], ["p1P2P4qp2P3qp3P4qP1p4P1q"], ["p1P2P3qP2P1p2P3qp3P4qp4P1q"], ["p1P2qp2P3qp3P4qP6p4P1qp5P7qp6P5qp7P6qP1"], ["P1P2P7p1P2qp2P3qp3P4qp4P1qp5P7qp6P5qp7P5q"], ["P2P7P6p1P2qp2P3qp3P4qp4P1qp5P8qp6P5qp7P5qp8P...
interview
https://www.codewars.com/kata/5c1b23aa34fb628f2e000043
def magic_call_depth_number(pattern):
1,614
# Connect Four Take a look at wiki description of Connect Four game: [Wiki Connect Four](https://en.wikipedia.org/wiki/Connect_Four) The grid is 6 row by 7 columns, those being named from A to G. You will receive a list of strings showing the order of the pieces which dropped in columns: ```python pieces_positio...
["COLUMNS, ROWS = 'ABCDEFG', range(6)\nLINES = [{(COLUMNS[i+k], ROWS[j]) for k in range(4)}\n for i in range(len(COLUMNS) - 3) for j in range(len(ROWS))] \\\n + [{(COLUMNS[i], ROWS[j+k]) for k in range(4)}\n for i in range(len(COLUMNS)) for j in range(len(ROWS) - 3)] \\\n + [{(COLUMNS[...
{"fn_name": "who_is_winner", "inputs": [[["C_Yellow", "E_Red", "G_Yellow", "B_Red", "D_Yellow", "B_Red", "B_Yellow", "G_Red", "C_Yellow", "C_Red", "D_Yellow", "F_Red", "E_Yellow", "A_Red", "A_Yellow", "G_Red", "A_Yellow", "F_Red", "F_Yellow", "D_Red", "B_Yellow", "E_Red", "D_Yellow", "A_Red", "G_Yellow", "D_Red", "D_Ye...
interview
https://www.codewars.com/kata/56882731514ec3ec3d000009
def who_is_winner(pieces_position_list):
1,615
### Lyrics... Pyramids are amazing! Both in architectural and mathematical sense. If you have a computer, you can mess with pyramids even if you are not in Egypt at the time. For example, let's consider the following problem. Imagine that you have a pyramid built of numbers, like this one here: ``` /3/ \7\ 4 2...
["def longest_slide_down(p):\n res = p.pop()\n while p:\n tmp = p.pop()\n res = [tmp[i] + max(res[i],res[i+1]) for i in range(len(tmp))] \n return res.pop()", "def longest_slide_down(pyr):\n for row in range(len(pyr)-1, 0, -1):\n for col in range(0, row):\n pyr[row-1][col] +...
{"fn_name": "longest_slide_down", "inputs": [[[[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]], [[[75], [95, 64], [17, 47, 82], [18, 35, 87, 10], [20, 4, 82, 47, 65], [19, 1, 23, 75, 3, 34], [88, 2, 77, 73, 7, 63, 67], [99, 65, 4, 28, 6, 16, 70, 92], [41, 41, 26, 56, 83, 40, 80, 70, 33], [41, 48, 72, 33, 47, 32, 37, 16, 94, 29]...
interview
https://www.codewars.com/kata/551f23362ff852e2ab000037
def longest_slide_down(pyramid):
1,617
I started this as a joke among friends, telling that converting numbers to other integer bases is for n00bs, while an actual coder at least converts numbers to more complex bases like [pi (or π or however you wish to spell it in your language)](http://en.wikipedia.org/wiki/Pi), so they dared me proving I was better. A...
["from math import *\n\nDIGS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\ndef converter(n, decimals=0, base=pi):\n lst,n = ['-'*(n<0)], abs(n)\n pMax = max(0, n and int(log(n,base)))\n \n for p in reversed(range(-decimals,pMax+1)):\n if p==-1: lst.append('.')\n p = base**p\n d,n = n/p...
{"fn_name": "converter", "inputs": [[13], [10], [13, 3], [13, 0, 8], [10, 0, 16], [10000, 4, 13], [7, 0, 19], [13.5, 4, 16], [10.81, 0, 16], [1, 2, 2], [-10, 0, 23], [0, 4, 26], [-15.5, 2, 23], [13, 0, 10], [5.5, 1, 10]], "outputs": [["103"], ["100"], ["103.010"], ["15"], ["A"], ["4723.0000"], ["7"], ["D.8000"], ["A"],...
interview
https://www.codewars.com/kata/5509609d1dbf20a324000714
def converter(n, decimals=0, base=pi):
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], [[3, 2, 5], 0], [[2, 3], 1], [[2, 3], 2], [[2, 3], 3], [[2, 3], 4], [[2, 3], 5], [[2, 3], 6], [[2, 3], 7], [[2, 3], 8], [[2, 3], 9], [[2, 3], 10], [[2, 3], 11], [[2, 3], 12], [[2, 3], 13], [[2, 3], 14], [[2, 3], 15], [[2, 3], 16], [[2, 3], 17], [[2, 3], 18], [[2, 3], 19],...
interview
https://www.codewars.com/kata/5aa417aa4a6b344e2200009d
def n_linear(m,n):
1,622
# Ten-Pin Bowling In the game of ten-pin bowling, a player rolls a bowling ball down a lane to knock over pins. There are ten pins set at the end of the bowling lane. Each player has 10 frames to roll a bowling ball down a lane and knock over as many pins as possible. The first nine frames are ended after two rolls or...
["def bowling_score(frames):\n rolls = list(frames.replace(' ',''))\n for i, hit in enumerate(rolls):\n if hit == 'X':\n rolls[i] = 10\n elif hit == '/':\n rolls[i] = 10 - rolls[i - 1]\n else:\n rolls[i] = int(hit)\n score = 0\n for i in range(10):\n ...
{"fn_name": "bowling_score", "inputs": [["11 11 11 11 11 11 11 11 11 11"], ["X X X X X X X X X XXX"], ["00 5/ 4/ 53 33 22 4/ 5/ 45 XXX"], ["5/ 4/ 3/ 2/ 1/ 0/ X 9/ 4/ 8/8"], ["5/ 4/ 3/ 2/ 1/ 0/ X 9/ 4/ 7/2"], ["X X 9/ 80 X X 90 8/ 7/ 44"], ["6/ 5/ 6/ 2/ 3/ 0/ 1/ 8/ 3/ 6/5"], ["00 00 00 00 00 00 00 00 00 0/X"], ["00 00 0...
interview
https://www.codewars.com/kata/5531abe4855bcc8d1f00004c
def bowling_score(frames):
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
4