Datasets:

Modalities:
Text
Formats:
parquet
ArXiv:
License:
Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
int64
0
5k
question
stringlengths
50
14k
solutions
stringlengths
12
1.21M
input_output
stringlengths
0
23.6M
difficulty
stringclasses
3 values
url
stringlengths
36
108
starter_code
stringlengths
0
1.4k
0
Polycarp has $n$ different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100". Polycarp wants to offer his set of $n$ binary words to play a game "words". In this game, players name words and each next word (starting from ...
["for _ in range(int(input())):\n n = int(input())\n mass = []\n zo = 0\n oz = 0\n zz = 0\n oo = 0\n ozs = []\n zos = []\n ozss = set()\n zoss = set()\n for j in range(n):\n k = input()\n mass.append(k)\n if k[0] == '0' and k[-1] == '1':\n zoss.add(k)\n ...
{ "inputs": [ "4\n4\n0001\n1000\n0011\n0111\n3\n010\n101\n0\n2\n00000\n00001\n4\n01\n001\n0001\n00001\n" ], "outputs": [ "1\n3 \n-1\n0\n\n2\n1 2 \n" ] }
interview
https://codeforces.com/problemset/problem/1259/D
1
Mikhail walks on a Cartesian plane. He starts at the point $(0, 0)$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $(0, 0)$, he can go to any of the following points in one move: $(1, 0)$; $(1, 1)$; $(0, 1)$; $(-1, 1)$; $(-1, 0)$; $(-1, -1)$; $(0, -...
["q=int(input())\n\nfor e in range(q):\n x,y,k=list(map(int,input().split()))\n x,y=abs(x),abs(y)\n x,y=max(x,y),min(x,y)\n \n if(x%2!=k%2):\n k-=1\n y-=1\n \n \n if(x>k):\n print(-1)\n continue\n if((x-y)%2):\n k-=1\n x-=1\n print(k)\n \n \n...
{ "inputs": [ "3\n2 2 3\n4 3 7\n10 1 9\n" ], "outputs": [ "1\n6\n-1\n" ] }
interview
https://codeforces.com/problemset/problem/1036/B
2
You are given three sequences: $a_1, a_2, \ldots, a_n$; $b_1, b_2, \ldots, b_n$; $c_1, c_2, \ldots, c_n$. For each $i$, $a_i \neq b_i$, $a_i \neq c_i$, $b_i \neq c_i$. Find a sequence $p_1, p_2, \ldots, p_n$, that satisfy the following conditions: $p_i \in \{a_i, b_i, c_i\}$ $p_i \neq p_{(i \mod n) + 1}$. In o...
["import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef...
{ "inputs": [ "5\n3\n1 1 1\n2 2 2\n3 3 3\n4\n1 2 1 2\n2 1 2 1\n3 4 3 4\n7\n1 3 3 1 1 1 1\n2 4 4 3 2 2 4\n4 2 2 2 4 4 2\n3\n1 2 1\n2 3 3\n3 1 2\n10\n1 1 1 2 2 2 3 3 3 1\n2 2 2 3 3 3 1 1 1 2\n3 3 3 1 1 1 2 2 2 3\n" ], "outputs": [ "1 2 3\n1 2 1 2\n1 3 4 1 2 1 4\n1 2 3\n1 2 1 2 3 2 3 1 3 2\n" ] }
interview
https://codeforces.com/problemset/problem/1408/A
3
You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $x$ and $y$ (the $x$-th barrel shouldn't be empty) and pour any possible ...
["def solve():\n n, k = map(int,input().split())\n lst = list(map(int,input().split()))\n lst.sort()\n ans = 0\n for i in range(n - k - 1, n):\n ans += lst[i]\n print(ans)\nfor i in range(int(input())):\n solve()", "t=int(input())\nfor i in range(t):\n n,k=[int(i) for i in input().split()...
{ "inputs": [ "2\n4 1\n5 5 5 5\n3 2\n0 0 0\n" ], "outputs": [ "10\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1430/B
4
You are given a permutation $p=[p_1, p_2, \ldots, p_n]$ of integers from $1$ to $n$. Let's call the number $m$ ($1 \le m \le n$) beautiful, if there exists two indices $l, r$ ($1 \le l \le r \le n$), such that the numbers $[p_l, p_{l+1}, \ldots, p_r]$ is a permutation of numbers $1, 2, \ldots, m$. For example, let $p ...
["for _ in range(int(input())):\n input()\n nums = [int(x) for x in input().split()]\n new_ar = list(zip(nums,[i for i in range(len(nums))]))\n new_ar.sort()\n \n maxx = new_ar[0][1]\n minn = new_ar[0][1]\n s=\"1\"\n for j in range(1,len(new_ar)):\n if(new_ar[j][1]>maxx):\n ...
{ "inputs": [ "3\n6\n4 5 1 3 2 6\n5\n5 3 1 2 4\n4\n1 4 3 2\n" ], "outputs": [ "101011\n11111\n1001\n" ] }
interview
https://codeforces.com/problemset/problem/1265/B
5
The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation. Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$. Now Dreamoon concatenates these two permutations into another sequ...
["def possible(a):\n ans = set()\n s = set()\n lmax = 0\n for i in range(len(a)):\n lmax = max(lmax, a[i])\n s.add(a[i])\n if lmax == i + 1 and len(s) == i + 1:\n ans.add(i + 1)\n return ans\n\n\nt = int(input())\nfor case_num in range(t):\n n = int(input())\n a = li...
{ "inputs": [ "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n" ], "outputs": [ "2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1330/B
6
Arthur owns a ski resort on a mountain. There are $n$ landing spots on the mountain numbered from $1$ to $n$ from the top to the foot of the mountain. The spots are connected with one-directional ski tracks. All tracks go towards the foot of the mountain, so there are no directed cycles formed by the tracks. There are ...
["import sys\ninput = sys.stdin.readline\nfor f in range(int(input())):\n n,m=list(map(int,input().split()))\n neig=[0]*n\n for i in range(n):\n neig[i]=[0]\n \n for i in range(m):\n a,b=list(map(int,input().split()))\n a-=1\n b-=1\n neig[a][0]+=1\n neig[a].appen...
{ "inputs": [ "2\n4 6\n1 2\n1 3\n2 3\n2 4\n3 4\n3 4\n7 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n" ], "outputs": [ "2\n3 4 \n4\n4 5 6 7 \n" ] }
interview
https://codeforces.com/problemset/problem/1368/E
7
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are $n$ voters, and two ways to convince each of them to vote for you. The first way to convince the $i$-th voter is to pay him $p_i$ ...
["import sys\ndef I():\n return sys.stdin.readline().rstrip()\n\nclass Heap:\n def __init__( self ):\n self.l = [ -1 ]\n self.n = 0\n def n( self ):\n return self.n\n def top( self ):\n return self.l[ 1 ]\n def ins( self, x ):\n self.l.append( x )\n n = len( self...
{ "inputs": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n" ], "outputs": [ "8\n0\n7\n" ] }
interview
https://codeforces.com/problemset/problem/1251/E2
8
You like playing chess tournaments online. In your last tournament you played $n$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $0$ points. When you win you get $1$ or $2$ points: if you have won also the previous game you get $2$ points, otherwise ...
["import sys\ninput = sys.stdin.readline\n\ndef main():\n n, k = map(int, input().split())\n string = input().strip()\n if \"W\" not in string:\n ans = min(n, k) * 2 - 1\n print(max(ans, 0))\n return\n \n L_s = []\n cnt = 0\n bef = string[0]\n ans = 0\n for s in strin...
{ "inputs": [ "8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n" ], "outputs": [ "7\n11\n6\n26\n46\n0\n1\n6\n" ] }
interview
https://codeforces.com/problemset/problem/1427/B
9
Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less than one) of consecutive equal characters in $s$ and delete them. For example...
["for _ in range(int(input())):\n s = input()\n p = [i for i in s.split(\"0\") if i!=\"\"]\n p.sort(reverse=True)\n ans = 0\n for i in range(0,len(p),2):\n ans+=len(p[i])\n print(ans)\n\n", "for _ in range(int(input())):\n s=[len(i)for i in input().split('0')]\n s.sort()\n print(sum(s[...
{ "inputs": [ "5\n01111001\n0000\n111111\n101010101\n011011110111\n" ], "outputs": [ "4\n0\n6\n3\n6\n" ] }
interview
https://codeforces.com/problemset/problem/1398/B
10
Given a permutation $p$ of length $n$, find its subsequence $s_1$, $s_2$, $\ldots$, $s_k$ of length at least $2$ such that: $|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$ is as big as possible over all subsequences of $p$ with length at least $2$. Among all such subsequences, choose the one whose length, $k$, is as small...
["for _ in range(int(input())):\n # n, x = map(int, input().split())\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [arr[0]]\n for i in range(1, n - 1):\n if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:\n ans.append(arr[i])\n elif arr[i - 1] > arr[i] and arr[i...
{ "inputs": [ "2\n3\n3 2 1\n4\n1 3 4 2\n" ], "outputs": [ "2\n3 1 \n3\n1 4 2 \n" ] }
interview
https://codeforces.com/problemset/problem/1364/B
11
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
["n = int(input())\n\ndef area(width, height) :\n return (width+1) * (height+1)\n\ndef calcul(s1, c, s2) :\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n for k in range(len(s1)) :\n if s1[k] == \"W\" :\n y += 1\n if s1[k] == \"S\" :\n y -= 1\n if s1[k] == \"...
{ "inputs": [ "3\nDSAWWAW\nD\nWA\n" ], "outputs": [ "8\n2\n4\n" ] }
interview
https://codeforces.com/problemset/problem/1202/C
12
Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem: There are two arrays of integers $a$ and $b$ of length $n$. It turned out that array $a$ contains only elements from the set $\{-1, 0, 1\}$. Anton can perform the following sequence of operations any nu...
["from math import *\n\nmod = 1000000007\n\nfor zz in range(int(input())):\n n = int(input())\n a = [ int(i) for i in input().split()]\n b = [int(i) for i in input().split()]\n ha = True\n hp = False\n hm = False\n for i in range(n):\n if b[i] != a[i]:\n if b[i] > a[i]:\n ...
{ "inputs": [ "5\n3\n1 -1 0\n1 1 -2\n3\n0 1 1\n0 2 2\n2\n1 0\n1 41\n2\n-1 0\n-1 -41\n5\n0 1 -1 1 -1\n1 1 -1 1 -1\n" ], "outputs": [ "YES\nNO\nYES\nYES\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1333/B
13
Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary because of the climate. The climate in your region is periodical: there ar...
["for i in range(int(input())):\n n,g,b=map(int,input().split())\n nn=(n+1)//2\n print(max(nn+(nn-1)//g*b,n))", "for _ in range(int(input())):\n n, g, b = list(map(int, input().split()))\n half = (n - 1) // 2 + 1\n\n ans = (g + b) * (half // g) - b # + (half % g)\n if half % g != 0:\n ans +...
{ "inputs": [ "3\n5 1 1\n8 10 10\n1000000 1 1000000\n" ], "outputs": [ "5\n8\n499999500000\n" ] }
interview
https://codeforces.com/problemset/problem/1303/B
End of preview. Expand in Data Studio

NOTE

This is the same dataset as the original APPS dataset but the original repo does not work with datasets >= 4.0 as it uses a dataset script. There's an open PR to move to parquet but it has been open for over a year, and it seems unlikely that it will be merged. As a result, this repository exists under the same MIT license to work with new dataset versions. All credit should go to the original authors of the dataset (and the README below is copied from the original repo).

APPS Dataset

Dataset Description

APPS is a benchmark for code generation with 10000 problems. It can be used to evaluate the ability of language models to generate code from natural language specifications. You can also find APPS metric in the hub here codeparrot/apps_metric.

Languages

The dataset contains questions in English and code solutions in Python.

Dataset Structure

from datasets import load_dataset
load_dataset("codeparrot/apps")

DatasetDict({
    train: Dataset({
        features: ['problem_id', 'question', 'solutions', 'input_output', 'difficulty', 'url', 'starter_code'],
        num_rows: 5000
    })
    test: Dataset({
        features: ['problem_id', 'question', 'solutions', 'input_output', 'difficulty', 'url', 'starter_code'],
        num_rows: 5000
    })
})

How to use it

You can load and iterate through the dataset with the following two lines of code for the train split:

from datasets import load_dataset
import json

ds = load_dataset("codeparrot/apps", split="train")
sample = next(iter(ds))
# non-empty solutions and input_output features can be parsed from text format this way:
sample["solutions"] = json.loads(sample["solutions"])
sample["input_output"] = json.loads(sample["input_output"])
print(sample)

#OUTPUT:
{
 'problem_id': 0,
 'question': 'Polycarp has $n$ different binary words. A word called binary if it contains only characters \'0\' and \'1\'. For example...',
 'solutions': ["for _ in range(int(input())):\n    n = int(input())\n    mass = []\n    zo = 0\n    oz = 0\n    zz = 0\n    oo = 0\n...",...],
 'input_output': {'inputs': ['4\n4\n0001\n1000\n0011\n0111\n3\n010\n101\n0\n2\n00000\n00001\n4\n01\n001\n0001\n00001\n'], 
                  'outputs': ['1\n3 \n-1\n0\n\n2\n1 2 \n']},
 'difficulty': 'interview',
 'url': 'https://codeforces.com/problemset/problem/1259/D',
 'starter_code': ''}
}

Each sample consists of a programming problem formulation in English, some ground truth Python solutions, test cases that are defined by their inputs and outputs and function name if provided, as well as some metadata regarding the difficulty level of the problem and its source.

If a sample has non empty input_output feature, you can read it as a dictionary with keys inputs and outputs and fn_name if it exists, and similarily you can parse the solutions into a list of solutions as shown in the code above.

You can also filter the dataset for the difficulty level: Introductory, Interview and Competition. Just pass the list of difficulties as a list. E.g. if you want the most challenging problems, you need to select the competition level:

ds = load_dataset("codeparrot/apps", split="train", difficulties=["competition"])
print(next(iter(ds))["question"])

#OUTPUT:
"""\
Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by
...

For each settlement $p = 1, 2, \dots, n$, can you tell what is the minimum time required to travel between the king's residence and the parliament house (located in settlement $p$) after some roads are abandoned?

-----Input-----

The first line of the input contains four integers $n$, $m$, $a$ and $b$ 
...

-----Output-----

Output a single line containing $n$ integers
...

-----Examples-----
Input
5 5 20 25
1 2 25
...

Output
0 25 60 40 20
...

Data Fields

Field Type Description
problem_id int problem id
question string problem description
solutions string some python solutions
input_output string Json string with "inputs" and "outputs" of the test cases, might also include "fn_name" the name of the function
difficulty string difficulty level of the problem
url string url of the source of the problem
starter_code string starter code to include in prompts

we mention that only few samples have fn_name and starter_code specified

Data Splits

The dataset contains a train and test splits with 5000 samples each.

Dataset Statistics

  • 10000 coding problems
  • 131777 test cases
  • all problems have a least one test case except 195 samples in the train split
  • for tests split, the average number of test cases is 21.2
  • average length of a problem is 293.2 words
  • all files have ground-truth solutions except 1235 samples in the test split

Dataset Creation

To create the APPS dataset, the authors manually curated problems from open-access sites where programmers share problems with each other, including Codewars, AtCoder, Kattis, and Codeforces. For more details please refer to the original paper.

Considerations for Using the Data

In AlphaCode the authors found that this dataset can generate many false positives during evaluation, where incorrect submissions are marked as correct due to lack of test coverage.

Citation Information

@article{hendrycksapps2021,
  title={Measuring Coding Challenge Competence With APPS},
  author={Dan Hendrycks and Steven Basart and Saurav Kadavath and Mantas Mazeika and Akul Arora and Ethan Guo and Collin Burns and Samir Puranik and Horace He and Dawn Song and Jacob Steinhardt},
  journal={NeurIPS},
  year={2021}
}
Downloads last month
11

Papers for metr-evals/apps