version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | complete | Code_Contests | Code_Contests_35685_C | from typing import List, Tuple
def smallest_perimeter_polygon(n: int, k: int, points: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
""" Find k points that form the smallest possible perimeter of a convex polygon.
If there are multiple sets of k points that form such a polygon, return any one of them.
... | from itertools import combinations
from math import sqrt
def distance(p1, p2):
return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def calc_perimeter(points):
n = len(points)
perimeter = 0
for i in range(n):
perimeter += distance(points[i], points[(i+1) % n])
return perimeter
def con... | from solution import smallest_perimeter_polygon
def test_case_1():
n = 5
k = 3
points = [(0, 0), (1, 0), (0, 1), (1, 1), (2, 2)]
expected = [(0, 0), (1, 0), (0, 1)]
assert sorted(smallest_perimeter_polygon(n, k, points)) == sorted(expected)
def test_case_2():
n = 6
k = 4
points = [(4, ... | [
{
"docstring": null,
"function_declaration": "def distance(p1, p2):",
"function_name": "distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def calc_perimeter(points):",
"function_name": "calc_perimeter",
"parameter_list": "(points)"
},
{
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom math import sqrt\n\ndef distance(p1, p2):\n return sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)\n\ndef cal... | trial_gpt4o_0 | {
"original_instruction": "You are given n points in a 2D coordinate system, and an integer k. Your task is to find k points that form the smallest possible perimeter of a convex polygon.\n\nIf there are multiple sets of k points that form such a polygon, you should return any one of them.\n\nInput\n- The first line ... | 0.720236 | Code_Contests_35685 | C | [
"distance",
"calc_perimeter",
"convex_hull",
"smallest_perimeter_polygon"
] | 4 | [
[
"calc_perimeter",
"distance"
],
[
"smallest_perimeter_polygon",
"calc_perimeter"
],
[
"smallest_perimeter_polygon",
"convex_hull"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 348aa41b33cb3e220b776271c667c9d5e7999593 | 65da9e34609f19b015eb8e17d1b6356a48a523cc | |||
v1.0 | complete | Code_Contests | Code_Contests_35123_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def find_lca(root, u, v):
pass
def path_sum_from_ancestor(root, target):
pass
def path_sum(root, u, v):
pass
def update_value(root, old_value, new_value):
pass
def build_tree... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
# Helper function to find the Lowest Common Ancestor (LCA)
def find_lca(root, u, v):
if root is None:
return None
if root.value == u or root.value == v:
return root
... | from solution import TreeNode, find_lca, path_sum_from_ancestor, path_sum, update_value, build_tree
def test_find_lca():
root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
assert find_lca(root, 2, 3).value == 1
assert find_lca(root, 2, 2).value == 2
def test_path_sum_from_ancestor... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\... | trial_gpt4o_2 | {
"original_instruction": "Carla loves trees, particularly binary trees. She comes up with an interesting problem:\n\nGiven a binary tree, each node has a value. She wants to update some nodes and sum the values in given ranges of the tree.\n\nAny node in the tree has at most two children, commonly called the left ch... | 0.609442 | Code_Contests_35123 | C | [
"find_lca",
"path_sum_from_ancestor",
"path_sum",
"update_value",
"build_tree",
"main"
] | 6 | [
[
"path_sum",
"find_lca"
],
[
"path_sum",
"path_sum_from_ancestor"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c74df62ba5f7900ef43029b29f87976912133e13 | 5f3e172332095547d31219d916606ca69cd373e9 | |||
v1.0 | complete | Code_Contests | Code_Contests_35985_C | def number_of_additional_connections_ways(n: int, m: int, p: int, connections: List[Tuple[int, int]]) -> int:
"""
Calculate the number of distinct ways to add the minimum number of additional connections
to ensure that every individual ends up in exactly one strongly connected group, modulo p.
Ar... | def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x]) # Path compression
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
... | def test_additional_connections_ways():
assert number_of_additional_connections_ways(4, 2, 1000000007, [(1, 2), (3, 4)]) == 1
assert number_of_additional_connections_ways(3, 0, 1000, []) == 2
assert number_of_additional_connections_ways(5, 4, 1000000007, [(1, 2), (2, 3), (3, 4), (4, 5)]) == 1
assert num... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_parent(parent, x):\n if parent[x] != x:\n parent[x] = find_parent(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x,... | trial_gpt4o_5 | {
"original_instruction": "Sherlock Holmes is analyzing a sequence of mysterious events that involve various individuals, represented by integers from 1 to n. Each individual has a unique identification number and some pairs of individuals are connected through mutual trust. Sherlock wants to identify all strongly co... | 0.565473 | Code_Contests_35985 | C | [
"find",
"union",
"number_of_additional_connections_ways",
"solve"
] | 4 | [
[
"number_of_additional_connections_ways",
"find"
],
[
"number_of_additional_connections_ways",
"union"
],
[
"solve",
"number_of_additional_connections_ways"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 1af9b1e17d79e01e5f53849e74a8e18787811f47 | 4505f02e8207741fd72b184f17b4659348ebd1c9 | |||
v1.0 | complete | Code_Contests | Code_Contests_35647_C | def encode_morse(text: str) -> str:
"""
Encodes a regular string into Morse Code.
>>> encode_morse("HELLO 123") == ".... . .-.. .-.. --- .---- ..--- ...--"
>>> encode_morse("SOS") == "... --- ..."
>>> encode_morse("ABC 123") == ".- -... -.-. .---- ..--- ...--"
"""
pass
def decode_morse(... | morse_code_dict = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-... | from solution import process_input, encode_morse, decode_morse
def test_encode_morse():
assert encode_morse("HELLO 123") == ".... . .-.. .-.. --- .---- ..--- ...--"
assert encode_morse("SOS") == "... --- ..."
assert encode_morse("ABC 123") == ".- -... -.-. .---- ..--- ...--"
def test_decode_morse():
... | [
{
"docstring": "Encodes a regular string into Morse Code.",
"function_declaration": "def encode_morse(text):",
"function_name": "encode_morse",
"parameter_list": "(text)"
},
{
"docstring": "Decodes a Morse Code string into a regular string.",
"function_declaration": "def decode_morse(mor... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MORSE_CODE_DICT = {\n 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', \n 'I': '..', 'J': '.---', 'K'... | trial_gpt4o_1 | {
"original_instruction": "Sam is learning Morse Code, which encodes letters and digits into sequences of dots (.) and dashes (-). He wants to write a function that translates a given string into Morse Code and vice versa. Your task is to help him by writing two functions: one that encodes a string into Morse Code an... | 0.629794 | Code_Contests_35647 | C | [
"encode_morse",
"decode_morse",
"process_input"
] | 3 | [
[
"process_input",
"decode_morse"
],
[
"process_input",
"encode_morse"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | aebd961f0536ca6352696254a3a80ce081e9f013 | ff66b79f490bced00a5fa8437c7743969e0bb0c5 | |||
v1.0 | complete | Code_Contests | Code_Contests_35965_C | import sys
from typing import List
def longest_common_prefix(words: List[str]) -> str:
"""
Finds the longest common prefix among a list of words.
If there is no common prefix, returns an empty string.
>>> longest_common_prefix(['flower', 'flow', 'flight'])
'fl'
>>> longest_common_prefix(['... | def longest_common_prefix(words):
"""
Finds the longest common prefix among a list of words.
If there is no common prefix, returns an empty string.
"""
if not words:
return ""
prefix = words[0]
for word in words[1:]:
while word[:len(prefix)] != prefix and prefix:
... | from solution import process_input_lines, longest_common_prefix
def test_longest_common_prefix():
assert longest_common_prefix(['flower', 'flow', 'flight']) == 'fl'
assert longest_common_prefix(['dog', 'racecar', 'car']) == ''
assert longest_common_prefix(['reflow', 'reform', 'refund']) == 'ref'
assert... | [
{
"docstring": "Finds the longest common prefix among a list of words.\nIf there is no common prefix, returns an empty string.",
"function_declaration": "def longest_common_prefix(words):",
"function_name": "longest_common_prefix",
"parameter_list": "(words)"
},
{
"docstring": "Processes mul... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_prefix(words):\n \"\"\"\n Finds the longest common prefix among a list of words.\n If there is no common prefix, returns an emp... | trial_gpt4o_0 | {
"original_instruction": "Given a series of lowercase words, your mission is to find the longest common prefix among them. The input consists of lines, each containing a space-separated list of words. The input terminates with a line containing a single dash ('-'). For each list of words, your program should output ... | 0.733202 | Code_Contests_35965 | C | [
"longest_common_prefix",
"process_input_lines"
] | 2 | [
[
"process_input_lines",
"longest_common_prefix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 86dd34f071d31cc9449a9c03ac38f5f32f802eef | e36b6e48c41462a9a9eac61972ea2005ef3db29c | |||
v1.0 | complete | Code_Contests | Code_Contests_35959_C | from typing import List
def max_cards_drawn(deck: List[str]) -> int:
""" Determine the maximum number of cards that can be drawn in one round.
>>> max_cards_drawn(["9H", "7C", "3D", "KH", "9S"])
3
>>> max_cards_drawn(["2H", "JD", "4C", "7C"])
2
"""
pass
def max_cards_drawn_in_each_round(te... | import random
from collections import deque
def max_cards_drawn(deck):
def draw_card(deck, card):
hand = [card]
queue = deque([card])
while queue:
current = queue.popleft()
next_cards = [c for c in deck if c[0] == current[0] or c[1] == current[1]]
for nex... | from solution import max_cards_drawn_in_each_round, process_input
def test_single_card():
input_string = "1\n1\n3D"
test_cases = process_input(input_string)
result = max_cards_drawn_in_each_round(test_cases)
assert result == [1]
def test_no_matching_cards():
input_string = "1\n4\n2H JD 4C 7C"
... | [
{
"docstring": null,
"function_declaration": "def max_cards_drawn(deck):",
"function_name": "max_cards_drawn",
"parameter_list": "(deck)"
},
{
"docstring": null,
"function_declaration": "def max_cards_drawn_in_each_round(test_cases):",
"function_name": "max_cards_drawn_in_each_round"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\nimport random\n\ndef max_cards_drawn(m, deck):\n \"\"\"\n Returns the maximum number of cards that can be drawn ... | trial_gpt4o_2 | {
"original_instruction": "A popular card game involves an initial shuffle of a deck of 52 cards, followed by repeated drawing and shuffling in a particular pattern. Each card in the deck is identified by its suit and rank. The suits are denoted by \"H\" (Hearts), \"D\" (Diamonds), \"S\" (Spades), and \"C\" (Clubs), ... | 0.636131 | Code_Contests_35959 | C | [
"max_cards_drawn",
"max_cards_drawn_in_each_round",
"process_input"
] | 3 | [
[
"max_cards_drawn_in_each_round",
"max_cards_drawn"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 030cb79447046b3b1133a2e34f511934b6fcf717 | 2d736f22c39c3df2e6a4952846931bc1d8bc6e5c | |||
v1.0 | complete | Code_Contests | Code_Contests_35714_C | def max_height_reachable(M, N, Sx, Sy, E, terrain):
""" Calculate the maximum height Ella can reach without depleting her energy.
M: int - Number of rows in the terrain grid.
N: int - Number of columns in the terrain grid.
Sx: int - Starting position x coordinate.
Sy: int - Starting position y ... | def max_height_reachable(M, N, Sx, Sy, E, terrain):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = set()
max_height = 0
def dfs(x, y, energy, current_height):
nonlocal max_height
if energy < 0 or (x, y) in visited:
return
visited.add((x, y))
curren... | import pytest
from solution import parse_and_solve
def test_example_case():
input_data = """3 3
0 0
20
10 1 15 2 20 3
5 1 30 1 25 2
10 2 35 1 40 1"""
expected_output = 40
assert parse_and_solve(input_data) == expected_output
def test_case_no_energy_to_move():
input_data = """2 2
0 0
1
10 1 15 2
20 1 2... | [
{
"docstring": null,
"function_declaration": "def max_height_reachable(M, N, Sx, Sy, E, terrain):",
"function_name": "max_height_reachable",
"parameter_list": "(M, N, Sx, Sy, E, terrain)"
},
{
"docstring": null,
"function_declaration": "def parse_and_solve(input_str):",
"function_nam... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_height_reachable(M, N, Sx, Sy, E, terrain):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n visited = set()\n max_height = 0\n\n de... | trial_gpt4o_0 | {
"original_instruction": "problem\n\nElla is planning a hiking trip and wants to know the maximum height she can reach without running out of energy. She has a certain amount of initial energy and each step she takes either increases or decreases her energy. She can go up, down, left, or right, but she cannot revisi... | 0.609932 | Code_Contests_35714 | C | [
"max_height_reachable",
"parse_and_solve"
] | 2 | [
[
"parse_and_solve",
"max_height_reachable"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f35a2567db44e7c0d605ce3df449ef02d22a367e | 13cfc88b37c76abe52a505b90a38ca9a51a5fa20 | |||
v1.0 | complete | Code_Contests | Code_Contests_36234_C | def process_test_cases(T: int, test_cases: List[Tuple[int, int]]) -> List[int]:
"""
Calculate the sum of all prime numbers in the given ranges for multiple test cases.
Args:
T: Number of test cases.
test_cases: A list of tuples, each containing two integers L and R defining the range.
Returns:... | def generate_primes_up_to(n):
"""
Returns a list of prime numbers up to n
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(n**0.5) + 1):
if is_prime[start]:
for multiple in range(start*start, n + 1, start):
is_pr... | from solution import process_test_cases
def test_case_1():
assert process_test_cases(1, [(1, 10)]) == [17]
def test_case_2():
assert process_test_cases(1, [(11, 19)]) == [60]
def test_case_3():
assert process_test_cases(1, [(20, 30)]) == [52]
def test_case_4():
assert process_test_cases(3, [(1, 10),... | [
{
"docstring": "Returns a list of prime numbers up to n",
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers between L and R (inclusive)",
"function_declaration": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes_up_to(n):\n \"\"\"\n Returns a list of prime numbers up to n\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0] = is_p... | trial_gpt4o_0 | {
"original_instruction": "Sophia is studying number theory and is particularly interested in prime numbers. One day, she encountered a challenging problem related to the sum of prime numbers in a given range.\n\nYou are given a range defined by two integers L and R. Sophia wants to find the sum of all prime numbers ... | 0.624766 | Code_Contests_36234 | C | [
"generate_primes_up_to",
"sum_primes_in_range",
"sum_primes_in_ranges",
"process_test_cases"
] | 4 | [
[
"process_test_cases",
"sum_primes_in_ranges"
],
[
"sum_primes_in_ranges",
"generate_primes_up_to"
],
[
"sum_primes_in_ranges",
"sum_primes_in_range"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | b67940f1b1aeb8a6cec26acc05f72b6a6e7982b8 | 68ea997c13c77e77a54a6255666a3ba3862c5ff8 | |||
v1.0 | complete | Code_Contests | Code_Contests_36126_C | def is_balanced(string: str) -> str:
""" Determines if a string with parentheses and brackets is balanced.
Parameters:
string (str): The input string containing parentheses and brackets.
Returns:
str: 'YES' if the string is balanced, 'NO' otherwise.
>>> is_balanced("(){}[]")
'... | def is_balanced(string):
"""
Determines if a string with parentheses and brackets is balanced.
Parameters:
string (str): The input string containing parentheses and brackets.
Returns:
str: 'YES' if the string is balanced, 'NO' otherwise.
"""
stack = []
matching_brackets = {... | from solution import is_balanced, check_balanced_strings
def test_is_balanced_valid_cases():
assert is_balanced("(){}[]") == 'YES'
assert is_balanced("({[]})") == 'YES'
assert is_balanced("{[()]}") == 'YES'
def test_is_balanced_invalid_cases():
assert is_balanced("({[}])") == 'NO'
assert is_balanc... | [
{
"docstring": "Determines if a string with parentheses and brackets is balanced.\n\nParameters:\nstring (str): The input string containing parentheses and brackets.\n\nReturns:\nstr: 'YES' if the string is balanced, 'NO' otherwise.",
"function_declaration": "def is_balanced(string):",
"function_name": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced(s):\n \"\"\"\n Determine if the input string s is a balanced string of parentheses and brackets.\n \"\"\"\n stack = []\n map... | trial_gpt4o_2 | {
"original_instruction": "Balanced String Check\n\nIn a software development company, programmers often encounter a type of well-known challenge: handling parenthesis and bracket balancing in strings. A balanced string is a string with a matching opening and closing pair for each type of parentheses and brackets.\n\... | 0.717383 | Code_Contests_36126 | C | [
"is_balanced",
"check_balanced_strings"
] | 2 | [
[
"check_balanced_strings",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ea6d2df8ff2d7f089fbe962f8488fd153f6a86e8 | c900c0c9b5bb2d27ab9855bcd53bbe37db51efaa | |||
v1.0 | complete | Code_Contests | Code_Contests_36276_C | import re
from collections import defaultdict
def is_chemical_equation_balanced(equation: str):
""" Determine if a given chemical equation is balanced. The equation is considered balanced
if for each element the total number of atoms on the reactant side is equal to the total number
of atoms on the produc... | import re
from collections import defaultdict
def parse_chemical_formula(formula: str):
"""
Parse a chemical formula into a dictionary of elements and their counts.
Args:
formula (str): A string representing the chemical formula.
Returns:
dict: A dictionary with elements as keys and t... | from solution import is_chemical_equation_balanced
def test_balanced_equation():
assert is_chemical_equation_balanced('H2 + O2 -> H2O') == None # Expected to print "Balanced"
def test_unbalanced_equation():
assert is_chemical_equation_balanced('C2H6 + O2 -> CO2 + H2O') == None # Expected to print "Unbalance... | [
{
"docstring": "Parse a chemical formula into a dictionary of elements and their counts.\n\nArgs:\nformula (str): A string representing the chemical formula.\n\nReturns:\ndict: A dictionary with elements as keys and their counts as values.",
"function_declaration": "def parse_chemical_formula(formula):",
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import re\nfrom collections import defaultdict\n\ndef parse_compound(compound):\n \"\"\"Parse a chemical compound to return a d... | trial_gpt4o_8 | {
"original_instruction": "You are given a string representing a chemical equation. The string consists of alphanumeric characters and symbols indicating elements, quantities, reactants, and products. The equation follows the traditional format: `Reactants -> Products`, where each element is represented by its chemic... | 0.559557 | Code_Contests_36276 | C | [
"parse_chemical_formula",
"parse_equation",
"is_chemical_equation_balanced"
] | 3 | [
[
"is_chemical_equation_balanced",
"parse_equation"
],
[
"parse_equation",
"parse_chemical_formula"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b26e57a8aa8c72edcfe6f246067b7559c0ead522 | f3522c1a7c289a15b1a4f613c58481ebf1508304 | |||
v1.0 | complete | Code_Contests | Code_Contests_35741_C | def can_form_hamiltonian_cycle(n: int, m: int, edge_list: List[str]) -> str:
""" Determine whether it is possible to form a Hamiltonian cycle with the given venues and roads.
Args:
n (int): The number of venues.
m (int): The number of available roads.
edge_list (List[str]): The list of roads re... | from itertools import permutations
def is_hamiltonian_cycle(n, edges):
if n <= 1:
return True
adj_list = {i: set() for i in range(1, n + 1)}
for u, v in edges:
adj_list[u].add(v)
adj_list[v].add(u)
for perm in permutations(range(1, n + 1)):
valid = True
... | from solution import can_form_hamiltonian_cycle
def test_example_1():
n = 4
m = 4
edge_list = ["1 2", "2 3", "3 4", "4 1"]
assert can_form_hamiltonian_cycle(n, m, edge_list) == "Yes"
def test_example_2():
n = 4
m = 3
edge_list = ["1 2", "2 3", "3 1"]
assert can_form_hamiltonian_cycle(n... | [
{
"docstring": null,
"function_declaration": "def is_hamiltonian_cycle(n, edges):",
"function_name": "is_hamiltonian_cycle",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def can_form_hamiltonian_cycle(n, m, edge_list):",
"function_name": "can_form_h... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_hamiltonian_cycle(n, edges):\n if n <= 1:\n return True\n \n adj_list = {i: set() for i in ran... | trial_gpt4o_0 | {
"original_instruction": "The mayor of a small town wants to organize a series of events to celebrate the town's anniversary. The main event will be a series of connected parades, moving from one venue to another. Each venue can be considered a node, and the roads connecting them are edges in an undirected graph. Th... | 0.544975 | Code_Contests_35741 | C | [
"is_hamiltonian_cycle",
"can_form_hamiltonian_cycle"
] | 2 | [
[
"can_form_hamiltonian_cycle",
"is_hamiltonian_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bb77017353427033784d6414d777c0071d6f2436 | 62795ac0dd6028ee7902416d867c5f9b52fc88e8 | |||
v1.0 | complete | Code_Contests | Code_Contests_36095_C | def solve(n: int, grid: List[str], T: List[List[int]]) -> int:
""" Determine the maximum number of transformations that can occur in any cell on the path
from the top-left corner to the bottom-right corner such that there still exists a valid path.
>>> solve(4, ["....", ".X..", "..X.", "...."], [[0, 0,... | def max_transformations(grid, T):
n = len(grid)
# dp table to store the maximum number of transformations we can meet at each cell
dp = [[-1] * n for _ in range(n)]
# Base case
dp[0][0] = T[0][0] if grid[0][0] == '.' else -1
# DP computation
for i in range(n):
for j in range(n)... | def test_example_case():
n = 4
grid = [
"....",
".X..",
"..X.",
"...."
]
T = [
[0, 0, 1, 1],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 1]
]
assert solve(n, grid, T) == 0
def test_no_obstacles():
n = 3
grid = [
"...",
... | [
{
"docstring": null,
"function_declaration": "def max_transformations(grid, T):",
"function_name": "max_transformations",
"parameter_list": "(grid, T)"
},
{
"docstring": null,
"function_declaration": "def solve(n, grid, T):",
"function_name": "solve",
"parameter_list": "(n, grid,... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_transformations(grid, T):\n n = len(grid)\n dp = [[float('inf')] * n for _ in range(n)]\n dp[0][0] = T[0][0] if grid[0][0] == '.' else flo... | trial_gpt4o_4 | {
"original_instruction": "In a faraway land, there exists a grid of dimensions n x n, consisting of cells. Each cell can either be empty (represented by a '.') or contain an obstacle (represented by an 'X'). You, as the brave knight, can move through this grid, starting from the top-left corner (1,1) to the bottom-r... | 0.691418 | Code_Contests_36095 | C | [
"max_transformations",
"solve"
] | 2 | [
[
"solve",
"max_transformations"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5854b439508a51f87e4676f758d3dee3b1f0556c | bf3a7687a5b628b9bc438ac78112170f5ed100ed | |||
v1.0 | complete | Code_Contests | Code_Contests_35956_C | from typing import List
def is_palindrome(arr: List[int]) -> bool:
""" Check if the given array is a palindrome. """
return arr == arr[::-1]
def longest_palindrome_subarray_length(arr: List[int]) -> int:
"""
Find the length of the longest contiguous subarray that forms a palindrome.
Args:
... | def is_palindrome(arr):
"""
This function checks if the input array is a palindrome.
"""
return arr == arr[::-1]
def longest_palindrome_subarray_length(arr):
"""
This function finds the length of the longest contiguous subarray
that forms a palindrome.
"""
n = len(arr)
max_leng... | from solution import longest_palindrome_subarray_length, solve
def test_single_element_array():
assert longest_palindrome_subarray_length([1]) == 1
def test_entire_array_palindrome():
assert longest_palindrome_subarray_length([1, 2, 3, 2, 1]) == 5
def test_no_palindromes():
assert longest_palindrome_suba... | [
{
"docstring": "This function checks if the input array is a palindrome.",
"function_declaration": "def is_palindrome(arr):",
"function_name": "is_palindrome",
"parameter_list": "(arr)"
},
{
"docstring": "This function finds the length of the longest contiguous subarray \nthat forms a palind... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_subarray(arr):\n \"\"\"\n Returns the length of the longest palindromic subarray in the given array.\n \"\"\"\n n = len... | trial_gpt4o_2 | {
"original_instruction": "Aliens and Palindromes\n\nAliens from the planet Zog love palindromes. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward (ignoring spaces, punctuation, and capitalization). The Zog scientists have developed a special sequence of ... | 0.655475 | Code_Contests_35956 | C | [
"is_palindrome",
"longest_palindrome_subarray_length",
"solve"
] | 3 | [
[
"longest_palindrome_subarray_length",
"is_palindrome"
],
[
"solve",
"longest_palindrome_subarray_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e8c9b7af226ba33233d0064b1dd327c66ea2b4ad | cd53f9bea8355cc0a4795a0877af3627191dc39c | |||
v1.0 | complete | Code_Contests | Code_Contests_36501_C | from collections import defaultdict
def max_distance_in_tree(n: int, edges: List[Tuple[int, int]]) -> int:
""" Given the number of nodes `n` and a list of edges `edges` in a tree,
find the maximum distance between any two nodes in the tree.
>>> max_distance_in_tree(5, [(1, 2), (1, 3), (2, 4), (2, 5)])
... | from collections import deque, defaultdict
def bfs(farthest_node_start, n, graph):
visited = [-1] * (n + 1)
queue = deque([farthest_node_start])
visited[farthest_node_start] = 0
farthest_node = farthest_node_start
max_distance = 0
while queue:
node = queue.popleft()
current... | def test_max_distance_in_tree():
edges1 = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert max_distance_in_tree(5, edges1) == 3
edges2 = [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)]
assert max_distance_in_tree(6, edges2) == 4
edges3 = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert max_distance_in_tree(5, edges3) ... | [
{
"docstring": null,
"function_declaration": "def bfs(farthest_node_start, n, graph):",
"function_name": "bfs",
"parameter_list": "(farthest_node_start, n, graph)"
},
{
"docstring": null,
"function_declaration": "def max_distance_in_tree(n, edges):",
"function_name": "max_distance_in... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs_farthest_node(start, graph):\n \"\"\"\n Perform BFS to find the farthest node from the starting node and its... | trial_gpt4o_1 | {
"original_instruction": "Martha is very interested in botany and has recently become fascinated with the structure of trees. She learned that every tree can be uniquely represented as an undirected acyclic graph. She is interested in finding two particular nodes in a tree, which she will call x and y, such that the... | 0.612024 | Code_Contests_36501 | C | [
"bfs",
"max_distance_in_tree"
] | 2 | [
[
"max_distance_in_tree",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1ac1157e0fcd09a38a2d52f782f392899399aedc | b78aafa38edfd349c485737efca8eb766a193b6c | |||
v1.0 | complete | Code_Contests | Code_Contests_36700_C | def min_initial_infected(n: int, connections: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of computers that need to be infected initially to ensure that all computers in the network become infected.
>>> min_initial_infected(6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)])
1
>>> min_initi... | def find_connected_components(n, connections):
from collections import defaultdict, deque
graph = defaultdict(list)
for u, v in connections:
graph[u].append(v)
graph[v].append(u)
visited = [False] * (n + 1)
components = 0
def bfs(start):
queue = deque([star... | from solution import min_initial_infected
def test_min_initial_infected_example_1():
n = 6
connections = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
assert min_initial_infected(n, connections) == 1
def test_min_initial_infected_example_2():
n = 7
connections = [(1, 2), (2, 3), (4, 5), (6, 7)]
ass... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(n, connections):",
"function_name": "find_connected_components",
"parameter_list": "(n, connections)"
},
{
"docstring": null,
"function_declaration": "def min_initial_infected(n, connections):",
"function_nam... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_initial_infections(n, edges):\n \"\"\"\n Determines the minimum number of computers that need to be infected initially\n to ensure that al... | trial_gpt4o_2 | {
"original_instruction": "A network of computers is represented as an undirected graph with n nodes and m edges. Each node is uniquely identified by an integer from 1 to n. Write a program to determine the minimum number of computers that need to be infected initially to ensure that all computers in the network beco... | 0.584184 | Code_Contests_36700 | C | [
"find_connected_components",
"min_initial_infected"
] | 2 | [
[
"min_initial_infected",
"find_connected_components"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e0623d14f82e2ead7db801f76c90bfdc1023d835 | 5a9a5dbd457fcdd989ac79d3f0b58aa44a40f174 | |||
v1.0 | complete | Code_Contests | Code_Contests_36586_C | def reverse_number(n: int) -> int:
""" Reverse the digits of the number n.
>>> reverse_number(123)
321
>>> reverse_number(400)
4
>>> reverse_number(789)
987
"""
def is_palindrome(n: int) -> bool:
""" Check if the number n is a palindrome.
>>> is_palindrome(121)
True
... | def reverse_number(n):
return int(str(n)[::-1])
def is_palindrome(n):
return str(n) == str(n)[::-1]
def iterations_to_palindrome(n):
for i in range(1001):
if is_palindrome(n):
return i
n += reverse_number(n)
return -1
def sequence_iterations(numbers):
return [iteration... | from solution import reverse_number, is_palindrome, iterations_to_palindrome, sequence_iterations
def test_reverse_number():
assert reverse_number(123) == 321
assert reverse_number(400) == 4
assert reverse_number(789) == 987
def test_is_palindrome():
assert is_palindrome(121) is True
assert is_pal... | [
{
"docstring": null,
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docst... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_iterations_to_palindrome(n):\n \"\"\"\n Given an integer n, finds the number of iterations required to reach a palindrome\n by repeatedly... | trial_gpt4o_1 | {
"original_instruction": "Aman is fascinated by patterns in numbers. He recently stumbled upon a sequence problem and wants to automate the process of finding the sequence for a given set of numbers. As Aman is still learning programming, he seeks your assistance.\n\nThe sequence is defined as follows:\nStarting fro... | 0.729696 | Code_Contests_36586 | C | [
"reverse_number",
"is_palindrome",
"iterations_to_palindrome",
"sequence_iterations"
] | 4 | [
[
"iterations_to_palindrome",
"is_palindrome"
],
[
"iterations_to_palindrome",
"reverse_number"
],
[
"sequence_iterations",
"iterations_to_palindrome"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | c488eab10bbdc76aa423ddbf2f9697c52304df82 | c2088da9d32cd7a08bfdfea6107b75ce2dedeec5 | |||
v1.0 | complete | Code_Contests | Code_Contests_36475_C | from typing import List
from collections import deque
def word_ladder(start: str, end: str, dictionary: List[str]) -> int:
"""
Returns the minimum number of steps to convert start to end using the given dictionary.
Each step changes one letter and resulting word must be in the dictionary.
If the conver... | from collections import deque
def word_ladder(start, end, dictionary):
"""
Returns the minimum number of steps to convert start to end using the given dictionary.
Each step changes one letter and resulting word must be in the dictionary.
If the conversion is not possible, returns -1.
"""
if end... | from solution import word_ladder, get_input_and_solve
def test_example_case():
input_string = "hit cog\n6\nhot dot dog lot log cog"
output = get_input_and_solve(input_string)
assert output == 5
def test_impossible_case():
input_string = "hit cog\n4\nhot dot dog log"
output = get_input_and_solve(in... | [
{
"docstring": "Returns the minimum number of steps to convert start to end using the given dictionary.\nEach step changes one letter and resulting word must be in the dictionary.\nIf the conversion is not possible, returns -1.",
"function_declaration": "def word_ladder(start, end, dictionary):",
"funct... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef word_ladder(start, end, dictionary):\n if end not in dictionary:\n return -1\n\n word_set = set(dictionar... | trial_gpt4o_4 | {
"original_instruction": "A word ladder is a puzzle where you must convert a starting word to an ending word by changing one letter at a time, with each intermediate word being a valid word in the given dictionary. Each step must result in a valid word and you can only change one letter at a time.\n\nInput\nFirst li... | 0.653002 | Code_Contests_36475 | C | [
"word_ladder",
"get_input_and_solve"
] | 2 | [
[
"get_input_and_solve",
"word_ladder"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fb036d7bf5e86c8af4401db233569576f25ac06f | 4589166706c5c4fbd6d574314d9911280a165c93 | |||
v1.0 | complete | Code_Contests | Code_Contests_36486_C | def maximum_intensity_elixir(N, M, S, pathways):
"""Determine the maximum possible intensity of the elixir the alchemist can create.
Args:
N (int): Number of unique magical potions.
M (int): Number of bi-directional pathways.
S (int): The potion you start from.
pathways (List[Tuple[int, int... | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif rank[ro... | def test_example_1():
input_str = "3 3 1\n1 2 2\n2 3 3\n1 3 4\n"
assert solve_problem(input_str) == 4
def test_example_2():
input_str = "4 4 2\n1 2 5\n2 3 3\n3 4 7\n4 1 10\n"
assert solve_problem(input_str) == 10
def test_example_3():
input_str = "5 5 5\n1 2 1\n2 3 2\n3 4 3\n4 5 4\n5 1 5\n"
as... | [
{
"docstring": null,
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, u, v):",
"function_name": "union",
"parameter_list": "(parent, rank, u, v)"
},
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef maximum_intensity(N, M, S, pathways):\n graph = {i: [] for i in range(1, N + 1)}\n for u, v, c in pathways:\n graph[u].app... | trial_gpt4o_4 | {
"original_instruction": "In a faraway kingdom, there are $N$ unique magical potions and $M$ bi-directional magical pathways connecting them. Each pathway connects two potions, and traveling through a pathway for a certain amount of time allows the traveler to consume the effects of all potions connected through the... | 0.585082 | Code_Contests_36486 | C | [
"find",
"union",
"maximum_intensity_elixir",
"solve_problem"
] | 4 | [
[
"maximum_intensity_elixir",
"find"
],
[
"maximum_intensity_elixir",
"union"
],
[
"solve_problem",
"maximum_intensity_elixir"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | c66fbc9384fa131a14cf1275eec91a88aa948d73 | 3062c233083c9cc32506d5a71ee4f565d8a6e79f | |||
v1.0 | complete | Code_Contests | Code_Contests_36784_C | from typing import List
def max_square_submatrix_area(matrix: List[List[int]]) -> int:
""" Given a matrix of size M x N consisting of only 0s and 1s, find the
maximum size square sub-matrix with all 1s and return its area.
>>> max_square_submatrix_area([
... [1, 0, 1, 0, 0],
... [1, 0,... | def max_square_submatrix_area(matrix):
"""
Finds the maximum size square sub-matrix with all 1s and returns its area.
:param matrix: List of List of integers (0s and 1s)
:return: Integer representing the area of the largest square sub-matrix with all 1s
"""
if not matrix or not matrix[0]:
... | import pytest
from solution import max_square_submatrix_area, max_square_submatrix_area_from_input
def test_max_square_submatrix_area():
matrix1 = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert max_square_submatrix_area(matrix1) == 4
m... | [
{
"docstring": "Finds the maximum size square sub-matrix with all 1s and returns its area.\n\n:param matrix: List of List of integers (0s and 1s)\n:return: Integer representing the area of the largest square sub-matrix with all 1s",
"function_declaration": "def max_square_submatrix_area(matrix):",
"func... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximal_square_area(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n M, N = len(matrix), len(matrix[0])\n # Initialize a dp ar... | trial_gpt4o_2 | {
"original_instruction": "Given a matrix of size M x N consisting of only 0s and 1s, write a program that finds the maximum size square sub-matrix with all 1s and returns its area.\n\n### Input:\nTwo integers M and N, representing the dimensions of the matrix.\n\nFollowing M lines contain N space-separated integers,... | 0.670189 | Code_Contests_36784 | C | [
"max_square_submatrix_area",
"max_square_submatrix_area_from_input"
] | 2 | [
[
"max_square_submatrix_area_from_input",
"max_square_submatrix_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bf556875947afb3da86aedb59ed2c08a6bbb6a20 | 09405e60e490af1a7430c30dd3eebad470f89f17 | |||
v1.0 | complete | Code_Contests | Code_Contests_37059_C | from typing import List
def solve_warehouse_tasks(inputs: List[str]) -> List[int]:
"""
Parses the grid and queries for each test case, and computes the minimum number of steps required for each query.
Args:
- inputs: List of strings representing the test case inputs.
Returns:
- List of in... | from collections import deque
def bfs(grid, start, end, R, C):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([start])
visited = set()
visited.add(start)
steps = 0
while queue:
for _ in range(len(queue)):
r, c = queue.popleft()
if (r,... | import pytest
from solution import solve_warehouse_tasks
def test_example_case():
inputs = [
"1",
"5 5",
".....",
".###.",
"..#..",
".###.",
".....",
"2",
"1 1 5 5",
"1 1 3 3"
]
expected_output = [8, -1]
assert solve_wareho... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, start, end, R, C):",
"function_name": "bfs",
"parameter_list": "(grid, start, end, R, C)"
},
{
"docstring": null,
"function_declaration": "def shortest_paths(grid, R, C, queries):",
"function_name": "shortest_paths",
"pa... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(grid, start, end, R, C):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queue = deque([start])\n vis... | trial_gpt4o_2 | {
"original_instruction": "Vivek works at a warehouse that is organized in a grid layout of R rows and C columns. The grid has various sections, some of which are restricted and cannot be accessed. The warehouse manager assigns various tasks to Vivek, where each task involves carrying items from one section to anothe... | 0.561662 | Code_Contests_37059 | C | [
"bfs",
"shortest_paths",
"solve_warehouse_tasks"
] | 3 | [
[
"shortest_paths",
"bfs"
],
[
"solve_warehouse_tasks",
"shortest_paths"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 718fcafc4f7bfa41775e9e7d313f8224fa15ee7a | 49ffd1175eabd567d503d6b08e5cb75ae3300888 | |||
v1.0 | complete | Code_Contests | Code_Contests_36245_C | def minimum_time_to_complete_all_tasks(input_data: str) -> int:
""" Parse the input data and find the minimum time required to complete all tasks.
Args:
input_data (str): the input data containing task durations and dependencies
Returns:
int: the minimum amount of time required to finish all ta... | from collections import defaultdict, deque
def find_minimum_time(n, m, tasks, dependencies):
# Create a task duration map
task_duration = {}
for task in tasks:
task_id, duration = task
task_duration[task_id] = duration
# Create adjacency list and in-degree map
adj_list = defaultdic... | def test_example_1():
input_data = """5 4
1 3
2 2
3 4
4 6
5 8
1 2
2 3
3 4
4 5"""
assert minimum_time_to_complete_all_tasks(input_data) == 23
def test_example_2():
input_data = """3 1
1 5
2 10
3 3
1 2"""
assert minimum_time_to_complete_all_tasks(input_data) == 15
def test_no_dependencies():
input_d... | [
{
"docstring": null,
"function_declaration": "def find_minimum_time(n, m, tasks, dependencies):",
"function_name": "find_minimum_time",
"parameter_list": "(n, m, tasks, dependencies)"
},
{
"docstring": null,
"function_declaration": "def minimum_time_to_complete_all_tasks(input_data):",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef min_time_to_finish(tasks, dependencies):\n # Create a graph and in-degree count based on dependencies\... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of tasks that need to be scheduled on a single CPU machine. Each task has a duration, and some tasks must be performed before others. Create a program to find the minimum amount of time required to finish all tasks.\n\nEach task is represented by a unique identifier and... | 0.647766 | Code_Contests_36245 | C | [
"find_minimum_time",
"minimum_time_to_complete_all_tasks"
] | 2 | [
[
"minimum_time_to_complete_all_tasks",
"find_minimum_time"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7a9a76a773e5ab37c561d9bf4c987410d18ef5e7 | 22d23e3f2c0d33968e51a4d45f5287f83e288d68 | |||
v1.0 | complete | Code_Contests | Code_Contests_36581_C | def check_valid_grid(grid):
""" Checks if the given grid is valid according to the rules set by Ana.
Each row, each column, and each 3x4 subgrid must only contain unique letters.
If the grid is invalid, return the position and letter that is duplicated.
>>> check_valid_grid([
['a', 'b', 'c', 'd'... | def check_valid_grid(grid):
rows, cols = len(grid), len(grid[0])
# Check rows and columns
for r in range(rows):
row_letters = set()
for c in range(cols):
if grid[r][c] in row_letters:
return r, c, grid[r][c]
row_letters.add(grid[r][c])
fo... | def test_valid_grid():
datasets = [
[
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l']
]
]
results = validate_datasets(datasets)
assert results == [[
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l... | [
{
"docstring": null,
"function_declaration": "def check_valid_grid(grid):",
"function_name": "check_valid_grid",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def validate_datasets(datasets):",
"function_name": "validate_datasets",
"parameter_list": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_grid(n, datasets):\n def is_valid_grid(grid):\n rows, cols = len(grid), len(grid[0])\n \n # Check rows and columns\n ... | trial_gpt4o_2 | {
"original_instruction": "Ana is creating a rectangular grid composed of lowercase letters from 'a' to 'z'. She wants to make sure that no two cells in the same row or the same column contain the same letter. Additionally, each subgrid (3x4) must only contain unique letters.\n\nWrite a program that reads multiple da... | 0.604704 | Code_Contests_36581 | C | [
"check_valid_grid",
"validate_datasets",
"format_output"
] | 3 | [
[
"validate_datasets",
"check_valid_grid"
]
] | 1 | [
"format_output"
] | false | [] | false | pytest | false | [] | true | a79ef2895eccf941cfa816e474e43e03d32bb08f | 5dc49202a4a3d4820d352c2409f0572806c25320 | |||
v1.0 | complete | Code_Contests | Code_Contests_36714_C | from typing import List, Tuple
def minimum_recharges(d: int, c: int, k: int, destinations: List[Tuple[int, int, int]], recharge_stations: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of stops to recharge along the way to ensure all deliveries are made.
Each drone has a limited battery c... | from math import sqrt
from collections import deque
def distance(x1, y1, x2, y2):
return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_recharges(d, c, k, destinations, recharge_stations):
initial_battery = c
current_position = (0, 0)
current_battery = initial_battery
recharges = 0
destina... | from solution import minimum_recharges
def test_case_1():
d = 3
c = 50
k = 1
destinations = [(10, 10, 20), (20, 5, 30), (15, 15, 10)]
recharge_stations = [(5, 5), (25, 10)]
assert minimum_recharges(d, c, k, destinations, recharge_stations) == 1
def test_case_2():
d = 2
c = 100
k = ... | [
{
"docstring": null,
"function_declaration": "def distance(x1, y1, x2, y2):",
"function_name": "distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_recharges(d, c, k, destinations, recharge_stations):",
"function_name": "minimu... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.hypot(x2 - x1, y2 - y1)\n\ndef min_recharges_to_complete_deliveries(d, c, k, destin... | trial_gpt4o_3 | {
"original_instruction": "A group of delivery drones needs to deliver packages to various destinations. Each drone has a limited battery capacity and a fixed rate of battery consumption per kilometer. Given the initial battery charge of the drone, its consumption rate, and a list of destinations it must reach, deter... | 0.560517 | Code_Contests_36714 | C | [
"distance",
"minimum_recharges"
] | 2 | [
[
"minimum_recharges",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65f633ead92a540ab27503338f63455c665b4590 | cbdfa69af0231b8f11d7ed39cbbc0f2bafe53adc | |||
v1.0 | complete | Code_Contests | Code_Contests_36273_C | def number_of_unique_paths(n: int, m: int, grid: List[str]) -> int:
""" Determine the number of unique paths from the top-left corner to the bottom-right corner in a grid with obstacles.
>>> number_of_unique_paths(3, 3, ['. . .', '. # .', '. . .'])
2
>>> number_of_unique_paths(3, 3, ['. # .', '# . #', '... | def unique_paths_with_obstacles(grid):
n = len(grid)
m = len(grid[0])
# If starting point or ending point is an obstacle, return 0
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
# Initialize a 2D dp array with 0s
dp = [[0] * m for _ in range(n)]
# Starting poi... | from solution import number_of_unique_paths
def test_paths_with_obstacles():
assert number_of_unique_paths(3, 3, ['. . .', '. # .', '. . .']) == 2
assert number_of_unique_paths(3, 3, ['. # .', '# . #', '. # .']) == 0
assert number_of_unique_paths(2, 2, ['. .', '. .']) == 2
assert number_of_unique_paths... | [
{
"docstring": null,
"function_declaration": "def unique_paths_with_obstacles(grid):",
"function_name": "unique_paths_with_obstacles",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_unique_paths(n, m, grid):",
"function_name": "number_of_uni... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths(grid):\n n = len(grid)\n m = len(grid[0])\n \n # If the start or end is an obstacle, return 0 immediately\n if grid[0][0] =... | trial_gpt4o_2 | {
"original_instruction": "There is a unique game played in Gridland in which players need to traverse a grid filled with various obstacles. The grid is of size `n x m`, and some cells contain obstacles that make them inaccessible. The player starts from the top-left corner of the grid and needs to reach the bottom-r... | 0.669379 | Code_Contests_36273 | C | [
"unique_paths_with_obstacles",
"number_of_unique_paths"
] | 2 | [
[
"number_of_unique_paths",
"unique_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5a9734b0ffc5015aa04d187274166981bbe31b19 | e4119378aea6749a63e62fcf09a245ed8d239ed2 | |||
v1.0 | complete | Code_Contests | Code_Contests_37196_C | def minimum_toll_cost(data: str) -> int:
"""
Determine the smallest possible toll cost to maintain a road network that connects all cities
using the Minimum Spanning Tree algorithm.
Input:
- data: a string containing the number of cities and roads, followed by the names of cities,
and the... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[r... | def test_single_road():
data = "2 1\nCity1\nCity2\nCity1 City2 10\n"
assert minimum_toll_cost(data) == 10
def test_multiple_cities():
data = "4 5\nMumbai\nDelhi\nBangalore\nChennai\nMumbai Delhi 10\nDelhi Bangalore 15\nBangalore Chennai 5\nChennai Mumbai 7\nMumbai Bangalore 20\n"
assert minimum_toll_co... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro... | trial_gpt4o_2 | {
"original_instruction": "In a country there are several cities connected by bidirectional roads. Each road has a certain toll cost associated with it. Due to recent budget cuts, the government wants to minimize the total toll cost for travelers by reducing the number of active roads. Your task is to determine the s... | 0.636242 | Code_Contests_37196 | C | [
"find",
"union",
"minimum_spanning_tree",
"parse_input",
"minimum_toll_cost"
] | 5 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"minimum_toll_cost",
"minimum_spanning_tree"
],
[
"minimum_toll_cost",
"parse_input"
],
[
"union",
"find"
]
] | 5 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 9d881b6d4fad059e2a8ffd1544e069b1fcc23981 | f3eeace1473031eac5a6e06b36aa6ee91b80195f | |||
v1.0 | complete | Code_Contests | Code_Contests_36834_C | def minimum_portals(n: int, trails: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of portals required so that every creature can communicate with every other creature.
>>> minimum_portals(4, [(1, 2), (2, 3)])
2
>>> minimum_portals(5, [(1, 2), (2, 3), (3, 1), (4, 5), (5, 4)])
2... | from collections import defaultdict, deque
def kosaraju_sccs(n, graph):
def dfs1(v):
visited.add(v)
for u in graph[v]:
if u not in visited:
dfs1(u)
stack.append(v)
def dfs2(v):
component.append(v)
visited.add(v)
for u in reverse_g... | import pytest
from solution import minimum_portals
def test_minimum_portals_1():
assert minimum_portals(4, [(1, 2), (2, 3)]) == 2
def test_minimum_portals_2():
assert minimum_portals(5, [(1, 2), (2, 3), (3, 1), (4, 5), (5, 4)]) == 2
def test_minimum_portals_fully_connected():
assert minimum_portals(3, [(... | [
{
"docstring": null,
"function_declaration": "def kosaraju_sccs(n, graph):",
"function_name": "kosaraju_sccs",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def minimum_portals(n, trails):",
"function_name": "minimum_portals",
"parameter_list": "... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef min_portals_needed(N, T, trails):\n def kosaraju_scc(n, trails):\n g = defaultdict(list)\n ... | trial_gpt4o_7 | {
"original_instruction": "In the magical forest of Zog, there are N mystical creatures, each residing in their own lair. Some of these lairs are connected by enchanted trails that can only be traversed in one direction, specified by the sorcerer's decree. Due to a recent surge in dark magic, communication between cr... | 0.512023 | Code_Contests_36834 | C | [
"kosaraju_sccs",
"minimum_portals",
"main"
] | 3 | [
[
"minimum_portals",
"kosaraju_sccs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 73469f07bf2e15e0bcc09ee7b7b8adaa48097e92 | a2633fd8ab388ff687b4e89a2d60f15e8e915504 | |||
v1.0 | complete | Code_Contests | Code_Contests_37317_C | def sum_of_digits(n: int) -> int:
"""Returns the sum of the digits of the given integer n.
>>> sum_of_digits(123) 6
>>> sum_of_digits(456) 15
>>> sum_of_digits(789) 24
>>> sum_of_digits(0) 0
>>> sum_of_digits(100) 1
"""
def process_numbers(numbers: List[int]) -> List[int]:
"""Given a li... | def sum_of_digits(n):
"""
Returns the sum of the digits of the given integer n.
"""
return sum(int(digit) for digit in str(n))
def process_numbers(numbers):
"""
Given a list of numbers, return a list of the sum of digits for each
number, excluding the end-of-input signal -1.
"""
res... | from solution import sum_of_digits, process_numbers
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 15
assert sum_of_digits(789) == 24
assert sum_of_digits(0) == 0
assert sum_of_digits(100) == 1
def test_process_numbers():
assert process_numbers([123, 456,... | [
{
"docstring": "Returns the sum of the digits of the given integer n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of numbers, return a list of the sum of digits for each\nnumber, excluding the en... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of digits of the integer n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef read_... | trial_gpt4o_2 | {
"original_instruction": "Write a program that reads a list of integers and for each integer, outputs the sum of its digits. The program should continue reading integers until it reads an end-of-input signal, which is represented by the integer -1. The output should not include the sum for the end-of-input signal.\n... | 0.695292 | Code_Contests_37317 | C | [
"sum_of_digits",
"process_numbers"
] | 2 | [
[
"process_numbers",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a45f92eeaa2be3b2612bf34e7b14be9ec4033282 | a3cdedc1ebbfe4b6ce51103657cdcbde6cc1ef2a | |||
v1.0 | complete | Code_Contests | Code_Contests_37234_C | def find_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
for node in graph[start]:
if node not in path:
new_path = find_path(graph, node, end, path)
if new_path:
return new_path
return None
def max_value_on_pat... | def find_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
for node in graph[start]:
if node not in path:
new_path = find_path(graph, node, end, path)
if new_path:
return new_path
return None
def max_value_on_pat... | from solution import solve
def test_simple_case():
n, q = 5, 3
node_values = [5, 3, 7, 6, 2]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [(1, 5), (2, 4), (3, 5)]
assert solve(n, q, node_values, edges, queries) == [7, 7, 7]
def test_single_node():
n, q = 1, 1
node_values = [7]
ed... | [
{
"docstring": null,
"function_declaration": "def find_path(graph, start, end, path=[]):",
"function_name": "find_path",
"parameter_list": "(graph, start, end, path=[])"
},
{
"docstring": null,
"function_declaration": "def max_value_on_path(values, path):",
"function_name": "max_valu... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef preprocess_values(values):\n values_dict = {}\n for i, val in enumerate(values, start=1):\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a tree (connected undirected graph with no cycles) with n nodes rooted at node 1. Each node is assigned a unique value. Your task is to answer q queries of the following type: Given two nodes u and v, find the maximum value on the path from node u to node v.\n\nInput\n\nThe fi... | 0.701317 | Code_Contests_37234 | C | [
"find_path",
"max_value_on_path",
"solve"
] | 3 | [
[
"solve",
"find_path"
],
[
"solve",
"max_value_on_path"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2216999e0fe6f35a12b98702b95b19e470be6234 | 4b7c173ade414407c15d6bf1de97995e94f265ee | |||
v1.0 | complete | Code_Contests | Code_Contests_37254_C | def solve(input_data: str) -> list:
"""
Process multiple test cases, answering queries about an array.
Input is provided as a single string, representing multiple lines.
Each test case begins with two integers n and q (length of the array and number of queries).
The initial array is all zeros.
... | def process_queries(test_cases):
results = []
for n, q, queries in test_cases:
array = [0] * n
for query in queries:
if query[0] == 1:
x, y = query[1] - 1, query[2]
array[x] += y
elif query[0] == 2:
l, r = query[1] - 1, quer... | def test_process_queries():
input_data = """2
6 5
2 1 6
1 3 2
2 2 4
1 6 3
2 1 6
4 4
1 2 7
1 1 -4
2 1 4
1 4 10"""
expected_output = [0, 2, 3, 7]
assert solve(input_data) == expected_output
def test_edge_cases():
# A single test case with the smallest inputs
input_data = """1
1 1
2 1 1"... | [
{
"docstring": null,
"function_declaration": "def process_queries(test_cases):",
"function_name": "process_queries",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"parameter_list": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ArrayMaxQuery:\n def __init__(self, n):\n self.n = n\n self.array = [0] * n\n\n def add(self, x, y):\n self.array[x - 1] +... | trial_gpt4o_2 | {
"original_instruction": "You are provided with a sequence of integers and you need to answer a series of queries. The types of queries are:\n\n1. \"1 x y\": Add the value y to the element at index x (1-based indexing).\n2. \"2 l r\": Return the maximum value in the subarray from index l to index r (inclusive).\n\nY... | 0.624388 | Code_Contests_37254 | C | [
"process_queries",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"parse_input"
],
[
"solve",
"process_queries"
]
] | 2 | [
"process_queries",
"parse_input"
] | false | [] | false | pytest | false | [] | true | 1f2cccaef11b2ef6ed933175ca56884f41e2704d | e24fb8f93024a36766a9ee022d5b3bdb334eda2f | |||
v1.0 | complete | Code_Contests | Code_Contests_36918_C | def calculate_max_team_strength(n: int, employees_skills: List[List[int]]) -> int:
"""
Returns the maximum possible team strength by selecting two employees.
:param n: Number of employees
:param employees_skills: A list of lists, where each list contains the skills of an employee
:return: Maximum p... | def max_team_strength(n, skill_sets):
"""
Returns the maximum possible team strength by selecting two employees.
:param n: Number of employees
:param skill_sets: A list of sets, each containing the skill IDs of each employee
:return: Maximum possible team strength
"""
max_strength = 0
... | from solution import calculate_max_team_strength
def test_example_1():
n = 3
employees_skills = [
[3, 1, 2, 3],
[3, 2, 4, 5],
[2, 3, 5]
]
assert calculate_max_team_strength(n, employees_skills) == 5
def test_example_2():
n = 4
employees_skills = [
[2, 1, 2],
... | [
{
"docstring": "Returns the maximum possible team strength by selecting two employees.\n\n:param n: Number of employees\n:param skill_sets: A list of sets, each containing the skill IDs of each employee\n:return: Maximum possible team strength",
"function_declaration": "def max_team_strength(n, skill_sets):... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_team_strength(n, employees):\n \"\"\"\n Returns the maximum team strength by selecting two employees which\n is determined by the number o... | trial_gpt4o_1 | {
"original_instruction": "A company is organizing a team-building event for its employees. Each employee can form a team with any other employee if they share at least one common skill. The team's strength is determined by the number of unique skills possessed by the team members.\n\nYour task is to find out the max... | 0.638245 | Code_Contests_36918 | C | [
"max_team_strength",
"calculate_max_team_strength"
] | 2 | [
[
"calculate_max_team_strength",
"max_team_strength"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0f85fc806d38ca5dde5f15a104f6978e6699dc25 | 803893eaa134a5da56f7a58c74d9ce64bbaac68f | |||
v1.0 | complete | Code_Contests | Code_Contests_36490_C | from collections import defaultdict
import bisect
def dfs(node, parent, adj_list, node_values, subtree_nodes):
"""
Performs a depth-first search to collect all nodes in each subtree.
"""
subtree_nodes[node].append(node_values[node-1])
for neighbor in adj_list[node]:
if neighbor != parent:
... | from collections import defaultdict
import bisect
def dfs(node, parent, adj_list, node_values, subtree_nodes):
"""
Performs a depth-first search to collect all nodes in each subtree.
"""
subtree_nodes[node].append(node_values[node-1])
for neighbor in adj_list[node]:
if neighbor != parent:
... | from solution import dfs, kth_smallest_in_subtree, process_queries
def test_dfs():
n = 5
node_values = [5, 1, 4, 2, 3]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
adj_list = defaultdict(list)
for u, v in edges:
adj_list[u].append(v)
adj_list[v].append(u)
subtree_nodes = defaultdict... | [
{
"docstring": "Performs a depth-first search to collect all nodes in each subtree.",
"function_declaration": "def dfs(node, parent, adj_list, node_values, subtree_nodes):",
"function_name": "dfs",
"parameter_list": "(node, parent, adj_list, node_values, subtree_nodes)"
},
{
"docstring": "Re... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef dfs_subtree(node, parent, tree, values, subtree_values):\n subtree_values[node].append(values[node-1])... | trial_gpt4o_1 | {
"original_instruction": "You are given a tree with n nodes, rooted at node 1. The nodes are numbered from 1 to n. Each node i has a value vi. A tree is a connected acyclic graph.\n\nA query is a pair (u, k) which means you need to find the k-th smallest value in the subtree of node u. The subtree of a node u is the... | 0.547244 | Code_Contests_36490 | C | [
"dfs",
"kth_smallest_in_subtree",
"process_queries"
] | 3 | [
[
"process_queries",
"dfs"
],
[
"process_queries",
"kth_smallest_in_subtree"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 29e1c74fd5cd481f735b5f8d4ea61d5a81300bd3 | ada63c6ac3524f080eaac5677fca9833a10033be | |||
v1.0 | complete | Code_Contests | Code_Contests_37392_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def hasPathSum(root: TreeNode, targetSum: int) -> bool:
""" Determine if there is a root-to-leaf path in the binary tree such that
the sum of the values along the pa... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def hasPathSum(root: TreeNode, targetSum: int) -> bool:
if not root:
return False
if not root.left and not root.right:
return root.val == targetSum
... | def test_example_1():
n = 5
values = [5, 4, 8, 11, 13]
left_indices = [2, 4, 0, 0, 0]
right_indices = [3, 5, 0, 0, 0]
targetSum = 22
result = solution(n, values, left_indices, right_indices, targetSum)
assert result == "Yes"
def test_example_2():
n = 3
values = [1, 2, 3]
left_in... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef... | trial_gpt4o_4 | {
"original_instruction": "You are given a binary tree and you need to find if there exists a root-to-leaf path such that adding up all the values along the path equals a given sum. A leaf is defined as a node with no children.\n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 105) — the number of nodes in th... | 0.654586 | Code_Contests_37392 | C | [
"hasPathSum",
"build_tree",
"solution"
] | 3 | [
[
"solution",
"build_tree"
],
[
"solution",
"hasPathSum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | df0043bdc2abe4cac7e807e7dc47327f6ce44b05 | 73d98d9bb58241a902f0112a2ffb71646d48db24 | |||
v1.0 | complete | Code_Contests | Code_Contests_37552_C | from typing import List, Tuple
def find_lcm(n: int, relations: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Determines the lowest common manager (LCM) for any two given employees in the company.
Args:
n: int - the number of employees in the company.
relations: List[Tupl... | from collections import defaultdict, deque
def preprocess(n, edges):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Depth and parent tracking
depth = {}
parent = {}
def bfs(root):
queue = deque([(root, 0)]) # (node, curre... | from solution import find_lcm
def test_example_case():
n = 7
relations = [
(1, 2),
(1, 3),
(2, 4),
(2, 5),
(3, 6),
(3, 7),
(2, 8)
]
queries = [(5, 8)]
assert find_lcm(n, relations, queries) == [2]
def test_single_node():
n = 1
relatio... | [
{
"docstring": null,
"function_declaration": "def preprocess(n, edges):",
"function_name": "preprocess",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def lca(parent, depth):",
"function_name": "lca",
"parameter_list": "(parent, depth)"
},
{
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass LowestCommonManagerFinder:\n def __init__(self, n, edges):\n self.n = n\n self.tree = ... | trial_gpt4o_2 | {
"original_instruction": "A company has a hierarchy of employees working under a strict reporting structure. Each employee has a unique identification number, with the company CEO having the ID 1. Every other employee reports to exactly one manager, directly or indirectly, creating a hierarchical (tree-like) structu... | 0.527275 | Code_Contests_37552 | C | [
"preprocess",
"lca",
"find_lcm"
] | 3 | [
[
"find_lcm",
"lca"
],
[
"find_lcm",
"preprocess"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ac4b613f2152e06019d259364862a7633f887342 | 2658995583756281a36c6bc6b2e980b4694d0e0b | |||
v1.0 | complete | Code_Contests | Code_Contests_37103_C | def max_area_of_water_reservoir(heights):
"""Calculate the maximum area of water that can be contained within the given heights.
Args:
heights (List[int]): A list of integers representing the heights of columns.
Returns:
int: The maximum area of water that can be contained.
Examples:
>>> ... | def max_area_of_water_reservoir(heights):
"""
Calculate the maximum area of water that can be contained within the given heights.
"""
left = 0
right = len(heights) - 1
max_area = 0
while left < right:
height = min(heights[left], heights[right])
width = right - left
... | from solution import max_area_of_water_reservoir, solve, parse_input
def test_max_area_of_water_reservoir():
assert max_area_of_water_reservoir([1, 8, 6, 2, 5, 4, 8, 3, 7]) == 49
assert max_area_of_water_reservoir([1, 1, 1, 1, 1]) == 4
assert max_area_of_water_reservoir([1, 2, 1]) == 2
assert max_area_... | [
{
"docstring": "Calculate the maximum area of water that can be contained within the given heights.",
"function_declaration": "def max_area_of_water_reservoir(heights):",
"function_name": "max_area_of_water_reservoir",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_decla... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_water_area(heights):\n \"\"\"\n Calculates the maximum area of a rectangular water reservoir that can be \n formed between two columns in ... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers which represent the heights of columns of different widths placed side by side. The width of each column is 1 unit. Calculate the maximum area of a rectangular water reservoir that can be formed within the bounds of these columns, assuming water extends hori... | 0.681394 | Code_Contests_37103 | C | [
"max_area_of_water_reservoir",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"max_area_of_water_reservoir"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | aa864b63023693b3395ee2525d8b37d67b8936ef | 45b22cf410bb720895cdd7846daad9d4fdc54790 | |||
v1.0 | complete | Code_Contests | Code_Contests_38153_C | def maximalRectangleArea(grid: List[str]) -> int:
""" Determine the area of the largest possible rectangle that can be built without containing any rocks in a given grid.
>>> maximalRectangleArea(["..#", ".#."])
2
>>> maximalRectangleArea(["....", "..#.", "....", "#..."])
6
>>> maximalRectangleA... | def maximalRectangleArea(grid):
if not grid or not grid[0]:
return 0
n = len(grid)
m = len(grid[0])
heights = [0] * m
max_area = 0
for row in grid:
for j in range(m):
heights[j] = heights[j] + 1 if row[j] == '.' else 0
max_area = max(max_area, largestRectan... | from solution import maximalRectangleArea
def test_simple_case():
grid = [
"..#",
".#."
]
assert maximalRectangleArea(grid) == 2
def test_larger_case():
grid = [
"....",
"..#.",
"....",
"#..."
]
assert maximalRectangleArea(grid) == 6
def test_fu... | [
{
"docstring": null,
"function_declaration": "def maximalRectangleArea(grid):",
"function_name": "maximalRectangleArea",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleInHistogram(heights):",
"function_name": "largestRectangleInHistogr... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_area(grid):\n def max_histogram_area(heights):\n stack = []\n max_area = 0\n i = 0\n while i < len(hei... | trial_gpt4o_2 | {
"original_instruction": "Farmer John needs to build a new barn on his farm, but he has some constraints. The farm is represented as an n x m grid, with each cell either containing a rock or being empty. Farmer John wants to build the barn in such a way that it forms a rectangular area on the grid which is free of a... | 0.675915 | Code_Contests_38153 | C | [
"maximalRectangleArea",
"largestRectangleInHistogram"
] | 2 | [
[
"maximalRectangleArea",
"largestRectangleInHistogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef6dc16add517a928bed1ee4273750cd8f6b9ae2 | 5be06853408e053f3da1f8fc4c4e9f2e1bb54320 | |||
v1.0 | complete | Code_Contests | Code_Contests_37140_C | from typing import List
def is_path_possible(grid: List[List[str]]) -> str:
"""
Determines if there is a path from the top-left corner to the bottom-right corner in a 2D grid.
Args:
grid (list of list of str): A 2D list where each element is either '.' (empty space) or '#' (wall).
Returns... | def is_path_possible(grid):
"""
Determines if there is a path from the top-left corner to the bottom-right corner in a 2D grid.
Args:
grid (list of list of str): A 2D list where each element is either '.' (empty space) or '#' (wall).
Returns:
str: 'possible' if a path exists, 'impossib... | import pytest
from solution import is_path_possible, check_path
def test_example_1():
n = 4
m = 4
grid_lines = [
"..#.",
".#..",
"....",
"..#."
]
assert check_path(n, m, grid_lines) == "possible"
def test_example_2():
n = 3
m = 3
grid_lines = [
"... | [
{
"docstring": "Determines if there is a path from the top-left corner to the bottom-right corner in a 2D grid.\n\nArgs:\ngrid (list of list of str): A 2D list where each element is either '.' (empty space) or '#' (wall).\n\nReturns:\nstr: 'possible' if a path exists, 'impossible' otherwise.",
"function_dec... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_path_possible(n, m, grid):\n directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n \n def is_valid(x, y):\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid with N rows and M columns, where each cell contains either a '#' character representing a wall or a '.' character representing an empty space. Your task is to determine if there exists a path to navigate from the top-left corner of the grid (1,1) to the bottom-right cor... | 0.601434 | Code_Contests_37140 | C | [
"is_path_possible",
"check_path"
] | 2 | [
[
"check_path",
"is_path_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c646275daa741500564f72a650a0a417215c9c40 | ffe97091af74d64a405654fa79cece288fe47433 | |||
v1.0 | complete | Code_Contests | Code_Contests_36731_C | class SeatingArea:
def __init__(self, name, number_of_seats):
self.name = name
self.number_of_seats = number_of_seats
class Restaurant:
def __init__(self, name, width, height):
self.name = name
self.width = width
self.height = height
self.seating_areas... | class SeatingArea:
def __init__(self, name, number_of_seats):
self.name = name
self.number_of_seats = number_of_seats
class Restaurant:
def __init__(self, name, width, height):
self.name = name
self.width = width
self.height = height
self.seating_areas = {}
... | def test_seating_capacity_example_case():
n = 7
instructions = [
"Restaurant main_dining(20,20)",
"Table t1(4)",
"Booth b1(6)",
"Stool s1(2)",
"main_dining.add_seating(t1,5,5)",
"main_dining.add_seating(b1,5,5)",
"main_dining.add_seating(s1,2,2)"
]
... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class SeatingArea:\n def __init__(self, name, number_of_seats):\n self.name = name\n self.number_of_seats = number_of_seats\n\n\nclass Res... | trial_gpt4o_0 | {
"original_instruction": "A chef is planning to open a new restaurant chain and wants to make sure that the seating capacity of each restaurant meets the local regulations. The seating capacity is determined by various seating areas: tables, booths, and bar stools. Each area has a different seat allocation, and they... | 0.4837 | Code_Contests_36731 | C | [
"parse_instruction",
"seating_capacity"
] | 2 | [
[
"seating_capacity",
"parse_instruction"
]
] | 1 | [] | false | [
"SeatingArea",
"Restaurant"
] | true | pytest | false | [] | true | 5139ed8abada7f27d8870a40624c581309f8dfc9 | a2e0f034aa6eaa10390bb7bc8821118b81c1a5ac | |||
v1.0 | complete | Code_Contests | Code_Contests_37848_C | def construct_sequence_t(S):
"""
Construct the sequence T from the sequence S based on the following rules:
- If Si is a prime number, Ti is the sum of Si and the largest prime number less than or equal to Si.
- If Si is not a prime, Ti is equal to Si divided by the smallest prime factor of Si.
:pa... | def sieve(n):
"""
Return array of smallest prime factor (spf) for every number <= n.
spf[i] will return the smallest prime factor of i.
"""
spf = list(range(n + 1)) # initialize spf array
for i in range(2, int(n**0.5) + 1):
if spf[i] == i: # i is a prime number
for j in range... | from solution import process_sequence
def test_sample_input1():
assert process_sequence([4, 5, 12, 11, 25]) == [2, 10, 6, 22, 5]
def test_sample_input2():
assert process_sequence([3, 8, 6, 2]) == [6, 4, 3, 4]
def test_prime_numbers():
assert process_sequence([13, 17, 19]) == [26, 34, 38]
def test_non_pr... | [
{
"docstring": "Return array of smallest prime factor (spf) for every number <= n.\nspf[i] will return the smallest prime factor of i.",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": "Return the largest prime number which <= n us... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "Pasha is fascinated with prime numbers and has decided to play a game involving primes and sequences. He starts with a sequence of integers S of length n. He wants to create a new sequence T of the same length where each element Ti is derived from Si as follows:\n\n- If Si is a prime number... | 0.604599 | Code_Contests_37848 | C | [
"sieve",
"largest_prime_leq",
"construct_sequence_t",
"process_sequence"
] | 4 | [
[
"construct_sequence_t",
"largest_prime_leq"
],
[
"construct_sequence_t",
"sieve"
],
[
"process_sequence",
"construct_sequence_t"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 3142a87cf93504b11cf8136f2bc27c76f9e83c25 | 3c8cb3f6b692c67fcf454cd08468b4059909d104 | |||
v1.0 | complete | Code_Contests | Code_Contests_38101_C | def minimum_spanning_tree(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Compute the minimum cost required to construct the spanning tree.
>>> minimum_spanning_tree(4, [(0, 1, 1), (0, 2, 2), (0, 3, 3), (1, 2, 4), (2, 3, 5)])
6
>>> minimum_spanning_tree(3, [(0, 1, 2), (0, 2, 3), (1, 2, 1)])
3... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < rank[root_y]:
parent... | from solution import minimum_spanning_tree
def test_example_1():
n = 4
edges = [
(0, 1, 1),
(0, 2, 2),
(0, 3, 3),
(1, 2, 4),
(2, 3, 5),
]
assert minimum_spanning_tree(n, edges) == 6
def test_example_2():
n = 3
edges = [
(0, 1, 2),
(0, 2, ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_8 | {
"original_instruction": "In a certain country, there are N cities connected by M bidirectional roads. Each road connects two cities and has a certain travel cost associated with it. The government has decided to improve the connectivity of the cities by turning them into a more connected network. They have decided ... | 0.774717 | Code_Contests_38101 | C | [
"find",
"union",
"minimum_spanning_tree",
"main"
] | 4 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 43f3a3eeb04824b1d1c7bad4f5e3a158fa471c98 | e11d427746e3c8e24f2a0eadce3739e9f343360b | |||
v1.0 | complete | Code_Contests | Code_Contests_38291_C | def is_palindrome(n: int) -> bool:
""" Check if a given integer n is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(131)
True
>>> is_palindrome(11)
True
>>> is_palindrome(12321)
True
>>> is_palindrome(123321)
True
"""
... | def is_palindrome(n):
"""
Check if a given integer n is a palindrome.
"""
return str(n) == str(n)[::-1]
def next_palindrome(n):
"""
Find the smallest palindrome greater than the given integer n.
"""
while True:
n += 1
if is_palindrome(n):
return n | from solution import is_palindrome, next_palindrome
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(131) == True
assert is_palindrome(11) == True
assert is_palindrome(12321) == True
assert is_palindrome(123321) == True
def tes... | [
{
"docstring": "Check if a given integer n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest palindrome greater than the given integer n.",
"function_declaration": "def next_p... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n \"\"\"\n Check if a number is a palindrome\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef next_palindrome(N):\n ... | trial_gpt4o_2 | {
"original_instruction": "Create a program that determines the smallest palindrome greater than a given integer.\n\nA palindrome is a number that reads the same backward as forward. Given a positive integer N, your task is to find the smallest integer greater than N that is also a palindrome.\n\nInput\n\nThe input c... | 0.738895 | Code_Contests_38291 | C | [
"is_palindrome",
"next_palindrome"
] | 2 | [
[
"next_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65825f3cadbc615a356da4ee512236c410a6c46c | bc9d49b08465797b5deaedec264f4c1350032554 | |||
v1.0 | complete | Code_Contests | Code_Contests_38322_C | from typing import List
def is_prime(num: int) -> bool:
"""
Checks if a number is prime.
"""
pass
def find_smallest_prime_greater_than(n: int) -> int:
"""
Finds the smallest prime number greater than n.
"""
pass
def smallest_primes_greater_than_cases(t: int, cases: List[int]) -> List[... | import math
def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import is_prime, find_smallest_prime_greater_than, smallest_primes_greater_than_cases
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(29)
assert not is_prime(35)
def test_find_smallest_prime_greater_than():
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest prime number greater than n.",
"function_declaration": "def find_smallest_prime_greater_than(n):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "Miranda has a fascination with prime numbers. She recently came up with a game where she tries to find the smallest prime number greater than a given number. However, she wants your help to automate this process, as the game becomes tedious when dealing with large numbers.\n\nYour task is t... | 0.726143 | Code_Contests_38322 | C | [
"is_prime",
"find_smallest_prime_greater_than",
"smallest_primes_greater_than_cases"
] | 3 | [
[
"find_smallest_prime_greater_than",
"is_prime"
],
[
"smallest_primes_greater_than_cases",
"find_smallest_prime_greater_than"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1c1d526863e967533d2e3122b31cead231b6625a | bcf6e1b5c5c4262bdcf4810d798cd4b730f027dd | |||
v1.0 | complete | Code_Contests | Code_Contests_38299_C | MOD = 1000000007
def compute_fibonacci_up_to(n):
"""Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007."""
fib = [0] * (n + 1)
if n > 0:
fib[1] = 1
for i in range(2, n + 1):
fib[i] = (fib[i-1] + fib[i-2]) % MOD
return fib
def get_nth_fibonacci(numbers):
... | MOD = 1000000007
def compute_fibonacci_up_to(n):
"""Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007."""
fib = [0] * (n + 1)
if n > 0:
fib[1] = 1
for i in range(2, n + 1):
fib[i] = (fib[i-1] + fib[i-2]) % MOD
return fib
def get_nth_fibonacci(numbers):
... | from solution import get_nth_fibonacci
def test_single_case():
assert get_nth_fibonacci([0]) == [0]
assert get_nth_fibonacci([1]) == [1]
def test_multiple_cases():
assert get_nth_fibonacci([0, 1, 2, 3, 10]) == [0, 1, 1, 2, 55]
def test_large_number():
result = get_nth_fibonacci([1000000])
# We wo... | [
{
"docstring": "Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007.",
"function_declaration": "def compute_fibonacci_up_to(n):",
"function_name": "compute_fibonacci_up_to",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_nth_fib... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef compute_fibonacci_up_to(n):\n \"\"\"Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007.\"\"\"\n fi... | trial_gpt4o_0 | {
"original_instruction": "Marc loves playing with numbers, especially finding interesting sequences. He recently stumbled upon the Fibonacci sequence and now wants your help to determine specific values from it!\n\nYour task is to find the n-th Fibonacci number for multiple test cases. Since the Fibonacci numbers ca... | 0.770293 | Code_Contests_38299 | C | [
"compute_fibonacci_up_to",
"get_nth_fibonacci"
] | 2 | [
[
"get_nth_fibonacci",
"compute_fibonacci_up_to"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ea9beba03ca0a54531fd59a9b8f1b12298d49ff | 2b19a78ba8fb99af74a9f66171759d2e73203c9a | |||
v1.0 | complete | Code_Contests | Code_Contests_37851_C | from typing import List, Tuple
def find_shortest_path(n: int, cities: List[str], m: int, paths: List[Tuple[str, str, int]], start: str, end: str) -> int:
""" Determines the shortest path between two cities using Dijkstra's Algorithm.
>>> n = 5
>>> cities = ['CityA', 'CityB', 'CityC', 'CityD', 'CityE']
... | import heapq
def dijkstra(graph, start, end):
"""
Determines the shortest path between two cities using Dijkstra's Algorithm.
"""
queue = [(0, start)]
distances = {node: float('infinity') for node in graph}
distances[start] = 0
while queue:
current_distance, current_node = heapq.he... | from solution import find_shortest_path
def test_case_1():
n = 5
cities = ['CityA', 'CityB', 'CityC', 'CityD', 'CityE']
m = 6
paths = [
('CityA', 'CityB', 4),
('CityA', 'CityC', 2),
('CityB', 'CityC', 5),
('CityB', 'CityD', 10),
('CityC', 'CityE', 3),
('C... | [
{
"docstring": "Determines the shortest path between two cities using Dijkstra's Algorithm.",
"function_declaration": "def dijkstra(graph, start, end):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, end)"
},
{
"docstring": null,
"function_declaration": "def find_shortes... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, cities, m, paths, source, destination):\n # Creating an adjacency list for the cities and paths\n graph = {city: [] f... | trial_gpt4o_2 | {
"original_instruction": "Given a list of cities and distances between some pairs of them, your task is to determine the shortest path between two specified cities using Dijkstra's algorithm. \n\n### Input\n\nThe input starts with a line containing an integer `n` (2 ≤ n ≤ 1000), the number of cities. The next `n` li... | 0.709904 | Code_Contests_37851 | C | [
"dijkstra",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1b0dfbca737062308600888784cb6735f94bae70 | c4c0fb14b9c072b67ee9659f8325ae10b16b7a35 | |||
v1.0 | complete | Code_Contests | Code_Contests_36639_C | def is_valid_sudoku(grid: List[List[int]]) -> str:
""" Check if a Sudoku grid is valid.
>>> is_valid_sudoku([
... [5, 3, 4, 6, 7, 8, 9, 1, 2],
... [6, 7, 2, 1, 9, 5, 3, 4, 8],
... [1, 9, 8, 3, 4, 2, 5, 6, 7],
... [8, 5, 9, 7, 6, 1, 4, 2, 3],
... [4, 2, 6, 8, 5, 3, 7, 9, 1],
... [7, 1, 3,... | def is_valid_sudoku(grid):
def is_valid_block(block):
return sorted(block) == list(range(1, 10))
def get_column(grid, col_idx):
return [grid[row_idx][col_idx] for row_idx in range(9)]
def get_subgrid(grid, start_row, start_col):
return [grid[r][c] for r in range(start_row, ... | from solution import is_valid_sudoku, sudoku_validator
def test_valid_sudoku():
grid = [
[5, 3, 4, 6, 7, 8, 9, 1, 2],
[6, 7, 2, 1, 9, 5, 3, 4, 8],
[1, 9, 8, 3, 4, 2, 5, 6, 7],
[8, 5, 9, 7, 6, 1, 4, 2, 3],
[4, 2, 6, 8, 5, 3, 7, 9, 1],
[7, 1, 3, 9, 2, 4, 8, 5, 6],
... | [
{
"docstring": null,
"function_declaration": "def is_valid_sudoku(grid):",
"function_name": "is_valid_sudoku",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def sudoku_validator(T, grids):",
"function_name": "sudoku_validator",
"parameter_list": "(T,... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_sudoku(grid):\n def is_valid_block(block):\n return sorted(block) == list(range(1, 10))\n \n for i in range(9):\n row =... | trial_gpt4o_1 | {
"original_instruction": "Write a program that helps you to verify if your Sudoku solution is correct.\n\nA Sudoku puzzle consists of a 9x9 grid, divided into nine 3x3 subgrids. The objective is to fill the grid with numbers from 1 to 9 so that each row, each column, and each 3x3 subgrid contains all nine digits.\n\... | 0.603527 | Code_Contests_36639 | C | [
"is_valid_sudoku",
"sudoku_validator"
] | 2 | [
[
"sudoku_validator",
"is_valid_sudoku"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 52eb33cd28c310730fd2c02a0104895ad7f4e519 | 004875978dd914f0489a184f9fd917fd641d3f07 | |||
v1.0 | complete | Code_Contests | Code_Contests_37721_C | def generate_special_sequence(N: int) -> List[int]:
""" Generates a special sequence of length N.
A sequence of integers is called a "special sequence" if it satisfies the following conditions:
1. Every pair of consecutive integers in the sequence have a difference of either 1 or -1.
2. The sequence do... | def generate_special_sequence(N):
if N == 1:
return [0]
elif N == 2:
return [0, -1]
elif N < 1 or N > 1000:
return -1 # This should never happen given the problem constraints.
special_sequence = []
# For odd and even length
base_pattern_odd = [-1, 0, 1]
base_pattern... | from solution import generate_special_sequence
def test_generate_special_sequence_1():
assert generate_special_sequence(1) == [0]
def test_generate_special_sequence_2():
assert generate_special_sequence(2) == [0, -1]
def test_generate_special_sequence_3():
assert generate_special_sequence(3) == [-1, 0, 1... | [
{
"docstring": null,
"function_declaration": "def generate_special_sequence(N):",
"function_name": "generate_special_sequence",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def format_sequence(sequence):",
"function_name": "format_sequence",
"parameter... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_special_sequence(N):\n if N == 1:\n return [1]\n \n sequence = []\n for i in range(N):\n if i % 2 == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "A sequence of integers is called a \"special sequence\" if it satisfies the following conditions:\n1. Every pair of consecutive integers in the sequence have a difference of either 1 or -1.\n2. The sequence does not contain a positive integer followed immediately by a different positive int... | 0.702614 | Code_Contests_37721 | C | [
"generate_special_sequence",
"format_sequence",
"process_input"
] | 3 | [
[
"process_input",
"format_sequence"
],
[
"process_input",
"generate_special_sequence"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | ef18fa9079b0c39be61cda329735a3666eccb336 | e7db71f0f34a67ec14bb9a959f35d93fc9e82f0b | |||
v1.0 | complete | Code_Contests | Code_Contests_37919_C | def is_prime(n: int) -> bool:
""" Returns True if n is a prime number, otherwise False.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(1) == False
>>> is_prime(0) == False
>>> is_prime(-1) == False
>>> is_prime(17) == Tru... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, sum_of_primes_in_list, sum_of_primes_in_testcases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == F... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers in the given list.",
"function_declaration": "def sum_of_primes_in_... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n... | trial_gpt4o_0 | {
"original_instruction": "Maria has a list of integers and she wants to know the sum of the prime numbers in the list. Can you help her find the answer for each list she provides?\n\nINPUT:\n\nThe first line contains the number of testcases T, followed by T sections. Each section starts with an integer L representin... | 0.759494 | Code_Contests_37919 | C | [
"is_prime",
"sum_of_primes_in_list",
"sum_of_primes_in_testcases"
] | 3 | [
[
"sum_of_primes_in_list",
"is_prime"
],
[
"sum_of_primes_in_testcases",
"sum_of_primes_in_list"
]
] | 2 | [
"sum_of_primes_in_testcases"
] | false | [] | false | pytest | true | [] | true | 150139b4964f06adbf4c9a3aa23b1e2674730a49 | 0573c41b73989c2382207c72045d1706d23f412d | |||
v1.0 | complete | Code_Contests | Code_Contests_37540_C | from typing import List
def largest_rectangular_subgrid(R: int, C: int, grid: List[str]) -> int:
"""Given a grid with R rows and C columns where each cell is either '0' or '1',
determine the area of the largest rectangular sub-grid that contains only '1's.
>>> largest_rectangular_subgrid(4, 5, ["1010... | def largestRectangleArea(heights):
stack, max_area = [], 0
heights.append(0)
for i, height in enumerate(heights):
while stack and height < heights[stack[-1]]:
h = heights[stack.pop()]
w = i if not stack else i - stack[-1] - 1
max_area = max(max_area, h * w)
... | from solution import largest_rectangular_subgrid
def test_example_1():
R = 4
C = 5
grid = ["10100", "10111", "11111", "10010"]
assert largest_rectangular_subgrid(R, C, grid) == 6
def test_example_2():
R = 3
C = 3
grid = ["111", "111", "111"]
assert largest_rectangular_subgrid(R, C, gri... | [
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maxRectangleArea(R, C, grid):\n if R == 0 or C == 0:\n return 0\n\n def maximal_histogram_area(histogram):\n stack = []\n ma... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular grid with R rows and C columns. Each cell in the grid can either be occupied or empty, represented by '1' and '0' respectively.\n\nA sub-grid is any rectangular section of the grid obtained by selecting a contiguous block of cells.\n\nYour task is to determine th... | 0.574506 | Code_Contests_37540 | C | [
"largestRectangleArea",
"maximalRectangle",
"largest_rectangular_subgrid"
] | 3 | [
[
"largest_rectangular_subgrid",
"maximalRectangle"
],
[
"maximalRectangle",
"largestRectangleArea"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8c308b4d21cd79d3fd9de67c6cdaa54092852f60 | 9141b3358713a5596eac25a4012e4e079518399d | |||
v1.0 | complete | Code_Contests | Code_Contests_37906_C | from typing import List
def is_prime(num: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(29) == True
>>> is_prime(1) == False
>>> is_prime(0) == False
>>> is_prime(-... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def fibonacci_primes(limit):
... | from solution import is_prime, fibonacci_primes, precompute_fibonacci_primes, solve_fibonacci_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
asse... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def fibonacci_primes(limit):",
"function_name": "fibonacci_primes",
"parameter_list": "(limit)"
},
{
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sieve(n):\n \"\"\"Returns a list of primes ≤ n using the Sieve of Eratosthenes.\"\"\"\n is_prime = [True] * (n + 1)\n ... | trial_gpt4o_4 | {
"original_instruction": "John loves playing with numbers, especially finding interesting properties among them. His math teacher recently introduced him to the concept of Fibonacci prime numbers. A Fibonacci prime is a number that is both a Fibonacci number and a prime number. John gets really excited by this and w... | 0.855399 | Code_Contests_37906 | C | [
"is_prime",
"fibonacci_primes",
"precompute_fibonacci_primes",
"solve_fibonacci_primes",
"main"
] | 5 | [
[
"fibonacci_primes",
"is_prime"
],
[
"precompute_fibonacci_primes",
"fibonacci_primes"
],
[
"solve_fibonacci_primes",
"precompute_fibonacci_primes"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 34fd259679199499cdbd827fd6527d7ca7a9e8cf | aa94051942bdbccd3633d1a83b7226a8e75cc9e6 | |||
v1.0 | complete | Code_Contests | Code_Contests_38428_C | def length_of_LIS(s: str) -> int:
""" Finds length of longest increasing subsequence in a string, s.
>>> length_of_LIS("abc")
3
>>> length_of_LIS("abacaba")
3
>>> length_of_LIS("a")
1
>>> length_of_LIS("edcba")
1
"""
pass
def max_sum_of_LIS(n: int, k: int, s: str) -> int:
... | import bisect
def length_of_LIS(s):
"""
Finds length of longest increasing subsequence in a string, s.
"""
lis = []
for char in s:
pos = bisect.bisect_left(lis, char)
if pos == len(lis):
lis.append(char)
else:
lis[pos] = char
return len(lis)
def ... | from solution import length_of_LIS, max_sum_of_LIS
def test_length_of_LIS():
assert length_of_LIS("abc") == 3
assert length_of_LIS("abacaba") == 3
assert length_of_LIS("a") == 1
assert length_of_LIS("edcba") == 1
def test_max_sum_of_LIS_example():
assert max_sum_of_LIS(7, 3, "abacaba") == 5
def t... | [
{
"docstring": "Finds length of longest increasing subsequence in a string, s.",
"function_declaration": "def length_of_LIS(s):",
"function_name": "length_of_LIS",
"parameter_list": "(s)"
},
{
"docstring": "Finds the maximum possible sum of lengths of LIS among all k substrings.",
"funct... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def length_of_lis(s):\n \"\"\" Helper function to calculate the length of the longest increasing subsequence in s \"\"\"\n if not s:\n return ... | trial_gpt4o_1 | {
"original_instruction": "You are given a string `s` and an integer `k`. You need to split the string into exactly `k` non-empty substrings such that the sum of lengths of the longest increasing subsequence (LIS) among all substrings is maximized. \n\nRecall that a subsequence is a sequence that can be derived from ... | 0.649116 | Code_Contests_38428 | C | [
"length_of_LIS",
"max_sum_of_LIS"
] | 2 | [
[
"max_sum_of_LIS",
"length_of_LIS"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6caaa4747aa33bbd1a195e855dedff636211df3 | 0240fe32481faed29ae764e33c9e1a3a78df5e73 | |||
v1.0 | complete | Code_Contests | Code_Contests_38457_C | def simulate_branching_and_merging(branches, merge_queries):
""" Simulate the branching and merging process and determine the number of conflicts during a merge.
Input:
branches: List[List[str]]: List of branches with their commits.
merge_queries: List[Tuple[int, int]]: List of merge querie... | def simulate_branching_and_merging(branches, merge_queries):
from collections import defaultdict
def count_conflicts(branch1, branch2):
conflict_count = 0
seen_files = {}
for commit in branch1:
file, id_ = commit[0], commit[1:]
if file not in seen_fi... | from solution import simulate_branching_and_merging
def test_merge_no_conflict():
branches = [
["a1", "b1"],
["c1", "d1"]
]
merge_queries = [(1, 2)]
assert simulate_branching_and_merging(branches, merge_queries) == [0]
def test_merge_with_conflict():
branches = [
["a1", "b1... | [
{
"docstring": null,
"function_declaration": "def simulate_branching_and_merging(branches, merge_queries):",
"function_name": "simulate_branching_and_merging",
"parameter_list": "(branches, merge_queries)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_execute():"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_conflicts(branches, merge_queries):\n \"\"\"\n Returns the number of conflicts during the merging of branches based on the queries.\n \n... | trial_gpt4o_2 | {
"original_instruction": "In a software company, developers are using a version control system that supports branching and merging. Each branch is a sequence of commits represented as strings. Occasionally, a developer may need to merge two branches. During a merge, conflicts may arise if both branches have commits ... | 0.462428 | Code_Contests_38457 | C | [
"simulate_branching_and_merging",
"process_input_and_execute"
] | 2 | [
[
"process_input_and_execute",
"simulate_branching_and_merging"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c1ab768ddf16da661b410e9e084cfa1044f5f6c | a0aa323bfc36bba1cf6aa276282ff9ec35d6a632 | |||
v1.0 | complete | Code_Contests | Code_Contests_38621_C | def classify_number(n: int) -> str:
""" Returns whether a given positive integer n is a 'perfect number'
or 'not a perfect number' based on the sum of its divisors.
>>> classify_number(6)
'perfect number'
>>> classify_number(28)
'perfect number'
>>> classify_number(12)
'not a perfect n... | def classify_number(n):
"""
Returns whether a given positive integer n is a 'perfect number'
or 'not a perfect number' based on the sum of its divisors.
"""
if n < 2:
return None
sum_divisors = 0
for i in range(1, n):
if n % i == 0:
sum_divisors += i
... | from solution import classify_number, classify_numbers_from_input
def test_classify_number():
assert classify_number(6) == "perfect number"
assert classify_number(28) == "perfect number"
assert classify_number(12) == "not a perfect number"
assert classify_number(496) == "perfect number"
assert clas... | [
{
"docstring": "Returns whether a given positive integer n is a 'perfect number' \nor 'not a perfect number' based on the sum of its divisors.",
"function_declaration": "def classify_number(n):",
"function_name": "classify_number",
"parameter_list": "(n)"
},
{
"docstring": "Classifies a list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def classify_numbers(numbers):\n \"\"\"\n Classifies each number in the list as a \"perfect number\" or \"not a perfect number\".\n \n Args:\n ... | trial_gpt4o_1 | {
"original_instruction": "Write a program to calculate the sum of all divisors (excluding the number itself) of a given positive integer. If the sum of divisors equals the number, the number is classified as a \"perfect number.\" Otherwise, the program should classify the number as \"not a perfect number.\"\n\nInput... | 0.61017 | Code_Contests_38621 | C | [
"classify_number",
"classify_numbers_from_input"
] | 2 | [
[
"classify_numbers_from_input",
"classify_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7eb346ef5b30164f32e9ef0aa11ea807aa81387e | 6c78f23131bca1dc02087265ccd2e1bd8307600e | |||
v1.0 | complete | Code_Contests | Code_Contests_38941_C | def is_prime(num: int) -> bool:
""" Checks if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def smallest_prime_with_k_divisors(n: int, k: int) -> int:
""" Returns the smallest prime number greater than or equal to n
that has exactly k divisors.
>>> small... | import math
def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import smallest_prime_with_k_divisors
def test_smallest_prime_with_k_divisors_case1():
assert smallest_prime_with_k_divisors(10, 2) == 11
def test_smallest_prime_with_k_divisors_case2():
assert smallest_prime_with_k_divisors(20, 2) == 23
def test_smallest_prime_with_k_divisors_case3():
asse... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than or equal to n\nthat has exactly k divisors.",
"function_declaration": "def... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "Arthur is a lover of prime numbers and their properties. One day, Arthur came across an interesting problem involving prime numbers and divisors. He wants to find the smallest prime number `p` greater than or equal to a given integer `n` such that `p` has exactly `k` divisors.\n\nA prime nu... | 0.731391 | Code_Contests_38941 | C | [
"is_prime",
"smallest_prime_with_k_divisors"
] | 2 | [
[
"smallest_prime_with_k_divisors",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9deff11ddd80f1deba4163503db58c02637e5010 | f1e22926f2211e580facb4ec0fe8ae8bb431abec | |||
v1.0 | complete | Code_Contests | Code_Contests_38726_C | def additional_tunnels_needed(n: int, m: int, s: str, tunnels: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of additional tunnels required to ensure a backup route between each pair of working modules.
>>> additional_tunnels_needed(4, 3, "1101", [(1, 2), (2, 3), (3, 4)]) == 1
>>> addition... | def find_connected_components(graph, n):
visited = [False] * n
components = []
def dfs(node):
stack = [node]
component = []
while stack:
u = stack.pop()
if not visited[u]:
visited[u] = True
component.append(u)
... | def test_additional_tunnels_needed_case1():
assert additional_tunnels_needed(4, 3, "1101", [(1, 2), (2, 3), (3, 4)]) == 1
def test_additional_tunnels_needed_case2():
assert additional_tunnels_needed(5, 4, "11110", [(1, 2), (2, 3), (3, 4), (4, 5)]) == 0
def test_additional_tunnels_needed_no_tunnels():
asse... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(graph, n):",
"function_name": "find_connected_components",
"parameter_list": "(graph, n)"
},
{
"docstring": null,
"function_declaration": "def additional_tunnels_needed(n, m, s, tunnels):",
"function_name": "... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport itertools\n\ndef min_additional_tunnels(n, m, s, edges):\n graph = defaultdict(list)\n working_mod... | trial_gpt4o_3 | {
"original_instruction": "A space station has n modules connected by m bidirectional tunnels (a tunnel directly connects two different modules). Each module can either be working or non-working. \n\nYou need to ensure that there exists a backup route between any two working modules, meaning for every pair of working... | 0.588649 | Code_Contests_38726 | C | [
"find_connected_components",
"additional_tunnels_needed"
] | 2 | [
[
"additional_tunnels_needed",
"find_connected_components"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 00eddcc492c3bc65d5c6adb5222069299bb95018 | a2222f89aa4ebe9b1e2e95d64b01dec18fe8177d | |||
v1.0 | complete | Code_Contests | Code_Contests_38713_C | def delivery_sequence(n: int, destinations: List[Tuple[int, int]]) -> List[int]:
"""
Determine the sequence of delivery indices to minimize the total travel distance of the truck.
>>> delivery_sequence(3, [(2, 3), (-1, 4), (-2, -2)])
[2, 1, 3]
>>> delivery_sequence(4, [(1, 2), (3, 4), (-3, -3), (-1... | def distance(point1, point2):
"""
Calculate Euclidean distance between two points.
"""
return ((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)**0.5
def delivery_sequence(n, destinations):
"""
Determine the sequence to minimize total travel distance.
"""
start = (0, 0) # Wareho... | from solution import delivery_sequence, parse_input, parse_output
def test_example_1():
input_str = "3\n2 3\n-1 4\n-2 -2"
n, destinations = parse_input(input_str)
expected_output = [2, 1, 3]
output = delivery_sequence(n, destinations)
assert set(output) == set(expected_output)
def test_example_2()... | [
{
"docstring": "Calculate Euclidean distance between two points.",
"function_declaration": "def distance(point1, point2):",
"function_name": "distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Determine the sequence to minimize total travel distance.",
"function_declarati... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_distance(x, y):\n return (x**2 + y**2)**0.5\n\ndef find_delivery_sequence(n, coordinates):\n distances = [(i, calculate_distance(x, y))... | trial_gpt4o_8 | {
"original_instruction": "A logistics company needs to schedule the deliveries of packages to multiple destinations. For simplicity, the destinations are given as points on a 2D plane, with the company's warehouse located at the origin (0, 0). The company's delivery truck can only carry one package at a time and alw... | 0.593772 | Code_Contests_38713 | C | [
"distance",
"delivery_sequence",
"parse_input",
"parse_output"
] | 4 | [
[
"delivery_sequence",
"distance"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 02a8c3b93759a3b601369d21ddf46d0c612d3b82 | 9db25155b187253f04b0bc3ae218c67a1ca1016b | |||
v1.0 | complete | Code_Contests | Code_Contests_38807_C | def min_kimmies(n: int) -> int:
""" Returns the minimum number of Kimmies required to pay exactly n amount of taxes.
>>> min_kimmies(6)
2
>>> min_kimmies(10)
3
>>> min_kimmies(14)
4
"""
def process_kimmies_input(input_list: List[int]) -> List[int]:
""" Processes a list of inputs... | def min_kimmies(n):
"""
Returns the minimum number of Kimmies required to pay exactly n amount of taxes.
"""
if n == 0:
return 0
denominations = [1, 3, 4]
dp = [float('inf')] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
for coin in denominations:
if i -... | from solution import min_kimmies, process_kimmies_input
def test_min_kimmies():
assert min_kimmies(6) == 2
assert min_kimmies(10) == 3
assert min_kimmies(14) == 4
assert min_kimmies(1) == 1
assert min_kimmies(0) == 0
assert min_kimmies(5) == 2
def test_process_kimmies_input():
assert proce... | [
{
"docstring": "Returns the minimum number of Kimmies required to pay exactly n amount of taxes.",
"function_declaration": "def min_kimmies(n):",
"function_name": "min_kimmies",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of inputs and returns the results for minimum Kimmies ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_kimmies(N):\n \"\"\"\n Returns the minimum number of Kimmies required to pay exactly N amount of taxes.\n \"\"\"\n \n if N == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "In a distant land, there is a kingdom that uses a unique form of currency called \"Kimmies\". The kingdom has the following denominations of Kimmies: 1, 3, and 4. The king has decreed that every citizen should pay a certain amount, N, in taxes. However, the taxes must be paid using the mini... | 0.575683 | Code_Contests_38807 | C | [
"min_kimmies",
"process_kimmies_input"
] | 2 | [
[
"process_kimmies_input",
"min_kimmies"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6c41202cf298ec23ee195a409662f69c2aab4302 | 05187a9b27c186e3b65fce9f08293b460dec7402 | |||
v1.0 | complete | Code_Contests | Code_Contests_38934_C | def general_river_crossing(n: int, entities: List[str]) -> int:
"""Recreate the river crossing scenario and devise an algorithm to determine
the minimum number of crossings required to get everyone safely to the other
side of the river while adhering to specific constraints.
>>> general_river_crossing(... | def river_crossing(entities):
# Given simplified constraints, the minimum crossings problem can be solved by a generic greedy approach.
n = len(entities)
if n <= 2:
return n
return 2 * (n - 1) - 1
def general_river_crossing(n, entity_info):
return river_crossing(entity_info) | from solution import general_river_crossing
def test_single_entity():
assert general_river_crossing(1, ["person1"]) == 1
def test_two_entities():
assert general_river_crossing(2, ["person1", "animal1"]) == 2
def test_three_entities():
assert general_river_crossing(3, ["person1", "animal1", "person2"]) ==... | [
{
"docstring": null,
"function_declaration": "def river_crossing(entities):",
"function_name": "river_crossing",
"parameter_list": "(entities)"
},
{
"docstring": null,
"function_declaration": "def general_river_crossing(n, entity_info):",
"function_name": "general_river_crossing",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def river_crossing(entities):\n # Given simplified constraints, the minimum crossings problem can be solved by a generic greedy approach.\n n = len(e... | trial_gpt4o_0 | {
"original_instruction": "## River Crossing Puzzle\n\nYou are given a group of people and animals that need to cross a river using a boat. The boat can carry only two entities at a time (either two people, two animals, or one person and one animal). All entities can row the boat, but there are specific constraints t... | 0.590638 | Code_Contests_38934 | C | [
"river_crossing",
"general_river_crossing"
] | 2 | [
[
"general_river_crossing",
"river_crossing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f197396c7808810f6f58951e7f504fa4997cb54 | 1bc9ece26d1fb9078b9d0f0fe1cf76d06cdd48a6 | |||
v1.0 | complete | Code_Contests | Code_Contests_38924_C | def is_prime(num):
"""
Determines if a number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | import math
def is_prime(num):
"""
Determines if a number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return ... | from solution import is_prime, nth_prime_in_sequence
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) ... | [
{
"docstring": "Determines if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines the n-th prime number in the arithmetic sequence defined by a and d.\nReturns -1 if the n-th prime number do... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num < 2:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in ... | trial_gpt4o_1 | {
"original_instruction": "Tanya loves prime numbers. She has recently learned about an interesting property of prime numbers in arithmetic progressions and decided to create a problem around it. Given integers a, d, and n, she defines a sequence as follows:\n\nb_1 = a,\nb_2 = a + d,\nb_3 = a + 2d,\n...\n\nIn other w... | 0.844431 | Code_Contests_38924 | C | [
"is_prime",
"nth_prime_in_sequence"
] | 2 | [
[
"nth_prime_in_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f6da74bfc8473f789c31d2860e8659151ccfadd | 408be02c0c4e98f93dd92e17511e6b6c682ebf94 | |||
v1.0 | complete | Code_Contests | Code_Contests_38892_C | def fill_grid_task(inputs):
""" Determines if a grid can be completely filled with given block types and rotations.
Args:
inputs (list): A list of test cases. Each test case is represented by a tuple containing:
- grid height (int)
- grid width (int)
... | from itertools import product
def rotate(block):
""" Generates all rotations of the block """
rotations = []
current = block
for _ in range(4):
new_block = ["".join(row) for row in zip(*current[::-1])]
if new_block not in rotations:
rotations.append(new_block)
curren... | import pytest
from solution import fill_grid_task
def test_case_1():
inputs = [
(4, 4, 2, [
{'orientations': [["XX", "XX"], ["XX", "XX"]]},
{'orientations': [["X..", "XXX"], ["X..", "XXX"], ["X..", "XXX"]]}
])
]
expected_output = ["Case 1: No"]
assert fill_grid_t... | [
{
"docstring": "Generates all rotations of the block ",
"function_declaration": "def rotate(block):",
"function_name": "rotate",
"parameter_list": "(block)"
},
{
"docstring": "Generates all unique rotations for all blocks ",
"function_declaration": "def generate_orientations(blocks):",
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import product\n\ndef can_fill_grid(H, W, blocks):\n \"\"\"\n Function to determine if the grid can be completely filled with the give... | trial_gpt4o_3 | {
"original_instruction": "In a universe with infinite grids, there exist different types of blocks. Each type of block occupies a different amount of cells and each type of block can be placed in multiple orientations (rotations). You are tasked with determining if it is possible to completely fill a given rectangul... | 0.583165 | Code_Contests_38892 | C | [
"rotate",
"generate_orientations",
"can_fill_grid",
"fill_grid_task"
] | 4 | [
[
"fill_grid_task",
"can_fill_grid"
],
[
"fill_grid_task",
"generate_orientations"
],
[
"generate_orientations",
"rotate"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a581f2226ccf87e178a29ae3d3dd997ca3380b83 | 4098fa6a59f0a1d2a9066406b05524a9557b873f | |||
v1.0 | complete | Code_Contests | Code_Contests_38595_C | from typing import List, Tuple
def can_be_rearranged_to_palindrome(s: str) -> bool:
"""
Check if a string `s` can be rearranged into a palindrome.
"""
# Your code here
def count_rearrangeable_and_non_rearrangeable(s: str, p: int, q: int) -> Tuple[int, int]:
"""
Count substrings of length p tha... | def can_be_rearranged_to_palindrome(s):
"""
Check if a string `s` can be rearranged into a palindrome.
"""
from collections import Counter
count = Counter(s)
odd_count = sum(1 for c in count if count[c] % 2 != 0)
return odd_count <= 1
def count_rearrangeable_and_non_rearrangeable(s, p, q):
... | import pytest
from solution import can_be_rearranged_to_palindrome, count_rearrangeable_and_non_rearrangeable, process_cases
def test_can_be_rearranged_to_palindrome():
assert can_be_rearranged_to_palindrome("aba") == True
assert can_be_rearranged_to_palindrome("abc") == False
assert can_be_rearranged_to_p... | [
{
"docstring": "Check if a string `s` can be rearranged into a palindrome.",
"function_declaration": "def can_be_rearranged_to_palindrome(s):",
"function_name": "can_be_rearranged_to_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Count substrings of length p that can be rearranged i... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef can_form_palindrome(substring):\n \"\"\"\n Check if a given substring can be rearranged into a palindrome.\n ... | trial_gpt4o_6 | {
"original_instruction": "You are given a string s and two integers p and q. Your task is to find the number of substrings of s of length exactly p that can be rearranged into a palindrome, and the number of substrings of s of length exactly q that cannot be rearranged into a palindrome.\n\nA string is considered to... | 0.656089 | Code_Contests_38595 | C | [
"can_be_rearranged_to_palindrome",
"count_rearrangeable_and_non_rearrangeable",
"process_cases"
] | 3 | [
[
"count_rearrangeable_and_non_rearrangeable",
"can_be_rearranged_to_palindrome"
],
[
"process_cases",
"count_rearrangeable_and_non_rearrangeable"
]
] | 2 | [
"process_cases"
] | false | [] | false | pytest | true | [] | true | 4ec22011412c8336da40b025aab7d530120e7a73 | f48e1febeed8b7463cd2806ce575060f33969492 | |||
v1.0 | complete | Code_Contests | Code_Contests_38312_C | def count_paths(grid, n, m):
"""
Vasily has a 2D rectangular grid of dimensions n x m (1 ≤ n, m ≤ 10^3).
Each cell in the grid either contains an obstacle or is empty.
Vasily wants to find the number of distinct paths from the top-left corner of the grid to the bottom-right corner, moving only right ... | def count_paths(grid, n, m):
MOD = 998244353
# dp array - number of ways to reach each cell
dp = [[0] * m for _ in range(n)]
if grid[0][0] == '.' and grid[n-1][m-1] == '.':
dp[0][0] = 1
# Fill dp array
for i in range(n):
for j in range(m):
if grid[i][j]... | from solution import count_paths_from_input
def test_simple_case():
input_data = "4 4\n....\n..#.\n....\n#...\n"
assert count_paths_from_input(input_data) == 10
def test_no_path_case():
input_data = "3 3\n...\n.#.\n..#\n"
assert count_paths_from_input(input_data) == 0
def test_blocked_start():
in... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid, n, m):",
"function_name": "count_paths",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def count_paths_from_input(input_string):",
"function_name": "count_paths_from_input",
"p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_paths(n, m, grid):\n MOD = 998244353\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [[0] * m for _ in ran... | trial_gpt4o_2 | {
"original_instruction": "Vasily has a 2D rectangular grid of dimensions n x m (1 ≤ n, m ≤ 10^3). Each cell in the grid either contains an obstacle or is empty. Vasily wants to find the number of distinct paths from the top-left corner of the grid to the bottom-right corner, moving only right or down at each step, a... | 0.753859 | Code_Contests_38312 | C | [
"count_paths",
"count_paths_from_input"
] | 2 | [
[
"count_paths_from_input",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f714351fdd5e7206f6f2e605ed7d6d93cfe0244 | d7d343b625034be2f41cf639f9c614915cc12f2c | |||
v1.0 | complete | Code_Contests | Code_Contests_38979_C | def minimize_tallest_height(n, m, heights):
"""
Determine the minimum possible height of the tallest column in Emma's garden while ensuring no two adjacent columns have the same height.
Parameters:
n (int): The number of columns.
m (int): The number of possible heights.
heights (List[int]): Th... | def minimize_tallest_height(n, m, heights):
heights = sorted(heights)
if m == 1:
# If there's only one height, that's the only possible height we can choose
return heights[0]
left, right = 0, len(heights) - 1
while left < right:
mid = (left + right) // 2
if... | from solution import minimize_tallest_height
def test_example_1():
assert minimize_tallest_height(5, 3, [1, 3, 5]) == 3
def test_example_2():
assert minimize_tallest_height(4, 4, [8, 3, 9, 6]) == 6
def test_min_heights():
assert minimize_tallest_height(1, 1, [10]) == 10
assert minimize_tallest_height... | [
{
"docstring": null,
"function_declaration": "def minimize_tallest_height(n, m, heights):",
"function_name": "minimize_tallest_height",
"parameter_list": "(n, m, heights)"
},
{
"docstring": null,
"function_declaration": "def can_form_beautiful_garden(n, candidate_heights):",
"functio... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_tallest_column_height(n, m, heights):\n heights = sorted(heights)\n \n if n == 1:\n return min(heights)\n \n min_height = flo... | trial_gpt4o_2 | {
"original_instruction": "Emma is building a garden with exactly n columns of flowers. Each column can have a variable height based on the flowers' growth in that column. Emma wants to ensure that her garden is beautiful by ensuring that no two adjacent columns have the same height. \n\nEmma knows the heights h_1, h... | 0.591971 | Code_Contests_38979 | C | [
"minimize_tallest_height",
"can_form_beautiful_garden"
] | 2 | [
[
"minimize_tallest_height",
"can_form_beautiful_garden"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 278f913710c8cfeeb9cc1bffda8c36727bdc0ee1 | c0d2ecc1a76d0bef5966b5e194b6514d53281b64 | |||
v1.0 | complete | Code_Contests | Code_Contests_38618_C | from typing import List, Tuple
def check_circular_relationships(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[str]:
"""
Determines if there is a cycle in the graph which would indicate a circular following relationship among users.
Args:
T (int): Number of test cases.
... | from collections import defaultdict
def has_cycle(graph, node, visited, recStack):
visited[node] = True
recStack[node] = True
for neighbour in graph[node]:
if not visited[neighbour]:
if has_cycle(graph, neighbour, visited, recStack):
return True
elif recStack[ne... | import pytest
from solution import check_circular_relationships
def test_single_cycle():
T = 1
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)])
]
assert check_circular_relationships(T, test_cases) == ["YES"]
def test_multiple_cycles():
T = 1
test_cases = [
(4, 4, [(1, 2), (2, 3)... | [
{
"docstring": null,
"function_declaration": "def has_cycle(graph, node, visited, recStack):",
"function_name": "has_cycle",
"parameter_list": "(graph, node, visited, recStack)"
},
{
"docstring": null,
"function_declaration": "def detect_cycle(N, M, edges):",
"function_name": "detect... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_cycle_dfs(graph, v, visited, rec_stack):\n visited[v] = True\n rec_stack[v] = True\n \n for neighbor in graph[v]:\n if not visit... | trial_gpt4o_2 | {
"original_instruction": "Arun is a creator of a new social media platform. He wants to implement a feature where users can follow each other. He gave you a directed graph with N nodes and M edges representing users and their follow relationships respectively. Your task is to determine if there is a cycle in the gra... | 0.528656 | Code_Contests_38618 | C | [
"has_cycle",
"detect_cycle",
"check_circular_relationships"
] | 3 | [
[
"check_circular_relationships",
"detect_cycle"
],
[
"detect_cycle",
"has_cycle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 303cd927a8b492912c0e6cb2f166592385824aa0 | 277fe181af9a689c20b09309f5aba21f40a6e11a | |||
v1.0 | complete | Code_Contests | Code_Contests_38898_C | def quicksort(arr):
if len(arr) <= 1:
return arr
else:
mid_index = len(arr) // 2
pivot = arr[mid_index]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + qui... | def quicksort(arr):
if len(arr) <= 1:
return arr
else:
mid_index = len(arr) // 2
pivot = arr[mid_index]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + qui... | def test_simplified_quicksort_single_element():
input_data = "1\n5"
assert simplified_quicksort(input_data) == "5"
def test_simplified_quicksort_sorted_order():
input_data = "5\n1 2 3 4 5"
assert simplified_quicksort(input_data) == "1 2 3 4 5"
def test_simplified_quicksort_reverse_order():
input_d... | [
{
"docstring": null,
"function_declaration": "def quicksort(arr):",
"function_name": "quicksort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def simplified_quicksort(input_data):",
"function_name": "simplified_quicksort",
"parameter_list": "(input_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr):\n if len(arr) <= 1:\n return arr\n else:\n mid_index = len(arr) // 2\n pivot = arr[mid_index]\n left ... | trial_gpt4o_0 | {
"original_instruction": "A group of friends love to play Quicksort-inspired card games. One day, they decided to create a simplified version of the Quicksort algorithm to sort their decks faster. They asked you to help them implement it. The goal is to implement a simplified version of Quicksort, where you only nee... | 0.612905 | Code_Contests_38898 | C | [
"quicksort",
"simplified_quicksort"
] | 2 | [
[
"simplified_quicksort",
"quicksort"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b318bf761b405f94f4e320836ec17c0da06dfb5e | 367d370ffebdc67c192f126729774ed9e81c1af1 | |||
v1.0 | complete | Code_Contests | Code_Contests_39228_C | from typing import List
from math import gcd
from functools import reduce
def lcm(a, b):
return a * b // gcd(a, b)
def find_lcm_of_list(cycles):
return reduce(lcm, cycles)
def garden_growth_cycles(test_cases: List[List[int]]) -> List[int]:
""" Determine the least number of days after which all the plants... | from math import gcd
from functools import reduce
def lcm(a, b):
return a * b // gcd(a, b)
def find_lcm_of_list(cycles):
return reduce(lcm, cycles)
def garden_growth_cycles(test_cases):
result = []
for cycles in test_cases:
result.append(find_lcm_of_list(cycles))
return result | from solution import garden_growth_cycles
def test_basic_cases():
assert garden_growth_cycles([[2, 3, 4]]) == [12]
assert garden_growth_cycles([[5, 6, 7, 8]]) == [840]
def test_single_plant():
assert garden_growth_cycles([[4]]) == [4]
assert garden_growth_cycles([[1000]]) == [1000]
def test_two_plant... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def find_lcm_of_list(cycles):",
"function_name": "find_lcm_of_list",
"parameter_list": "(cycles)"
},
{
"docst... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef find_lcm_of_list(cycles):\n return reduce(lcm... | trial_gpt4o_0 | {
"original_instruction": "You are given the task of managing a garden with different types of plants. Each plant has a unique growth cycle, described by the number of days it takes for the plant to grow to its full height and start again from the beginning. You need to figure out when it will be the first day that a... | 0.573614 | Code_Contests_39228 | C | [
"lcm",
"find_lcm_of_list",
"garden_growth_cycles"
] | 3 | [
[
"find_lcm_of_list",
"lcm"
],
[
"garden_growth_cycles",
"find_lcm_of_list"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8c122952ec34d2611d8442e9d2c6d63b19da1caf | 91e1c807c5dac91b678d6d7ef5fc587c6aea595b | |||
v1.0 | complete | Code_Contests | Code_Contests_38861_C | def taskScheduler(tasks):
"""
Determines the maximum total reward the workers can achieve given the list of tasks.
Args:
tasks (list of tuples): A list of tuples where each tuple contains three integers
(start time, end time, reward) representing a task.
Return... | def taskScheduler(tasks):
"""
Determines the maximum total reward the workers can achieve given the list of tasks.
Args:
tasks (list of tuples): A list of tuples where each tuple contains three integers
(start time, end time, reward) representing a task.
Return... | def test_task_scheduler_example_1():
assert wrapper(4, [(1, 3, 10), (2, 5, 10), (4, 6, 5), (6, 7, 7)]) == 22
def test_task_scheduler_example_2():
assert wrapper(3, [(1, 2, 3), (2, 3, 2), (3, 4, 6)]) == 11
def test_task_scheduler_no_overlap():
assert wrapper(3, [(1, 2, 5), (3, 4, 10), (5, 6, 15)]) == 30
d... | [
{
"docstring": "Determines the maximum total reward the workers can achieve given the list of tasks.\n\nArgs:\ntasks (list of tuples): A list of tuples where each tuple contains three integers \n (start time, end time, reward) representing a task.\n\nReturns:\nint: The maximum total rewar... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def taskScheduler(N, tasks):\n \"\"\"\n Determines the maximum total reward by completing non-overlapping tasks.\n \n Parameters:\n N (int):... | trial_gpt4o_6 | {
"original_instruction": "A group of workers is given a number of tasks to complete. Each task has a specific start time, end time, and reward associated with its completion. The workers need to complete as many non-overlapping tasks as possible to maximize their total reward. Each worker can only work on one task a... | 0.620006 | Code_Contests_38861 | C | [
"taskScheduler",
"wrapper"
] | 2 | [
[
"wrapper",
"taskScheduler"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3e5ab2f171f6fd7e34dcb0e5112070e7157235bd | 1cc9dc74ca3035f9b353e3ad31112bab9e5c828c | |||
v1.0 | complete | Code_Contests | Code_Contests_38974_C | def is_prime(num):
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(11)
True
>>> is_prime(1)
False
>>> is_prime(4)
False
"""
pass
def calculate_salary_budget(employees, department_id):
""" Calculate total salary budget for a department considering only p... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def calculate_salary... | def test_is_prime():
assert is_prime(2)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(4)
assert is_prime(13)
def test_calculate_salary_budget():
employees = [
(1, 'Alice', 1500, 101),
(2, 'Bob', 1700, 102),
(3, 'Charlie', 1800, 101),
(4, 'David',... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Calculate total salary budget for a department considering only prime salaries.",
"function_declaration": "def calculate_s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\... | trial_gpt4o_0 | {
"original_instruction": "A company needs to manage its employee data in a new software system. Each employee has a unique ID, a name, and a salary. The company needs to calculate the total salary budget for a specific department, given a list of employees and their respective department IDs. However, the salary bud... | 0.625012 | Code_Contests_38974 | C | [
"is_prime",
"calculate_salary_budget"
] | 2 | [
[
"calculate_salary_budget",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 29cab22f61fcef20ef5e0ea03bdcf2b80281d49b | d8334a5b948921f8786915a9446eba6d740f03c0 | |||
v1.0 | complete | Code_Contests | Code_Contests_39249_C | def is_game_lost(arr):
"""
Determine if the array state causes the current player to lose.
If there is any non-zero number, the player has a move to make.
"""
pass
def optimal_winner(arr):
"""
Determine the optimal winner based on the initial array state.
If the array contains an odd nu... | def is_game_lost(arr):
"""
Determine if the array state causes the current player to lose.
If there is any non-zero number, the player has a move to make.
"""
return all(x == 0 for x in arr)
def optimal_winner(arr):
"""
Determine the optimal winner based on the initial array state.
If t... | from solution import is_game_lost, optimal_winner, game_winner
def test_is_game_lost():
assert is_game_lost([0, 0, 0]) == True
assert is_game_lost([1, 0, 0]) == False
assert is_game_lost([0, 1, 0]) == False
assert is_game_lost([0, 0, 1]) == False
def test_optimal_winner():
assert optimal_winner([1... | [
{
"docstring": "Determine if the array state causes the current player to lose.\nIf there is any non-zero number, the player has a move to make.",
"function_declaration": "def is_game_lost(arr):",
"function_name": "is_game_lost",
"parameter_list": "(arr)"
},
{
"docstring": "Determine the opt... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def determine_winner(A):\n \"\"\"\n Determines the winner of the game given the array A by calculating the XOR of all\n elements. If the result is... | trial_gpt4o_2 | {
"original_instruction": "Alice and Bob are playing a game with an array of integers. They take turns and each player must choose a non-zero number `X` from the array, replace `X` with `X-1`, and then multiply every other number in the array by `X`. The player who cannot make a move loses the game. Both players play... | 0.713559 | Code_Contests_39249 | C | [
"is_game_lost",
"optimal_winner",
"game_winner",
"main"
] | 4 | [
[
"game_winner",
"optimal_winner"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cbd9a67545d713ff78c7d242a6c21c3217ccb2f6 | fbcfcd40812a2f30c1b880799060929cc192dbeb | |||
v1.0 | complete | Code_Contests | Code_Contests_39394_C | from typing import List
def is_prime(n: int) -> bool:
""" Check if a number n is prime.
>>> is_prime(13) == True
>>> is_prime(14) == False
"""
pass
def next_prime_anagram(x: int) -> int:
""" Find the smallest prime anagram greater than x.
>>> next_prime_anagram(13) == 31
>>> next_prime... | from itertools import permutations as perm
from math import sqrt
def is_prime(n):
"""
Check if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (... | from solution import next_prime_anagram
def test_next_prime_anagram_case1():
assert next_prime_anagram(13) == 31
def test_next_prime_anagram_case2():
assert next_prime_anagram(71) == -1
def test_next_prime_anagram_case3():
assert next_prime_anagram(17) == 71
def test_next_prime_anagram_case4():
asse... | [
{
"docstring": "Check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest prime anagram greater than x.",
"function_declaration": "def next_prime_anagram(x):",
"function_name":... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\nfrom sympy import isprime\n\ndef next_prime_anagram(X):\n \"\"\"\n Finds the next prime anagram greater than X.\n... | trial_gpt4o_1 | {
"original_instruction": "In the kingdom of Pacifica, the inhabitants love to play with prime numbers and permutations. They have a special interest in detecting prime anagrams. Two numbers are considered prime anagrams if both numbers are prime, and one number's digits can be rearranged to form the other number. Fo... | 0.700816 | Code_Contests_39394 | C | [
"is_prime",
"next_prime_anagram"
] | 2 | [
[
"next_prime_anagram",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b3ee6a622c0602f8dbc9f44bdc7e2055ce91cf2e | 66ba1b849918c361f0cfb9e96783f92aea9f40f4 | |||
v1.0 | complete | Code_Contests | Code_Contests_38674_C | def calculate_total_delivery_time(delivery_points):
"""Calculate the total delivery time given the delivery points.
Args:
delivery_points (List[Tuple[int, int]]): List of delivery coordinates.
Returns:
int: The total delivery time.
Example:
>>> calculate_total_... | def calculate_total_delivery_time(delivery_points):
"""
This function calculates the total delivery time given the delivery points.
"""
return len(delivery_points) * 2
def robot_delivery(D, deliveries, C, changes):
from collections import defaultdict
initial_time = calculate_total_delivery... | from solution import calculate_total_delivery_time, robot_delivery
def test_calculate_total_delivery_time():
assert calculate_total_delivery_time([(3, 4), (-1, -2), (1, 1)]) == 6
assert calculate_total_delivery_time([(0, 0)]) == 2
assert calculate_total_delivery_time([(3, 3), (3, 3)]) == 4
def test_robot_... | [
{
"docstring": "This function calculates the total delivery time given the delivery points.",
"function_declaration": "def calculate_total_delivery_time(delivery_points):",
"function_name": "calculate_total_delivery_time",
"parameter_list": "(delivery_points)"
},
{
"docstring": null,
"fu... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_total_delivery_time(delivery_points):\n \"\"\"\n This function calculates the total delivery time given the delivery points.\n \"\"\... | trial_gpt4o_0 | {
"original_instruction": "**Robo Delivery:**\n\nA futuristic city uses an autonomous robot to deliver packages across predefined locations. Each location in the city is represented as a coordinate on a Cartesian plane. The robot starts at the origin (0, 0) and needs to deliver packages to a sequence of coordinates p... | 0.54283 | Code_Contests_38674 | C | [
"calculate_total_delivery_time",
"robot_delivery"
] | 2 | [
[
"robot_delivery",
"calculate_total_delivery_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1d384d2bbb5c94dc77137fb0353d984e4e8adc29 | a566062fb80ad4a829db881a299dae6763dd70ee | |||
v1.0 | complete | Code_Contests | Code_Contests_39155_C | class TreeNode:
def __init__(self, id, color):
self.id = id
self.color = color
self.left = None
self.right = None
def build_tree(node_details):
nodes = {}
for detail in node_details:
id = detail[0]
color = detail[1]
left_id = detail[2]
right_i... | class TreeNode:
def __init__(self, id, color):
self.id = id
self.color = color
self.left = None
self.right = None
def build_tree(node_details):
nodes = {}
for detail in node_details:
id = detail[0]
color = detail[1]
left_id = detail[2]
right_i... | def test_example_case():
input_data = """7
1 R 2 3
2 B 4 5
3 R -1 -1
4 R -1 -1
5 B -1 -1
6 R -1 -1
7 B 6 7"""
# Capturing the print output
import io
import sys
captured_output = io.StringIO()
sys.stdout = captured_output
solve(input_data)
sys.stdout = sys.__stdout__
assert... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, id, color):\n self.id = id\n self.color = color\n self.left = None\n self.right = None\... | trial_gpt4o_0 | {
"original_instruction": "You are given a binary tree, where each node contains a value, and each value is either 'R' (for red) or 'B' (for blue). The goal is to determine if a path exists from the root to any leaf where the number of 'R' nodes is greater than the number of 'B' nodes. Your task is to write a functio... | 0.600463 | Code_Contests_39155 | C | [
"build_tree",
"path_with_more_reds_than_blues_exists",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"path_with_more_reds_than_blues_exists"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 04b9dd384847ccc4b96360481328daef30311c53 | 69f065f627b87ffc445697fe900ff52026e4a5be | |||
v1.0 | complete | Code_Contests | Code_Contests_38823_C | def can_empty_servers(N: int, B: int, logs: List[int]) -> Tuple[bool, List[str]]:
"""
Determines if all servers can be emptied given the bandwidth capacity.
Parameters:
N (int): Number of servers.
B (int): Bandwidth capacity.
logs (List[int]): Initial sizes of logs on each server.
Returns:... | def can_empty_servers(N, B, logs):
"""
Determines if all servers can be emptied given the bandwidth capacity
:param N: int - number of servers
:param B: int - bandwidth capacity
:param logs: list of int - initial sizes of logs on each server
:return: tuple - (bool, list of str) - whether it is ... | def test_example1():
N = 3
B = 5
logs = [8, 10, 3]
assert can_empty_servers(N, B, logs) == (True, [
"1 5", "1 3", "2 5", "2 5", "3 3"
])
def test_example2():
N = 2
B = 2
logs = [5, 4]
assert can_empty_servers(N, B, logs) == (True, [
"1 2", "1 2", "1 1", "2 2", "2 2"
... | [
{
"docstring": "Determines if all servers can be emptied given the bandwidth capacity\n\n:param N: int - number of servers\n:param B: int - bandwidth capacity\n:param logs: list of int - initial sizes of logs on each server\n:return: tuple - (bool, list of str) - whether it is possible and the sequence of opera... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def possible_to_empty_servers(N, B, log_sizes):\n operations = []\n for i in range(N):\n while log_sizes[i] > 0:\n transfer_size = ... | trial_gpt4o_8 | {
"original_instruction": "Implement an algorithm to solve the following problem: You are responsible for managing a network of servers in a data center. Each server holds logs of varying sizes that need to be transferred to a central server for analysis.\n\nDue to a limitation in network bandwidth, you can only tran... | 0.53219 | Code_Contests_38823 | C | [
"can_empty_servers",
"solve"
] | 2 | [
[
"solve",
"can_empty_servers"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5016ec6a95803ae9691f0689e933c782d0cc9557 | 3e51298edce3ef3e9b68b2d71381cdf747007b8e | |||
v1.0 | complete | Code_Contests | Code_Contests_38959_C | def calculate_levels(t: int, challenges: List[Tuple[int, List[int]]]) -> List[Tuple[int, int]]:
"""
Calculates the maximum level up and the maximum level down a player can achieve given a terrain challenge structure.
Each challenge contains a number of terrain sections with varying difficulty levels.
... | def calculate_levels(t, challenges):
results = []
for challenge in challenges:
n = challenge[0]
terrains = challenge[1]
max_level_up = 0
max_level_down = 0
for i in range(1, n):
if terrains[i] > terrains[i - 1]:
max_level_up = max(max_lev... | from solution import parse_and_calculate_levels
def test_example_case():
input_data = """4
6
15 85 45 70 95 120
3
10 30 5
2
50 20
5
80 80 80 80 80"""
expected_output = [(70, 40), (20, 25), (0, 30), (0, 0)]
assert parse_and_calculate_levels(input_data) == expected_output
def test_all_increasing():
inpu... | [
{
"docstring": null,
"function_declaration": "def calculate_levels(t, challenges):",
"function_name": "calculate_levels",
"parameter_list": "(t, challenges)"
},
{
"docstring": null,
"function_declaration": "def parse_and_calculate_levels(input_data):",
"function_name": "parse_and_cal... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_levels(t, challenges):\n results = []\n \n for challenge in challenges:\n n, terrains = challenge\n max_level_up = 0\n... | trial_gpt4o_1 | {
"original_instruction": "A popular game called \"Land of Kings\" involves leveling up challenges where players traverse through various terrains. Each terrain section has a different difficulty level, represented by integers. Players can level up when moving to a terrain section of a higher difficulty and level dow... | 0.571033 | Code_Contests_38959 | C | [
"calculate_levels",
"parse_and_calculate_levels"
] | 2 | [
[
"parse_and_calculate_levels",
"calculate_levels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3e974f4ebe1cd56e8919f72e0b8068e5ec74a3c | be5e72ea23471883898a84d52f01d871eb516740 | |||
v1.0 | complete | Code_Contests | Code_Contests_39122_C | import itertools
from typing import List, Tuple
def compute_area(p1: Tuple[int, int], p2: Tuple[int, int], p3: Tuple[int, int]) -> float:
"""Compute the area of a triangle given three points (p1, p2, p3)."""
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
return 0.5 * abs(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 -... | import itertools
def compute_area(p1, p2, p3):
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
return 0.5 * abs(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2))
def smallest_triangle_area(points):
n = len(points)
min_area = float('inf')
found = False
for p1, p2, p3 in itertools.combinations(points, 3)... | def test_triangle_area():
# Test case 1
points = [(0, 0), (1, 0), (0, 1), (1, 1)]
assert smallest_triangle_area(points) == 0.5
# Test case 2
points = [(1, 1), (2, 2), (3, 3)]
assert smallest_triangle_area(points) == -1
# Test case 3 - Larger number of points
points = [(0, 0), (0, 2), (... | [
{
"docstring": null,
"function_declaration": "def compute_area(p1, p2, p3):",
"function_name": "compute_area",
"parameter_list": "(p1, p2, p3)"
},
{
"docstring": null,
"function_declaration": "def smallest_triangle_area(points):",
"function_name": "smallest_triangle_area",
"param... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def smallest_triangle_area(test_cases):\n from itertools import combinations\n import sys\n\n results = []\n\n def triangle_area(p1, p2, p3):\n... | trial_gpt4o_1 | {
"original_instruction": "In a land of geometric shapes, there are several powerful magic wands. Each wand has its unique power source derived from triangles. The sorcerers of this land found that placing a few points on a plane and connecting them to form triangles can generate a mysterious energy.\n\nGiven n point... | 0.775394 | Code_Contests_39122 | C | [
"compute_area",
"smallest_triangle_area",
"process_test_cases",
"main"
] | 4 | [
[
"process_test_cases",
"smallest_triangle_area"
],
[
"smallest_triangle_area",
"compute_area"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | e9c3216f6b8d8e1ce055cffb761beab121e69f73 | 93cecc8a5291b1ef8b57b542cf1750021c35d88d | |||
v1.0 | complete | Code_Contests | Code_Contests_39381_C | def product_of_digits(num: int) -> int:
"""
Returns the product of the digits of a number.
>>> product_of_digits(15)
5
>>> product_of_digits(101)
0
>>> product_of_digits(123)
6
>>> product_of_digits(999)
729
>>> product_of_digits(5)
5
"""
pass
def kth_number_in_s... | def product_of_digits(num):
"""
Returns the product of the digits of a number.
"""
product = 1
while num > 0:
digit = num % 10
if digit == 0:
return 0
product *= digit
num //= 10
return product
def kth_number_in_sequence(a, k):
"""
Returns the... | from solution import product_of_digits, kth_number_in_sequence, process_test_cases
def test_product_of_digits():
assert product_of_digits(15) == 5
assert product_of_digits(101) == 0
assert product_of_digits(123) == 6
assert product_of_digits(999) == 729
assert product_of_digits(5) == 5
def test_kt... | [
{
"docstring": "Returns the product of the digits of a number.",
"function_declaration": "def product_of_digits(num):",
"function_name": "product_of_digits",
"parameter_list": "(num)"
},
{
"docstring": "Returns the k-th number in the sequence starting with a.",
"function_declaration": "d... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def product_of_digits(num):\n \"\"\"\n Returns the product of the digits of a number.\n \"\"\"\n product = 1\n while num > 0:\n digit... | trial_gpt4o_0 | {
"original_instruction": "Consider a sequence of numbers where each number is the product of the digits of all previous numbers in the sequence, starting with an initial number. Your task is to determine the k-th number in this sequence.\n\nINPUT:\n\nThe first line contains the number of test cases t.\nEach of the n... | 0.672734 | Code_Contests_39381 | C | [
"product_of_digits",
"kth_number_in_sequence",
"process_test_cases"
] | 3 | [
[
"kth_number_in_sequence",
"product_of_digits"
],
[
"process_test_cases",
"kth_number_in_sequence"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | cccd9f92bb31cb298b15dfc3d81aa6e95a4679bd | ba24170aacc1f06cd0a5ecd3ef6644b3c399b9f7 | |||
v1.0 | complete | Code_Contests | Code_Contests_39280_C | def final_robot_position(commands_list):
"""
Given a list of commands, determines the final position of the robot.
Parameters:
commands_list (list): A list of strings where each string is a command.
Returns:
tuple: The final coordinates of the robot (x, y).
>>> final_robot... | def final_robot_position(commands_list):
"""
Given a list of commands, determines the final position of the robot.
Parameters:
commands_list (list): A list of strings where each string is a command.
Returns:
tuple: The final coordinates of the robot (x, y).
"""
x, y = 0... | def test_final_robot_position():
assert final_robot_position(["UP", "RIGHT", "DOWN", "LEFT"]) == (0, 0)
assert final_robot_position(["UP", "UP", "RIGHT", "RIGHT", "DOWN", "DOWN"]) == (2, 0)
assert final_robot_position(["LEFT", "LEFT", "LEFT", "LEFT", "UP", "UP", "RIGHT", "RIGHT"]) == (-2, 2)
def test_proce... | [
{
"docstring": "Given a list of commands, determines the final position of the robot.\n\nParameters:\n commands_list (list): A list of strings where each string is a command.\n\nReturns:\n tuple: The final coordinates of the robot (x, y).",
"function_declaration": "def final_robot_position(commands_li... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def final_coordinates(commands):\n \"\"\"\n Given a list of commands, this function calculates the final coordinates\n of the robot starting from ... | trial_gpt4o_2 | {
"original_instruction": "A language interprets strings as instructions for a mechanical robot. The robot starts at the origin (0, 0) on a 2D plane. The robot can receive commands to move in four directions: \"UP\", \"DOWN\", \"LEFT\", and \"RIGHT\", altering its coordinates by 1 unit accordingly. For example, a com... | 0.541034 | Code_Contests_39280 | C | [
"final_robot_position",
"process_commands"
] | 2 | [
[
"process_commands",
"final_robot_position"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 569fccc2b0e470d3161193c3981916a28dfd12c6 | 407351bed081cdfa318739448ee5db442220688b | |||
v1.0 | complete | Code_Contests | Code_Contests_38902_C | from typing import List
def parse_input(input_text: str):
"""
Parses the input text and returns a structured representation of the vehicles, locations, and roads.
"""
lines = input_text.strip().split("\n")
index = 0
number_of_vehicle_types = int(lines[index])
index += 1
vehicles = []
... | def parse_input(input_text):
"""
Parses the input text and returns a structured representation of the vehicles, locations, and roads.
"""
lines = input_text.strip().split("\n")
index = 0
number_of_vehicle_types = int(lines[index])
index += 1
vehicles = []
for _ in range(number_of_ve... | from solution import main_process
def test_case_1():
input_text = """\
2
truck 5.0 2000 500
van 10.0 1000 300
3
1 500 6
2 1000 8
3 1500 10
4
0 1 250 50
0 2 300 60 van
1 3 350 70 truck
2 3 400 80
"""
output_text = """\
truck impossible
van impossible"""
assert main_process(input_text).strip() == output... | [
{
"docstring": "Parses the input text and returns a structured representation of the vehicles, locations, and roads.",
"function_declaration": "def parse_input(input_text):",
"function_name": "parse_input",
"parameter_list": "(input_text)"
},
{
"docstring": null,
"function_declaration": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef calculate_optimal_route(vehicle_data, location_data, road_data):\n v = len(vehicle_data)\n l = len(location_data)\n r = len(ro... | trial_gpt4o_1 | {
"original_instruction": "A transportation company wants to optimize its delivery route to minimize cost and time, taking into account varying cargo sizes and delivery deadlines. The company has a fleet of different types of vehicles, each with different fuel efficiencies, capacities, and maximum allowable distances... | 0.543262 | Code_Contests_38902 | C | [
"parse_input",
"calculate_delivery_cost_and_time",
"optimize_delivery_route",
"main_process"
] | 4 | [
[
"main_process",
"optimize_delivery_route"
],
[
"optimize_delivery_route",
"calculate_delivery_cost_and_time"
],
[
"optimize_delivery_route",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | ed2debe6f67dbbc86d1b888be9c6f8bebffbea7f | 8c48cf870137769cad89fa8a1c69134be5868719 | |||
v1.0 | complete | Code_Contests | Code_Contests_39511_C | def compress_string(s: str) -> str:
""" Compress the string using Run-Length Encoding.
>>> compress_string("aaabbcc") "a3b2c2"
>>> compress_string("a") "a1"
>>> compress_string("aaabbbbcc") "a3b4c2"
>>> compress_string("abcd") "a1b1c1d1"
"""
def are_compressed_strings_equal(s1: str, s2: st... | def compress_string(s):
"""
Compress the string using Run-Length Encoding.
"""
compressed = []
count = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
count += 1
else:
compressed.append(s[i - 1] + str(count))
count = 1
compressed.append... | from solution import compress_string, are_compressed_strings_equal
def test_compress_string():
assert compress_string("aaabbcc") == "a3b2c2"
assert compress_string("a") == "a1"
assert compress_string("aaabbbbcc") == "a3b4c2"
assert compress_string("abcd") == "a1b1c1d1"
def test_are_compressed_strings_... | [
{
"docstring": "Compress the string using Run-Length Encoding.",
"function_declaration": "def compress_string(s):",
"function_name": "compress_string",
"parameter_list": "(s)"
},
{
"docstring": "Check if the two strings are equivalent when compressed using RLE.",
"function_declaration": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compress_string(s):\n compressed = []\n count = 1\n \n for i in range(1, len(s)):\n if s[i] == s[i - 1]:\n count += 1\n ... | trial_gpt4o_2 | {
"original_instruction": "Vera is fascinated by strings. Recently, she learned about string compression techniques used in data storage and transmission. A commonly used method is Run-Length Encoding (RLE). In this method, a string is compressed by replacing consecutive identical characters with the character follow... | 0.601553 | Code_Contests_39511 | C | [
"compress_string",
"are_compressed_strings_equal"
] | 2 | [
[
"are_compressed_strings_equal",
"compress_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8df7c17632ba3f28bed0dad32f31a373c2bb90f5 | 150b3100e0937eed8a71094c429e91ce381f6e6c | |||
v1.0 | complete | Code_Contests | Code_Contests_39374_C | from typing import List
from math import gcd
from functools import reduce
def gcd_of_array(arr: List[int]) -> int:
""" Computes the GCD of all elements in the array. """
return reduce(gcd, arr)
def final_array_values(N: int, A: List[int]) -> List[int]:
"""
Determine the final value of the array after... | from math import gcd
from functools import reduce
def gcd_of_array(arr):
"""
Computes the GCD of all elements in the array.
"""
return reduce(gcd, arr)
def final_array_values(N, A):
"""
Returns the final values of the array after performing the defined operation
until no more changes can ... | from solution import final_array_values
def test_example1():
N = 5
A = [2, 4, 6, 8, 10]
assert final_array_values(N, A) == [2, 2, 2, 2, 2]
def test_example2():
N = 4
A = [15, 10, 5, 20]
assert final_array_values(N, A) == [5, 5, 5, 5]
def test_single_element():
N = 1
A = [42]
asser... | [
{
"docstring": "Computes the GCD of all elements in the array.",
"function_declaration": "def gcd_of_array(arr):",
"function_name": "gcd_of_array",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the final values of the array after performing the defined operation \nuntil no more change... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef gcd_of_array(arr):\n \"\"\"\n Returns the GCD of all elements in the given array.\n \"\"\"\n r... | trial_gpt4o_2 | {
"original_instruction": "**Problem Statement**\n\nYou are given an integer array `A` of length `N`. An operation is defined as follows: Select an arbitrary index `i` (1 <= i <= N) and replace `A[i]` with the greatest common divisor (GCD) of all elements in the array. You are allowed to perform this operation any nu... | 0.678075 | Code_Contests_39374 | C | [
"gcd_of_array",
"final_array_values"
] | 2 | [
[
"final_array_values",
"gcd_of_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d1034f2e37862ef80c136ecd0e1ca40a33e43b9e | 8a6f7ccfb04442865a02e0b137def6bec5331b7b | |||
v1.0 | complete | Code_Contests | Code_Contests_39404_C | def generate_concatenation_sequence(x: int) -> list:
"""
Generates the first 10 numbers in the concatenation sequence starting from the given integer x.
>>> generate_concatenation_sequence(2)
['2', '22', '222', '2222', '22222', '222222', '2222222', '22222222', '222222222', '2222222222']
>>> generate... | def generate_concatenation_sequence(x):
"""
Generates the first 10 numbers in the concatenation sequence starting from the given integer x.
"""
sequence = [str(x)]
for _ in range(9):
next_num = sequence[-1] + str(x)
sequence.append(next_num)
return sequence
def format_sequence(s... | def test_generate_concatenation_sequence():
assert generate_concatenation_sequence(2) == ['2', '22', '222', '2222', '22222', '222222', '2222222', '22222222', '222222222', '2222222222']
assert generate_concatenation_sequence(7) == ['7', '77', '777', '7777', '77777', '777777', '7777777', '77777777', '777777777', ... | [
{
"docstring": "Generates the first 10 numbers in the concatenation sequence starting from the given integer x.",
"function_declaration": "def generate_concatenation_sequence(x):",
"function_name": "generate_concatenation_sequence",
"parameter_list": "(x)"
},
{
"docstring": "Formats the sequ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_concatenation_sequence(x):\n sequence = [str(x)]\n for _ in range(9):\n next_num = sequence[-1] + sequence[-1][0]\n sequen... | trial_gpt4o_1 | {
"original_instruction": "A \"concatenation sequence\" is a special type of sequence consisting of strictly increasing positive integers. For any given sequence S, you can generate the next number in the sequence T by concatenating S with itself and then taking the first len(S) + 1 digits, ensuring the resulting num... | 0.710192 | Code_Contests_39404 | C | [
"generate_concatenation_sequence",
"format_sequence",
"get_concatenation_sequence"
] | 3 | [
[
"get_concatenation_sequence",
"format_sequence"
],
[
"get_concatenation_sequence",
"generate_concatenation_sequence"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 04620c7a7821d40a3b7d614716d7b9733edf650f | 4662e5b92acf36d8061c26424320879d9709aee3 | |||
v1.0 | complete | Code_Contests | Code_Contests_39026_C | import math
from typing import List, Tuple
def circle_coverage(n: int, circles: List[Tuple[int, int, int]], target_circle: Tuple[int, int, int]) -> str:
"""
Determines if there's a non-empty subset of the given circles that entirely covers the target circle.
Parameters:
n (int): number of circles... | import math
def is_point_covered(x, y, circles):
"""
Checks if a point (x, y) is covered by any of the given circles.
"""
for (cx, cy, cr) in circles:
if math.sqrt((x - cx)**2 + (y - cy)**2) <= cr:
return True
return False
def circle_fully_covered(target_circle, circles):
"... | from solution import circle_coverage
def test_case_1():
n = 5
circles = [(0, 0, 3), (2, 2, 2), (1, 1, 1), (4, 4, 2), (5, 5, 1)]
target_circle = (2, 2, 1)
result = circle_coverage(n, circles, target_circle)
assert "YES" in result
def test_case_2():
n = 3
circles = [(0, 0, 1), (5, 5, 1), (10... | [
{
"docstring": "Checks if a point (x, y) is covered by any of the given circles.",
"function_declaration": "def is_point_covered(x, y, circles):",
"function_name": "is_point_covered",
"parameter_list": "(x, y, circles)"
},
{
"docstring": "Check if every point in the target circle is covered ... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_point_inside_circle(px, py, cx, cy, cr):\n \"\"\"\n Determines if a point (px, py) is inside a circle with center (cx, cy) and ... | trial_gpt4o_7 | {
"original_instruction": "You are given a set of n circles, labeled 1 through n. The circles may touch each other or even overlap. Your task is to determine if there's a non-empty subset of the circles that entirely covers a given target circle.\n\nA circle is defined by its center's coordinates and its radius. For ... | 0.632409 | Code_Contests_39026 | C | [
"is_point_covered",
"circle_fully_covered",
"find_covering_subset",
"circle_coverage"
] | 4 | [
[
"circle_coverage",
"find_covering_subset"
],
[
"circle_fully_covered",
"is_point_covered"
],
[
"find_covering_subset",
"circle_fully_covered"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f50a5e0c172c2e66154e9b5dc1149ab25f743a0e | ab390be151d650b6c739b1ef27df22a0f5eca349 | |||
v1.0 | complete | Code_Contests | Code_Contests_39061_C | import math
import random
from typing import List, Tuple
class Circle:
def __init__(self, center: Tuple[float, float], radius: float):
self.center = center
self.radius = radius
def __repr__(self):
return f"Circle(center={self.center}, radius={self.radius})"
def dist(p1: Tuple[float, f... | import math
import random
class Circle:
def __init__(self, center, radius):
self.center = center
self.radius = radius
def __repr__(self):
return f"Circle(center={self.center}, radius={self.radius})"
def dist(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
d... | from solution import Circle, circle_from_2_points, circle_from_3_points, is_in_circle, dist, minimal_enclosing_circle
def test_dist():
assert dist((0, 0), (3, 4)) == 5.0
def test_is_in_circle():
c = Circle((0, 0), 5)
assert is_in_circle(c, (3, 4)) == True
assert is_in_circle(c, (6, 8)) == False
def t... | [] | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def area_and_centroid_polygon(vertices):\n \"\"\"\n Compute the area and centroid (cx, cy) of polygon given by vertices.\n vertices is a list of (... | trial_gpt4o_4 | {
"original_instruction": "Input\n\n3 3\n1 1\n5 1\n5 5\n1 5\n\n\nOutput\n\n49.110611",
"prompt_id": "00039061",
"row_id": 39061,
"seed_ids": "[13213]"
} | 0.692095 | Code_Contests_39061 | C | [
"dist",
"is_in_circle",
"circle_from_2_points",
"circle_from_3_points",
"welzl",
"find_min_circle",
"minimal_enclosing_circle"
] | 7 | [
[
"circle_from_2_points",
"dist"
],
[
"circle_from_3_points",
"dist"
],
[
"find_min_circle",
"welzl"
],
[
"is_in_circle",
"dist"
],
[
"minimal_enclosing_circle",
"find_min_circle"
],
[
"welzl",
"circle_from_2_points"
],
[
"welzl",
"circ... | 8 | [] | false | [
"Circle"
] | true | pytest | true | [] | true | cae72d79ef05333ba7670f225539b12c0a1ad428 | 0c5c8503d33aef350e7b26f9e82008ce0200543f | |||
v1.0 | complete | Code_Contests | Code_Contests_39501_C | from typing import List
from sympy import isprime
def find_circular_primes(n: int) -> List[int]:
""" Returns a list of all circular primes less than or equal to n.
A circular prime is a prime number that remains prime under all rotations of its digits.
>>> find_circular_primes(10)
[2, 3, 5, 7... | from typing import List
from sympy import isprime
def rotate_number(num: int) -> List[int]:
"""
Returns a list of all rotations of the digits in the given number.
"""
rotations = []
str_num = str(num)
for i in range(len(str_num)):
rotated = str_num[i:] + str_num[:i]
rotations.ap... | from solution import find_circular_primes
def test_small_range():
assert find_circular_primes(10) == [2, 3, 5, 7]
def test_medium_range():
assert find_circular_primes(100) == [2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97]
def test_with_specific_value():
assert find_circular_primes(13) == [2, 3, 5, 7, 1... | [
{
"docstring": "Returns a list of all rotations of the digits in the given number.",
"function_declaration": "def rotate_number(num):",
"function_name": "rotate_number",
"parameter_list": "(num)"
},
{
"docstring": "Checks if a number is a circular prime.",
"function_declaration": "def is... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\nfrom itertools import permutations\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num == 2:\n ... | trial_gpt4o_1 | {
"original_instruction": "Adam is fascinated with the concept of prime numbers. He recently read about \"circular primes\". A circular prime is a prime number that remains prime under all rotations of its digits. For instance, 197 is a circular prime because 197, 971, and 719 are all prime numbers.\n\nAdam wants to ... | 0.690033 | Code_Contests_39501 | C | [
"rotate_number",
"is_circular_prime",
"find_circular_primes"
] | 3 | [
[
"find_circular_primes",
"is_circular_prime"
],
[
"is_circular_prime",
"rotate_number"
]
] | 2 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | 8f0e7fa17f7827711901d3889bdf515bd8ab0ab4 | 4c180dff251434e8c56752a3dd773f0e9f2fc0ba | |||
v1.0 | complete | Code_Contests | Code_Contests_39708_C | def sequence_length_and_max(start):
"""
Returns the length of the sequence and the maximum value in the sequence starting from 'start'.
>>> sequence_length_and_max(3) (8, 16)
>>> sequence_length_and_max(1) (1, 1)
>>> sequence_length_and_max(6) (9, 16)
>>> sequence_length_and_max(19) (21, 88)
... | def sequence_length_and_max(start):
"""
Returns the length of the sequence and the maximum value in the sequence starting from 'start'.
"""
length = 1
max_value = start
current = start
while current != 1:
if current % 2 == 0:
current //= 2
else:
c... | from solution import sequence_length_and_max, puzzle_solution
def test_sequence_length_and_max():
assert sequence_length_and_max(3) == (8, 16)
assert sequence_length_and_max(1) == (1, 1)
assert sequence_length_and_max(6) == (9, 16)
assert sequence_length_and_max(19) == (21, 88)
assert sequence_leng... | [
{
"docstring": "Returns the length of the sequence and the maximum value in the sequence starting from 'start'.",
"function_declaration": "def sequence_length_and_max(start):",
"function_name": "sequence_length_and_max",
"parameter_list": "(start)"
},
{
"docstring": null,
"function_decla... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sequence_length_and_max(start):\n \"\"\"\n Returns the length of the sequence and the maximum value in the sequence starting from 'start'.\n \... | trial_gpt4o_0 | {
"original_instruction": "Alice and Bob were given a puzzle to solve by their friend, who loves sequences. The puzzle involves a sequence that starts with a single integer `A`. Each subsequent number in the sequence is derived as follows: If the current number is even, divide it by 2; if it is odd, multiply it by 3 ... | 0.579767 | Code_Contests_39708 | C | [
"sequence_length_and_max",
"puzzle_solution"
] | 2 | [
[
"puzzle_solution",
"sequence_length_and_max"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8b840df900395f263caeead8203cec514d49fe01 | 841bec829e1a0ff91f498682d10b7b691b25458e | |||
v1.0 | complete | Code_Contests | Code_Contests_39764_C | def minimum_outposts(n: int, m: int, roads: List[Tuple[int, int]]) -> int:
"""The kingdom of Linaria has n villages connected by m roads. Some of these roads are known to be dangerous due to bandit activity. The goal is to place outposts such that every road's two villages can communicate through guards directly or... | def find_connected_components(n, edges):
from collections import defaultdict, deque
def bfs(start, visited, graph):
queue = deque([start])
while queue:
node = queue.popleft()
for neighbor in graph[node]:
if not visited[neighbor]:
visit... | from solution import minimum_outposts
def test_case_1():
n = 5
m = 4
roads = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert minimum_outposts(n, m, roads) == 1
def test_case_2():
n = 4
m = 2
roads = [(1, 2), (3, 4)]
assert minimum_outposts(n, m, roads) == 2
def test_case_3():
n = 6
m ... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(n, edges):",
"function_name": "find_connected_components",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_outposts(n, m, roads):",
"function_name": "minimum_outpos... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_outposts(n, roads):\n \"\"\"\n Finds the minimum number of outposts required for the given villages and roads.\n\n :param n: Numb... | trial_gpt4o_2 | {
"original_instruction": "The kingdom of Linaria has n villages connected by m roads. Some of these roads are known to be dangerous due to bandit activity. The King has decided that, as a precaution, additional outpost towers should be constructed along the roads to guarantee the safety and quick response of the kin... | 0.643624 | Code_Contests_39764 | C | [
"find_connected_components",
"minimum_outposts"
] | 2 | [
[
"minimum_outposts",
"find_connected_components"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1b715d56e69b9b15f81060194b0b7f284b898a7a | 0a1a6cb90d741640ffd431ffb4feeaa391797b0b | |||
v1.0 | complete | Code_Contests | Code_Contests_39564_C | import math
from typing import List, Tuple
def is_perfect_square(x: int) -> bool:
"""
Check if a number is a perfect square.
>>> is_perfect_square(4)
True
>>> is_perfect_square(7)
False
>>> is_perfect_square(-4)
False
"""
if x < 0:
return False
root = int(math.isqrt(... | import math
def is_perfect_square(x):
"""
Returns True if x is a perfect square, False otherwise.
"""
if x < 0:
return False
root = int(math.isqrt(x))
return root * root == x
def filter_records(records):
"""
Given a list of (id, value) tuples, return a filtered list excluding t... | from solution import filter_records
def test_filter_records_with_perfect_squares():
records = [(1, 4), (2, 7), (3, 9), (4, 16), (5, 23)]
filtered = filter_records(records)
assert filtered == [(2, 7), (5, 23)]
def test_filter_records_with_some_perfect_squares():
records = [(1, 1), (2, 3), (3, -4), (4, ... | [
{
"docstring": "Returns True if x is a perfect square, False otherwise.",
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Given a list of (id, value) tuples, return a filtered list excluding those\nwhose va... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"\n Returns True if x is a perfect square, False otherwise.\n \"\"\"\n if x < 0:\n retur... | trial_gpt4o_0 | {
"original_instruction": "You are working for a software company and your team has been assigned to optimize the memory usage of a large dataset. As an initial step, you need to perform a simple data reduction task based on a given criterion.\n\nThe dataset consists of n records, each with an ID (which is a positive... | 0.597993 | Code_Contests_39564 | C | [
"is_perfect_square",
"filter_records"
] | 2 | [
[
"filter_records",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d7c78b65e0dfb7597fe16c147a9aafdabea9962 | 5062104853e93108f08a4bf235a81778ffffd727 | |||
v1.0 | complete | Code_Contests | Code_Contests_39777_C | from typing import List, Tuple
def solve_task(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[int]:
""" For each test case, determine the minimum number of additional roads required to make the set of cities fully connected.
Args:
T (int): The number of test cases
test_cases ... | def find(num_of_cities, roads, city):
if city != roads[city]:
roads[city] = find(num_of_cities, roads, roads[city])
return roads[city]
def union(num_of_cities, roads, rank, city1, city2):
root1 = find(num_of_cities, roads, city1)
root2 = find(num_of_cities, roads, city2)
if root1 != root2:
... | from solution import solve_task
def test_single_test_case():
assert solve_task(1, [(3, 1, [(1, 2)])]) == [1]
assert solve_task(1, [(4, 2, [(1, 2), (2, 3)])]) == [1]
assert solve_task(1, [(1, 0, [])]) == [0]
assert solve_task(1, [(2, 0, [])]) == [1]
assert solve_task(1, [(2, 1, [(1, 2)])]) == [0]
d... | [
{
"docstring": null,
"function_declaration": "def find(num_of_cities, roads, city):",
"function_name": "find",
"parameter_list": "(num_of_cities, roads, city)"
},
{
"docstring": null,
"function_declaration": "def union(num_of_cities, roads, rank, city1, city2):",
"function_name": "un... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(num_of_cities, roads, city):\n if city != roads[city]:\n roads[city] = find(num_of_cities, roads, roads[city])\n return roads[city]\n... | trial_gpt4o_0 | {
"original_instruction": "Petya has a set of straight roads connecting several cities. Each road connects exactly two different cities, and no two roads intersect each other at any point other than at their endpoints (the cities). Petya wants to find the minimum number of additional roads required to make the set of... | 0.696068 | Code_Contests_39777 | C | [
"find",
"union",
"min_additional_roads_needed",
"solve_task"
] | 4 | [
[
"min_additional_roads_needed",
"find"
],
[
"min_additional_roads_needed",
"union"
],
[
"solve_task",
"min_additional_roads_needed"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | dfb91c2b7683fecd7dbcca8b01fb6f30f19037be | 44588cc27a7e28205515dc575ac2f9662914de2d | |||
v1.0 | complete | Code_Contests | Code_Contests_39745_C | MOD = 10**9 + 7
def process_queries(n: int, q: int, arr: List[int], queries: List[str]) -> List[int]:
"""Process a series of queries on an array.
Args:
n: int: The number of elements in the array.
q: int: The number of queries.
arr: List[int]: The initial array of integers.
queries: List[s... | MOD = 10**9 + 7
def process_queries(n, q, arr, queries):
results = []
for query in queries:
parts = query.split()
if parts[0] == "SET":
l, r, x = map(int, parts[1:])
for i in range(l-1, r):
arr[i] = x
elif parts[0] == "SUM-SQUARE":
... | from solution import solve
def test_case_1():
n = 5
q = 5
array = [1, 3, 9, 4, 8]
queries = [
"SUM-SQUARE 1 3", # SUM-SQUARE 1, 9, 81 --> 1 + 9 + 81 = 91
"SET 2 4 2", # [1, 2, 2, 2, 8]
"SUM-SQUARE 1 5", # SUM-SQUARE 1, 2, 2, 2, 8 --> 1 + 4 + 4 + 4 + 64 = 77
"SET ... | [
{
"docstring": null,
"function_declaration": "def process_queries(n, q, arr, queries):",
"function_name": "process_queries",
"parameter_list": "(n, q, arr, queries)"
},
{
"docstring": null,
"function_declaration": "def solve(n, q, array, raw_queries):",
"function_name": "solve",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 10**9 + 7\n\ndef preprocess_sums(a):\n n = len(a)\n sum_squares = [0] * (n + 1)\n for i in range(1, n + 1):\n sum_squares[i] = sum_sq... | trial_gpt4o_8 | {
"original_instruction": "You are given an array a_1, a_2, …, a_n.\n\nYou need to perform q queries of the following two types:\n\n1. \"SET l r x\" — for every i (l ≤ i ≤ r) set a_i to x.\n2. \"SUM-SQUARE l r\" — print the sum of squares of the subarray from index l to r, taken modulo 10^9+7.\n\nInput\n\nThe first l... | 0.646612 | Code_Contests_39745 | C | [
"process_queries",
"solve"
] | 2 | [
[
"solve",
"process_queries"
]
] | 1 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 3c4b9cbb759fa4ce04ac3660855247d532436a30 | 8b660835a186e76a4ce84ee8432377948939503c | |||
v1.0 | complete | Code_Contests | Code_Contests_39996_C | from typing import List, Tuple
def can_all_knights_move_simultaneously(board_size: int, knight_positions: List[Tuple[int, int]]) -> str:
"""Determine if it is possible for all knights to simultaneously make one valid move without landing on any other knight’s starting or ending positions.
Args:
board_... | def is_valid_move(board_size, x, y):
return 1 <= x <= board_size and 1 <= y <= board_size
def generate_moves(board_size, current_pos):
x, y = current_pos
potential_moves = [
(x + 2, y + 1), (x + 2, y - 1), (x - 2, y + 1), (x - 2, y - 1),
(x + 1, y + 2), (x + 1, y - 2), (x - 1, y + 2), (x - ... | from solution import can_all_knights_move_simultaneously
def test_case_1():
board_size = 5
knight_positions = [(1, 1), (4, 4)]
assert can_all_knights_move_simultaneously(board_size, knight_positions) == "YES"
def test_case_2():
board_size = 6
knight_positions = [(1, 1), (2, 3), (3, 2)]
assert ... | [
{
"docstring": null,
"function_declaration": "def is_valid_move(board_size, x, y):",
"function_name": "is_valid_move",
"parameter_list": "(board_size, x, y)"
},
{
"docstring": null,
"function_declaration": "def generate_moves(board_size, current_pos):",
"function_name": "generate_mov... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_move(knights, N):\n \"\"\"\n Determine if all knights can simultaneously make one valid move without \n landing on any other knight’s... | trial_gpt4o_5 | {
"original_instruction": "In a distant land called Matrixonia, the king has a square N x N chessboard. Each cell in the chessboard either contains a friendly knight or is empty. Knights can jump to certain positions on the chessboard following specific rules - they can move in an L-shape: two cells in one direction ... | 0.58823 | Code_Contests_39996 | C | [
"is_valid_move",
"generate_moves",
"can_all_knights_move_simultaneously"
] | 3 | [
[
"can_all_knights_move_simultaneously",
"generate_moves"
],
[
"generate_moves",
"is_valid_move"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dd9ec967dd139065931035cc6b54ee51316bfc75 | 19d5ce6513a20d066abeb4bedeab25824670f354 | |||
v1.0 | complete | Code_Contests | Code_Contests_39910_C | def max_rectangle_containing_plants(n: int, m: int, garden: List[str]) -> int:
""" Calculate the maximum area of contiguous plant cells forming a rectangle in a grid.
>>> max_rectangle_containing_plants(4, 5, [".....", ".*.*.", ".***.", ".***."])
6
>>> max_rectangle_containing_plants(3, 3, ["***", ... | def maximalRectangle(matrix):
if not matrix:
return 0
# Function to calculate maximal histogram area using heights
def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= he... | def test_case_1():
n = 4
m = 5
garden = [
".....",
".*.*.",
".***.",
".***."
]
assert max_rectangle_containing_plants(n, m, garden) == 6
def test_case_2():
n = 3
m = 3
garden = [
"***",
"*..",
"***"
]
assert max_rectangle_c... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_containing_plants(n, m, garden):",
"function_name": "max_rectangle_contai... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n = len(matrix)\n m = len(matrix[0])\n \n # Initialize height, left... | trial_gpt4o_2 | {
"original_instruction": "A garden is laid out as an n x m grid. Each cell in the grid can either contain a plant or be empty. Over time, some plant cells may die due to adverse conditions and become empty cells. You are tasked with calculating the maximum number of contiguous cells containing plants that form a rec... | 0.640626 | Code_Contests_39910 | C | [
"maximalRectangle",
"max_rectangle_containing_plants"
] | 2 | [
[
"max_rectangle_containing_plants",
"maximalRectangle"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0894739072d4d40e95afa01e0ee863a6b9693dc3 | 771ba9a6eeb96b82ebd73640f71485c1eef48fc4 | |||
v1.0 | complete | Code_Contests | Code_Contests_39686_C | def critical_streets(n: int, m: int, golds: List[int], streets: List[Tuple[int, int]], k: int, collapsed: List[Tuple[int, int]]) -> str:
"""Determine if the remaining streets are sufficient to keep the city connected, or if a critical street needs to be reconstructed to ensure connectivity.
Args:
n (in... | from collections import defaultdict
def find_set(parent, u):
if parent[u] != u:
parent[u] = find_set(parent, parent[u])
return parent[u]
def union_sets(parent, rank, u, v):
root_u = find_set(parent, u)
root_v = find_set(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]... | def test_no_streets_destroyed():
inp = """4 3
3 6 9 12
1 2
2 3
3 4
0
"""
expected = "Connected"
assert run_test_case(inp) == expected
def test_connected_after_destroying_some_streets():
inp = """6 7
1 1 1 1 1 1
1 2
2 3
3 4
4 5
5 6
6 1
2 5
2
1 2
2 3
"""
expected = "Connected"
assert run_test_cas... | [
{
"docstring": null,
"function_declaration": "def find_set(parent, u):",
"function_name": "find_set",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union_sets(parent, rank, u, v):",
"function_name": "union_sets",
"parameter_list": "(parent, ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_connected_components(n, edges):\n \"\"\"\n Finds connected components in a graph.\n \"\"\"\n from collections import defaultdict, dequ... | trial_gpt4o_2 | {
"original_instruction": "A city has n houses and m streets. Each street connects exactly two houses and all the houses of the city are connected to each other either directly or indirectly through the streets. Each house has a certain amount of gold coins inside it.\n\nAn earthquake occurs in the city causing some ... | 0.572996 | Code_Contests_39686 | C | [
"find_set",
"union_sets",
"is_city_connected",
"critical_streets",
"main"
] | 5 | [
[
"critical_streets",
"is_city_connected"
],
[
"is_city_connected",
"find_set"
],
[
"is_city_connected",
"union_sets"
],
[
"union_sets",
"find_set"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 704ca649b59791ef05d3f94b432966b0fb78c981 | eece5e6257079b89f5d3ff3fc87c157facc19edd | |||
v1.0 | complete | Code_Contests | Code_Contests_39879_C | def is_prime(n: int) -> bool:
""" Determines if a given number n is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
"""
pass
def find_prime_indices(sequence: List[int]) -> str:
""" Finds the indices of all prime numbers in the given sequence.
... | def is_prime(n):
"""
Determines if a given number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def find_prime_indi... | from solution import is_prime, find_prime_indices
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(25) == False
assert is_prime(1) == False
assert is_prime(0) == False
def test_find_prime_indi... | [
{
"docstring": "Determines if a given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds the indices of all prime numbers in the given sequence.",
"function_declaration": "def find_prime_indices(s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_indices(sequence):\n \"\"\"\n Given a sequence of integers, find the indices of all prime numbers in the sequence.\n Args:\n sequence... | trial_gpt4o_2 | {
"original_instruction": "In a fierce battle of wits, Alice and Bob, two brilliant programmers, face off in a competition with a twist on prime numbers. They have a sequence of integers and need to determine the relative position of prime numbers within the sequence for further analysis.\n\nYou are to write a progra... | 0.792726 | Code_Contests_39879 | C | [
"is_prime",
"find_prime_indices"
] | 2 | [
[
"find_prime_indices",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 57e2dd08f69d49104f139dba4b4b3760270240d9 | efede87ef4634c1983b075ae50045296ec405c5c | |||
v1.0 | complete | Code_Contests | Code_Contests_40006_C | from typing import List
def find_optimal_order(n: int, m: int, skills: List[List[int]]) -> List[int]:
"""
Finds the optimal order of activities to minimize the maximum skill level
difference between consecutive activities for any participant.
Parameters:
n (int): the number of participants.
... | from itertools import permutations
def calculate_max_diff(order, skills):
"""
Calculate the maximum skill difference for the given activity order.
"""
n, m = len(skills), len(order)
max_diff = 0
for i in range(n):
prev_skill = skills[i][order[0]]
for j in range(1, m):
... | from solution import find_optimal_order
def test_example_case():
n, m = 3, 4
skills = [
[10, 20, 30, 40],
[15, 25, 35, 45],
[5, 15, 25, 35]
]
order = find_optimal_order(n, m, skills)
assert calculate_max_diff([x - 1 for x in order], skills) == 10
def test_single_participant... | [
{
"docstring": "Calculate the maximum skill difference for the given activity order.",
"function_declaration": "def calculate_max_diff(order, skills):",
"function_name": "calculate_max_diff",
"parameter_list": "(order, skills)"
},
{
"docstring": "Finds the optimal order of activities.",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef find_optimal_order(n, m, skills_matrix):\n \"\"\"\n Find the optimal order of activities that minimizes the... | trial_gpt4o_9 | {
"original_instruction": "A start-up company is organizing a hackathon event where n participants will compete in m different activities. The organizers want to ensure that each participant gets a fair chance to compete and win prizes. Each participant has a certain skill level si in each activity. \n\nThe organizer... | 0.579841 | Code_Contests_40006 | C | [
"calculate_max_diff",
"find_optimal_order"
] | 2 | [
[
"find_optimal_order",
"calculate_max_diff"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9da261e87c4d3e76cbf422783133036bef17f4d5 | f07fc6e0f74d3e9615486d67203af2304c13bfa0 | |||
v1.0 | complete | Code_Contests | Code_Contests_40087_C | def palindrome_result(s: str) -> str:
""" Determine if the string is a palindrome, ignoring non-letter characters and case.
Args:
s (str): The input string consisting of lowercase English letters and potentially other characters.
Returns:
str: "Yes" if the processed string is a palindrome, "... | def is_palindrome(s):
"""
Determine if the string is a palindrome, ignoring non-letter characters and case.
"""
# Normalizing the string: removing non-letter characters and converting to lowercase
normalized_s = ''.join(char.lower() for char in s if char.isalpha())
# Checking if the normali... | from solution import palindrome_result
def test_basic_palindrome():
assert palindrome_result("A man, a plan, a canal, Panama") == "Yes"
def test_non_palindrome():
assert palindrome_result("race a car") == "No"
def test_palindrome_with_numbers():
assert palindrome_result("Madam In Eden, I'm Adam 123") == ... | [
{
"docstring": "Determine if the string is a palindrome, ignoring non-letter characters and case.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def palindrome_result(s):",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Determine if the string is a palindrome, ignoring any characters that are not letters and ignoring case.\n \n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a string consisting of lowercase English letters. Your task is to determine if the string is a palindrome, ignoring any characters that are not letters and ignoring case.\n\nInput\n\nThe only line of input contains a string s (1 ≤ length(s) ≤ 10^6).\n\nOutput\n\nOutput \"Yes\"... | 0.827421 | Code_Contests_40087 | C | [
"is_palindrome",
"palindrome_result"
] | 2 | [
[
"palindrome_result",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6f808ada0ea30737b2d01e7a68335fa9ab00d55b | cf7982fcd9d7860e965d9376511c821c93b58dc3 | |||
v1.0 | complete | Code_Contests | Code_Contests_40057_C | def min_additional_routes_needed(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of additional bus routes needed to make the transportation system strongly connected.
>>> min_additional_routes_needed(4, 3, [(1, 2), (2, 3), (3, 1)])
1
>>> min_additional_routes_neede... | def find_strongly_connected_components(n, edges):
from collections import defaultdict, deque
def fill_order(v, visited, stack, adj):
visited[v] = True
for i in adj[v]:
if not visited[i]:
fill_order(i, visited, stack, adj)
stack = stack.append(v)
def dfs(... | from solution import min_additional_routes_needed
def test_min_additional_routes_needed_case1():
assert min_additional_routes_needed(4, 3, [(1, 2), (2, 3), (3, 1)]) == 1
def test_min_additional_routes_needed_case2():
assert min_additional_routes_needed(5, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)]) == 0
def... | [
{
"docstring": null,
"function_declaration": "def find_strongly_connected_components(n, edges):",
"function_name": "find_strongly_connected_components",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def min_additional_routes_needed(n, m, edges):",
"f... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef add_minimum_routes(N, M, routes):\n graph = defaultdict(list)\n reverse_gr... | trial_gpt4o_4 | {
"original_instruction": "A city has a convenient public transportation system represented by a directed graph G. Each vertex in G represents a bus stop, and each directed edge represents a direct bus route from one stop to another.\n\nYour task is to determine the minimum number of additional bus routes needed to m... | 0.691137 | Code_Contests_40057 | C | [
"find_strongly_connected_components",
"min_additional_routes_needed"
] | 2 | [
[
"min_additional_routes_needed",
"find_strongly_connected_components"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e9965e842a1e0c5bdc3d70e6854300776206a5b | 7f7215b00a01def59cdee16154ad86aae3eb3786 | |||
v1.0 | complete | Code_Contests | Code_Contests_39803_C | def encode(message: str, key: str) -> str:
"""
Encodes the message using the given key.
Parameters:
- message (str): The message to encode.
- key (str): The key to use for encoding.
Returns:
- str: The encoded message.
Examples:
>>> encode("hello", "key")
'\x00\x19\r... | def encode(message: str, key: str) -> str:
"""
Encodes the message using the given key.
Parameters:
- message (str): The message to encode.
- key (str): The key to use for encoding.
Returns:
- str: The encoded message.
"""
n, k = len(message), len(key)
encoded = []
for ... | def test_encode_decode():
message = "hello"
key = "key"
encoded = encode(message, key)
decoded = decode(encoded, key)
assert encoded == ''.join([chr(104 ^ 107), chr(101 ^ 101), chr(108 ^ 121), chr(108 ^ 107), chr(111 ^ 101)])
assert decoded == message
def test_encode_repeat_key():
mess... | [
{
"docstring": "Encodes the message using the given key.\n\nParameters:\n- message (str): The message to encode.\n- key (str): The key to use for encoding.\n\nReturns:\n- str: The encoded message.",
"function_declaration": "def encode(message, key):",
"function_name": "encode",
"parameter_list": "(m... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def encode(message: str, key: str) -> str:\n \"\"\"\n Encodes the message using the key by applying bitwise XOR operation\n on each character. The... | trial_gpt4o_4 | {
"original_instruction": "You are tasked with developing a secure communication algorithm for a new messaging application. The security of messages relies on encoding and decoding operations using a shared secret key between the sender and the receiver. Each message is encoded by first converting it to its ASCII val... | 0.669547 | Code_Contests_39803 | C | [
"encode",
"decode"
] | 2 | [
[
"decode",
"encode"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e367684ca247c977b09a5a94ce05d03784524456 | 502560a2d76efe2677480595fd53e8f5e819ae0e | |||
v1.0 | complete | Code_Contests | Code_Contests_40211_C | from typing import List
def is_prime(num: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(17) True
"""
pass
def smallest_prime_greater_than(n: int) -> int:
""" Return the smallest prime number greater than n.
... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import is_prime, smallest_prime_greater_than
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_smallest_prime_greater_than():
assert smallest_prime_greater_than(... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Return the smallest prime number greater than n.",
"function_declaration": "def smallest_prime_greater_than(n):",
"fun... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(x):\n \"\"\"\n Checks if a number x is prime.\n \"\"\"\n if x <= 1:\n return False\n if x <= 3:\n ... | trial_gpt4o_1 | {
"original_instruction": "Implement a function that accepts a positive integer `n` and outputs the smallest prime number that is greater than `n`.\n\n### Input\n\n- A single integer `n` (1 ≤ n ≤ 10^6)\n\n### Output\n\n- A single integer which is the smallest prime number that is greater than `n`.\n\n### Examples\n\n... | 0.799262 | Code_Contests_40211 | C | [
"is_prime",
"smallest_prime_greater_than"
] | 2 | [
[
"smallest_prime_greater_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 075dd558d7a415d1c856d4248af4e38ee2df822c | d9228078198f85a619e4ac1b6038c52d7016edef | |||
v1.0 | complete | Code_Contests | Code_Contests_40190_C | def is_prime(num: int) -> bool:
"""
Helper function to determine if a number is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(11) == True
>>> is_prime(21) == False
>>> is_prime(23) == True
"""
def smallest_prime_ge(n: int) -> int:
... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
retu... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(21) == False
assert is_prime(23) == True
def test_smallest_prime_ge():
assert smallest_prime_ge(10) == 11
assert smallest_prime_ge(15) == 17... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than or equal to n.",
"function_declaration": "def smalle... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "Given a number n (1 ≤ n ≤ 10^5), determine the smallest prime number p that is greater than or equal to n. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. For example, 5 is prime because the only ways of writing it as a pro... | 0.80721 | Code_Contests_40190 | C | [
"is_prime",
"smallest_prime_ge"
] | 2 | [
[
"smallest_prime_ge",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c41caee023c07d6ea65242fe1e16ab9d1c7614ee | 06189e9e0c6209df30db65efdce01fc891a0c22e | |||
v1.0 | complete | Code_Contests | Code_Contests_39982_C | def max_product_of_two_numbers_from_array(test_cases):
"""Compute the maximum product of any two different numbers in the array.
Args:
test_cases (List[List[int]]): List of test cases with each test case containing a list of integers.
Returns:
List[int]: List of maximum products for each tes... | def max_product_of_two_numbers_from_array(test_cases):
results = []
for array in test_cases:
n = len(array)
array.sort()
# Compute the max product of two highest numbers or two lowest (most negative) numbers
max_product = max(array[0] * array[1], array[-1] * array[-... | import pytest
from solution import parse_input, max_product_of_two_numbers_from_array, process
def test_max_product_of_two_numbers_from_array():
# Example cases
assert max_product_of_two_numbers_from_array([[1, 3, 5, 2]]) == [15]
assert max_product_of_two_numbers_from_array([[-10, -20, 5, 6, -3]]) == [200]... | [
{
"docstring": null,
"function_declaration": "def max_product_of_two_numbers_from_array(test_cases):",
"function_name": "max_product_of_two_numbers_from_array",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"functio... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_product_pair(numbers):\n \"\"\"\n Returns the maximum product of any two different numbers in the given list of integers.\n \"\"\"\n nu... | trial_gpt4o_2 | {
"original_instruction": "Soumya is passionate about mathematics and often finds herself playing with numbers. One day, her friend challenged her with a task involving numbers. Her friend provided her with an array of integers and asked her to find the maximum product of any two different numbers in the array. Soumy... | 0.658462 | Code_Contests_39982 | C | [
"max_product_of_two_numbers_from_array",
"parse_input",
"process"
] | 3 | [
[
"process",
"max_product_of_two_numbers_from_array"
],
[
"process",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3d9b6e055fc625681edf96e4a8dea3ed997079fe | 0453e407622cbfcae87fd20ede37264becabec52 | |||
v1.0 | complete | Code_Contests | Code_Contests_39833_C | import math
from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Check if a number is a prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(22)
False
"""
pass
def has_beautiful_subarray(n: int, a: List[int]) -> str:
"""
... | import math
def is_prime(num):
"""
Check if a number is a prime.
"""
if num < 2:
return False
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return False
return True
def has_beautiful_subarray(n, a):
"""
Determine if the array a has any beautif... | from solution import process_queries, is_prime, has_beautiful_subarray
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(22) == False
assert is_prime(23) == True
def test_has_beautiful_subarray():
... | [
{
"docstring": "Check if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determine if the array a has any beautiful subarray.",
"function_declaration": "def has_beautiful_subarray(n, a):",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\" Helper function to check if a number is prime \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return Tru... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of n integers a = [a_1, a_2, …, a_n]. Let's define a subarray of a as beautiful if it contains at least one pair of distinct adjacent elements whose sum is a prime number.\n\nFor example, let a = [2, 4, 5, 3]. In this case, the subarrays [2, 4], [4, 5], [5, 3] are bea... | 0.670271 | Code_Contests_39833 | C | [
"is_prime",
"has_beautiful_subarray",
"process_queries"
] | 3 | [
[
"has_beautiful_subarray",
"is_prime"
],
[
"process_queries",
"has_beautiful_subarray"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | f84210f766e56dd31e3923ac95c7b654584023ee | 19fc0c710a99325d4e645ca39c43520e86175ea5 | |||
v1.0 | complete | Code_Contests | Code_Contests_40423_C | def sieve_of_eratosthenes(limit: int) -> List[int]:
"""
Finds all prime numbers up to a given limit using the Sieve of Eratosthenes algorithm.
"""
def sum_of_primes(n: int) -> int:
"""
Calculates the sum of all prime numbers less than or equal to a given number N.
>>> sum_of_primes(10) 17
... | def sieve_of_eratosthenes(limit):
primes = [True] * (limit + 1)
p = 2
while (p * p <= limit):
if primes[p] == True:
for i in range(p * p, limit + 1, p):
primes[i] = False
p += 1
return [p for p in range(2, limit + 1) if primes[p]]
def sum_of_primes(n):
pr... | from solution import sieve_of_eratosthenes, sum_of_primes, process_test_cases
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
assert sieve_of_eratosthenes(2) == [2]
def test_sum_of_primes():
assert sum_... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": null,
"function_declaration": "def sum_of_primes(n):",
"function_name": "sum_of_primes",
"parameter_list": "(n... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_primes(N):\n \"\"\"\n Returns the sum of all prime numbers less than or equal to N.\n \"\"\"\n if N < 2:\n return 0\n \n ... | trial_gpt4o_1 | {
"original_instruction": "Rhea loves playing with numbers, especially prime numbers. One day, she thought of a game where she picks a random number N and tries to determine the sum of prime numbers less than or equal to N. This may look very simple but it was really time-consuming as the value of N grew.\n\nThen she... | 0.666474 | Code_Contests_40423 | C | [
"sieve_of_eratosthenes",
"sum_of_primes",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"sum_of_primes"
],
[
"sum_of_primes",
"sieve_of_eratosthenes"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 507108a56b223c3955452fdc215e13c59fee7cd7 | bc0ce26d5d5fc775d4a2e5c18f0e024836148417 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.