problem_name stringlengths 11 77 | problem_id stringlengths 2 4 | solution_id stringlengths 5 9 | description stringlengths 445 3.59k | solution_code stringlengths 31 3.97k | dataclass_code stringlengths 3.26k 3.93k | space_complexity_inferred stringclasses 52
values | tests dict |
|---|---|---|---|---|---|---|---|
1331_G. Lingua Romana | 22 | 22_41 | 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.
... | import math
seq = []
for _ in range(11):
seq.append(int(input()))
for _ in range(11):
n = seq.pop()
aresult = math.sqrt(abs(n))
bresult = (n ** 3) * 5
result = aresult + bresult
if result <= 400:
print("f(%d) = %.2f" % (n, result))
else:
print("f(%d) = MAGNA NIMIS!" % n)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(1) | {
"public_tests": [
{
"input": "0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10\n",
"output": "f(10) = MAGNA NIMIS!\nf(-9) = -3642.00\nf(-8) = -2557.17\nf(-7) = -1712.35\nf(-6) = -1077.55\nf(-5) = -622.76\nf(-4) = -318.00\nf(-3) = -133.27\nf(-2) = -38.59\nf(1) = 6.00\nf(0) = 0.00\n"
}
],
"private_tes... |
1331_G. Lingua Romana | 22 | 22_43 | 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.
... | from math import sqrt
l = []
for i in range(11):
l.append(int(input()))
for v in reversed(l):
x = int(v)
ans = 5*x**3 + sqrt(abs(x))
if ans > 400:
print(str.format("f({}) = MAGNA NIMIS!", x))
else:
print(str.format("f({}) = {:.2f}", x, ans))
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(n) | {
"public_tests": [
{
"input": "0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10\n",
"output": "f(10) = MAGNA NIMIS!\nf(-9) = -3642.00\nf(-8) = -2557.17\nf(-7) = -1712.35\nf(-6) = -1077.55\nf(-5) = -622.76\nf(-4) = -318.00\nf(-3) = -133.27\nf(-2) = -38.59\nf(1) = 6.00\nf(0) = 0.00\n"
}
],
"private_tes... |
518_A. Vitaly and Strings | 559 | 559_232 | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English l... | # Tran Duy_Big O Blue
# +1 vao s, neu s = t => no such thing, s != t => print(s)
s = list(input())
t = list(input())
equal = True
for i in range(len(s)-1, -1, -1):
if s[i] == 'z':
s[i] = 'a'
else:
s[i] = chr(ord(s[i])+1)
break
for i in range(len(s)):
if s[i] != t[i]:
equal ... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(n+m) | {
"public_tests": [
{
"input": "aaa\nzzz\n",
"output": "aab"
},
{
"input": "a\nc\n",
"output": "b"
},
{
"input": "abcdefg\nabcdefh\n",
"output": "No such string"
}
],
"private_tests": [
{
"input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaa... |
518_A. Vitaly and Strings | 559 | 559_74 | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English l... | s = input()
t = input()
l = list(s)
for i in range(len(l)-1,-1,-1) :
if l[i] == 'z' : l[i] = 'a'
else :
l[i] = chr(ord(l[i]) + 1)
break
ss = ''.join(l)
if ss < t : print(ss)
else : print("No such string")
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(n) | {
"public_tests": [
{
"input": "aaa\nzzz\n",
"output": "aab"
},
{
"input": "a\nc\n",
"output": "b"
},
{
"input": "abcdefg\nabcdefh\n",
"output": "No such string"
}
],
"private_tests": [
{
"input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaa... |
1325_C. Ehab and Path-etic MEXs | 1774 | 1774_14 | You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
* Every label is an integer between 0 and n-2 inclusive.
* All the written labels are distinct.
* The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ... | n=int(input())
a=[ [] for i in range(n+1)]
b=[]
for _ in range(n-1):
u,v=map(int,input().split())
a[u].append(v)
a[v].append(u)
b.append((u,v))
c=0
for _ in range(1,n+1):
if len(a[_])==1:
c+=1
p=0
q=c
for i in b:
if len(a[i[0]])==1 or len(a[i[1]])==1:
print(p)
p+=1
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(1) | {
"public_tests": [
{
"input": "6\n1 2\n1 3\n2 4\n2 5\n5 6\n",
"output": "0\n3\n1\n2\n4\n"
},
{
"input": "3\n1 2\n1 3\n",
"output": "0\n1\n"
}
],
"private_tests": [
{
"input": "6\n1 2\n2 3\n3 4\n3 5\n3 6\n",
"output": "0\n4\n1\n2\n3\n"
},
{
"in... |
1325_C. Ehab and Path-etic MEXs | 1774 | 1774_183 | You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
* Every label is an integer between 0 and n-2 inclusive.
* All the written labels are distinct.
* The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ... | n = int(input())
l = []
for i in range(n-1):
s = (input()).split()
l.append((i,int(s[0])-1,int(s[1])-1))
g = []
for i in range(n):
g.append(0)
for x in l:
g[x[1]] = g[x[1]] + 1
g[x[2]] = g[x[2]] + 1
i = 0
r = -1
while (i<n):
if g[i]>2:
r = i
i = i+1
def h(j,r):
return (l[j][1]==r)|(l[j][2]==r)
if r ==... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(n) | {
"public_tests": [
{
"input": "6\n1 2\n1 3\n2 4\n2 5\n5 6\n",
"output": "0\n3\n1\n2\n4\n"
},
{
"input": "3\n1 2\n1 3\n",
"output": "0\n1\n"
}
],
"private_tests": [
{
"input": "6\n1 2\n2 3\n3 4\n3 5\n3 6\n",
"output": "0\n4\n1\n2\n3\n"
},
{
"in... |
318_B. Strings of Power | 2190 | 2190_102 | Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons... |
s = input()[::-1]
h = "heavy"[::-1]
m = "metal"[::-1]
sum = 0
cnt_b = 0
if h and m in s:
for i in range(len(s)):
if s[i: i + len(m)] == m:
cnt_b += 1
elif s[i: i + len(h)] == h:
sum += cnt_b
print(sum)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(n^2) | {
"public_tests": [
{
"input": "heavymetalisheavymetal\n",
"output": "3\n"
},
{
"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n",
"output": "3\n"
},
{
"input": "heavymetalismetal\n",
"output": "2\n"
}
],
"pr... |
318_B. Strings of Power | 2190 | 2190_132 | Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons... | s=input()
c=ans=0
for i in range(len(s)-4):
if s[i:i+5] == 'heavy':
c+=1
elif s[i:i+5] == 'metal':
ans+=c
print(ans)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(1) | {
"public_tests": [
{
"input": "heavymetalisheavymetal\n",
"output": "3\n"
},
{
"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n",
"output": "3\n"
},
{
"input": "heavymetalismetal\n",
"output": "2\n"
}
],
"pr... |
318_B. Strings of Power | 2190 | 2190_34 | Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.
Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons... | s = input()
dic = {}
l = len(s)
i = diclen = sub = 0
while 1:
if i<=l-5:
if s[i:i+5]=='heavy':
dic[i] = 0
diclen += 1
i += 5
elif s[i:i+5]=='metal':
sub += diclen
i += 5
else:
i += 1
else:
break
print(sub) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(n) | {
"public_tests": [
{
"input": "heavymetalisheavymetal\n",
"output": "3\n"
},
{
"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n",
"output": "3\n"
},
{
"input": "heavymetalismetal\n",
"output": "2\n"
}
],
"pr... |
1096_B. Substring Removal | 1426 | 1426_21 | You are given a string s of length n consisting only of lowercase Latin letters.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.
Your task is to calculate the number of ways to remove exactly one substring from thi... |
n = int(input())
s = input()
l = r = 2
while s[l-1] == s[0]: l += 1
while s[-r] == s[-1]: r += 1
if s[0]==s[-1]:print(l*r%998244353)
else:print(l+r-1)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | O(1) | {
"public_tests": [
{
"input": "7\naacdeee\n",
"output": "6\n"
},
{
"input": "2\naz\n",
"output": "3\n"
},
{
"input": "4\nabaa\n",
"output": "6\n"
}
],
"private_tests": [
{
"input": "23\nszsqqwareupmhkxlqwdtgbn\n",
"output": "3\n"
},
... |
ComplexityInspector(Bench) v1.0
Version 1.0, the version evaluated in the accompanying paper. ComplexityInspector is under active development; later versions will be released separately, and this version stays available unchanged.
ComplexityInspector(Bench) is a benchmark of whether language models can determine the time and space complexity of code and of problems. This repository holds its test sets and the results of the runs evaluated in the paper; the code (the prompts, the scorer and the run scripts) is in the code repository.
Tasks
| Task | The model sees | It answers | Ground truth |
|---|---|---|---|
| Code complexity prediction | a problem description and one human solution in Python | the time or space complexity of that solution | the solution's label |
| Problem complexity prediction | a problem description only | the best time or space complexity a solution can achieve | the best label among the problem's solutions |
The model answers with one big-O expression in a formal grammar, using the variables that the problem
description defines (e.g. O(n*log(n)+m)). The answer is parsed, rewritten into a normal form by explicit
rules, and compared with the ground truth. Variables are never renamed, so O(n) and O(m) are different
answers.
Test sets
The test sets come in three cleaning rounds. Round 2 is the main test set; round 3 is a cleaner but less representative subset, reported next to it; round 1 is kept as the record of the first cleaning.
| Round | Code, time | Code, space | Problem, time | Problem, space |
|---|---|---|---|---|
round_1 |
640 solutions of 311 problems | 636 solutions of 308 problems | 290 problems | 298 problems |
round_2 |
640 solutions of 311 problems | 636 solutions of 308 problems | 278 problems | 278 problems |
round_3 |
462 solutions of 273 problems | 374 solutions of 258 problems | 168 problems | 101 problems |
- Round 1 added to every description a "Variables for the complexity:" block stating what each letter means, and rewrote the labels in the grammar with those letters (round_1/README.md, which also describes the fields).
- Round 2 corrected 76 time and 80 space labels whose variables were bound wrongly; nothing else changed (round_2/README.md).
- Round 3 changes no row: it is a subset of round 2 that leaves out the problems whose statement ties one variable to another, and every solution whose label a full check did not judge correct (round_3/README.md).
Every row in the round-2 and round-3 files was evaluated: they hold exactly the solutions and problems the included results answer.
Each round has four files, {code,problem}_{time,space}_complexity_test_set.jsonl, one row per solution (code)
or per problem (problem). They can be loaded with the datasets library, one configuration per file kind and
one split per round, e.g. load_dataset("ComplexityInspector-test-dataset/ComplexityInspector-v1.0-dataset", "code_time", split="round_2").
Results
results/ holds the answers and scores of the 11 model configurations of the paper, on both tasks,
for time and space: in results/round_2/ scored on the round-2 test sets, and in results/round_3/ on the
round-3 subsets, each with an analysis/ folder (a summary.md and figures).
results/README.md explains the folders and files.
Layout
round_1/, round_2/, round_3/ the test sets of each cleaning round, with a README
results/round_2/, round_3/ the results of the runs, scored on round 2 and on round 3
The code repository's download script places these folders in its data/ folder, where the run and analysis
scripts expect them.
License and attribution
Licensed under CC BY-NC 4.0, like BigO(Bench), from which the test sets are derived: the problems, solutions, tests and original labels come from the BigO(Bench) test sets (Chambon et al., 2025), and the changes are those described above (variables blocks, labels in the grammar, corrected labels, subsets, unused fields removed). BigO(Bench)'s problems and solutions come from CodeContests (Li et al., 2022), whose non-code materials are licensed under CC BY 4.0.
Citation
The citation of the paper will be added after the review. The test sets build on:
@misc{chambon2025bigobenchllmsgenerate,
title={BigO(Bench) -- Can LLMs Generate Code with Controlled Time and Space Complexity?},
author={Pierre Chambon and Baptiste Roziere and Benoit Sagot and Gabriel Synnaeve},
year={2025},
howpublished={\url{https://github.com/facebookresearch/BigOBench}},
}
@article{li2022alphacode,
title={Competition-level code generation with AlphaCode},
author={Yujia Li and David Choi and Junyoung Chung and Nate Kushman and Julian Schrittwieser and R{\'e}mi Leblond and Tom Eccles and James Keeling and Felix Gimeno and Agustin Dal Lago and Thomas Hubert and Peter Choy and Cyprien de Masson d'Autume and Igor Babuschkin and Xinyun Chen and Po-Sen Huang and Johannes Welbl and Sven Gowal and Alexey Cherepanov and James Molloy and Daniel J. Mankowitz and Esme Sutherland Robson and Pushmeet Kohli and Nando de Freitas and Koray Kavukcuoglu and Oriol Vinyals},
journal={Science},
volume={378},
number={6624},
pages={1092--1097},
year={2022},
doi={10.1126/science.abq1158},
}
- Downloads last month
- 124