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_49425_C | from typing import List, Tuple
def subtree_sums(n: int, edges: List[Tuple[int, int]]) -> List[int]:
""" Calculate the sum of subtrees for each node in a binary tree.
>>> subtree_sums(5, [(1, 2), (1, 3), (2, 4), (2, 5)])
[15, 11, 3, 4, 5]
>>> subtree_sums(3, [(1, 2), (1, 3)])
[6, 2, 3]
"""
Uni... | def subtree_sums(n, edges):
from collections import defaultdict
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
subtree_sum = [0] * (n + 1)
visited = [False] * (n + 1)
def dfs(node):
visited[node] = True
total_sum = node
... | def test_case_1():
assert process_input_and_solve(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == [15, 11, 3, 4, 5]
def test_case_2():
assert process_input_and_solve(3, [(1, 2), (1, 3)]) == [6, 2, 3]
def test_case_3():
assert process_input_and_solve(7, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == [28, 11,... | [
{
"docstring": null,
"function_declaration": "def subtree_sums(n, edges):",
"function_name": "subtree_sums",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_solve(n, edges):",
"function_name": "process_input_and_solve",
"param... | [
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 subtree_sum(n, edges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:\n graph[u].a... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree. For each node of the tree, find and note down the sum of values of all nodes forming the subtree rooted at that node.\n\nFor example, consider the binary tree below:\n\n```\n 1\n / \\\n 2 3\n / \\\n4 5\n```\n\nThe sums of the subtrees for each node are... | 0.549734 | Code_Contests_49425 | C | [
"subtree_sums",
"process_input_and_solve"
] | 2 | [
[
"process_input_and_solve",
"subtree_sums"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9e66901c35f5f3ec5177d00cfe42096e1085de09 | 24672a87fbee0ce39374771ba072f5bc8f7c1428 | |||
v1.0 | complete | Code_Contests | Code_Contests_49437_C | def rob(houses):
"""
Returns the maximum amount of money you can rob without alerting the police.
>>> rob([1, 2, 3, 1])
4
>>> rob([2, 7, 9, 3, 1])
12
>>> rob([0])
0
>>> rob([1,2])
2
>>> rob([5,5,10,100,10,5])
110
"""
pass
def max_robbery(test_cases):
"""
... | def rob(houses):
"""
Returns the maximum amount of money you can rob without alerting the police.
"""
prev1 = prev2 = 0
for money in houses:
temp = prev1
prev1 = max(prev2 + money, prev1)
prev2 = temp
return prev1
def max_robbery(test_cases):
results = []
for cas... | from solution import rob, parse_input, max_robbery, solve
def test_rob():
assert rob([1, 2, 3, 1]) == 4
assert rob([2, 7, 9, 3, 1]) == 12
assert rob([0]) == 0
assert rob([1,2]) == 2
assert rob([5,5,10,100,10,5]) == 110
def test_parse_input():
input_data = "2\n4\n1 2 3 1\n5\n2 7 9 3 1"
test... | [
{
"docstring": "Returns the maximum amount of money you can rob without alerting the police.",
"function_declaration": "def rob(houses):",
"function_name": "rob",
"parameter_list": "(houses)"
},
{
"docstring": null,
"function_declaration": "def max_robbery(test_cases):",
"function_na... | [
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 rob(houses):\n \"\"\"\n Determines the maximum amount of money that can be robbed from a row of houses \n without alerting the police, i.e., w... | trial_gpt4o_2 | {
"original_instruction": "You have a row of houses arranged in a straight line, each house having a certain amount of money stashed. However, you cannot rob two adjacent houses due to the security system in place that will automatically alert the police if two adjacent houses were broken into on the same night.\n\nW... | 0.548736 | Code_Contests_49437 | C | [
"rob",
"max_robbery",
"parse_input",
"solve"
] | 4 | [
[
"max_robbery",
"rob"
],
[
"solve",
"max_robbery"
],
[
"solve",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 775e1d2ed58391937f733dd9b8bd3123f44c04e0 | 98d7a8f1087480211f7e5f33c22f21700dae8804 | |||
v1.0 | complete | Code_Contests | Code_Contests_49633_C | from typing import List
def is_palindrome(s: str) -> bool:
""" Check if a given string is a palindrome.
>>> is_palindrome("abba")
True
>>> is_palindrome("abcba")
True
>>> is_palindrome("abca")
False
>>> is_palindrome("a")
True
>>> is_palindrome("")
True
"""
pass
def... | def is_palindrome(s):
return s == s[::-1]
def can_form_palindrome(s):
if is_palindrome(s):
return True
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
# Try removing either left or right character
without_left = s[left+1:right+1]
... | from solution import palindrome_check, is_palindrome, can_form_palindrome
def test_is_palindrome():
assert is_palindrome("abba") == True
assert is_palindrome("abcba") == True
assert is_palindrome("abca") == False
assert is_palindrome("a") == True
assert is_palindrome("") == True
def test_can_form_... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
... | [
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_palindrome(s):\n return s == s[::-1]\n\ndef can_form_palindrome_by_removal(s):\n if is_palindrome(s):\n return \"YES\"\n\n left, rig... | trial_gpt4o_1 | {
"original_instruction": "You are given a string of lowercase Latin letters. You are allowed to remove at most one character from this string. Your task is to determine if it is possible to obtain a palindrome by removing exactly one character or not removing any character at all.\n\nInput\nThe first line of input c... | 0.845384 | Code_Contests_49633 | C | [
"is_palindrome",
"can_form_palindrome",
"palindrome_check"
] | 3 | [
[
"can_form_palindrome",
"is_palindrome"
],
[
"palindrome_check",
"can_form_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6ddaf0702d9fbff797a396302a16050208fc7994 | 604b9392aa243bfbf48b107e660c92b1f3500ed6 | |||
v1.0 | complete | Code_Contests | Code_Contests_49182_C | from typing import List, Tuple, Dict
from collections import deque, defaultdict
def find_shortest_cycle(n: int, adj_list: Dict[int, List[int]]) -> int:
"""
Finds the length of the shortest cycle in a directed graph.
If no cycle exists, returns -1.
Parameters:
n (int): Number of vertices in the gra... | from collections import deque, defaultdict
def find_shortest_cycle(n, adj_list):
"""
Finds the length of the shortest cycle in a directed graph.
If no cycle exists, returns -1.
Parameters:
n (int): Number of vertices in the graph.
adj_list (dict): Adjacency list of the graph.
Returns:
... | import pytest
from solution import detect_cycles
def test_single_cycle():
test_cases = [
(4, 5, [(1, 2), (2, 3), (3, 1), (3, 4), (4, 2)])
]
expected = [3]
assert detect_cycles(test_cases) == expected
def test_no_cycle():
test_cases = [
(3, 2, [(1, 2), (2, 3)])
]
expected = ... | [
{
"docstring": "Finds the length of the shortest cycle in a directed graph.\nIf no cycle exists, returns -1.\n\nParameters:\nn (int): Number of vertices in the graph.\nadj_list (dict): Adjacency list of the graph.\n\nReturns:\nint: Length of the shortest cycle, or -1 if no cycle exists.",
"function_declarat... | [
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, defaultdict\n\ndef shortest_cycle_length(n, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u]... | trial_gpt4o_2 | {
"original_instruction": "You are given a directed graph represented as an adjacency list.\n\nYour task is to detect if the graph contains a cycle. If a cycle exists, determine the length of the shortest cycle in the graph. If no cycle exists, output -1.\n\nA cycle is defined as a non-empty sequence of edges where t... | 0.687809 | Code_Contests_49182 | C | [
"find_shortest_cycle",
"process_test_cases",
"detect_cycles"
] | 3 | [
[
"detect_cycles",
"process_test_cases"
],
[
"process_test_cases",
"find_shortest_cycle"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 9f2da6bb19f45dd05eee289bd25986fa16cb2465 | 3aba487b1bf83030e3f8bbdb526575540211c091 | |||
v1.0 | complete | Code_Contests | Code_Contests_49200_C | import heapq
from typing import List, Tuple
def max_energy_capsules(n: int, m: int, wormholes: List[Tuple[int, int, int]]) -> int:
"""Calculate the maximum number of energy capsules the robot can collect on its way from planet 1 to planet n.
Args:
n (int): Number of planets.
m (int): Number of wor... | import heapq
def max_energy_capsules(n, m, wormholes):
# Create a graph from the wormholes
graph = [[] for _ in range(n + 1)]
for u, v, w in wormholes:
graph[u].append((v, w))
# Dijkstra-like algorithm to find the maximum path value
max_capsules = [-1] * (n + 1)
max_capsules[1] = 0... | def test_max_energy_capsules():
input_data_1 = "5 6\n1 2 5\n1 3 10\n2 4 15\n3 4 5\n4 5 10\n3 5 20"
assert max_energy_capsules_from_input(input_data_1) == 30
input_data_2 = "4 3\n1 2 10\n2 3 5\n3 4 10"
assert max_energy_capsules_from_input(input_data_2) == 25
input_data_3 = "3 1\n1 3 7"
assert ... | [
{
"docstring": null,
"function_declaration": "def max_energy_capsules(n, m, wormholes):",
"function_name": "max_energy_capsules",
"parameter_list": "(n, m, wormholes)"
},
{
"docstring": null,
"function_declaration": "def max_energy_capsules_from_input(input_data):",
"function_name": ... | [
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 heapq import heappop, heappush\nimport sys\n\ndef max_energy_capsules(n, m, wormholes):\n adj = [[] for _ in range(n + 1)]\n for u, v, w in worm... | trial_gpt4o_2 | {
"original_instruction": "In a distant galaxy, there are n planets (numbered 1 through n) and m one-way wormholes connecting them. The planets have a unique hierarchy such that each planet can influence certain other planets directly through a wormhole.\n\nA scientist on planet 1 wants to send a robot to planet n to... | 0.531642 | Code_Contests_49200 | C | [
"max_energy_capsules",
"max_energy_capsules_from_input"
] | 2 | [
[
"max_energy_capsules_from_input",
"max_energy_capsules"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ea62cec385cda242b252910dad4f56eb081e9e44 | 219bab6f96274632e8e2f7e805c220cd10f05e82 | |||
v1.0 | complete | Code_Contests | Code_Contests_49227_C | from math import factorial
MOD = 10**9 + 7
def count_valid_strings(n, k, char_counts):
"""
Calculate the number of valid permutations of a string with given character counts.
"""
# calculate numerator: n!
numerator = factorial(n) % MOD
# calculate denominator: product of factorials of counts
... | from math import factorial
MOD = 10**9 + 7
def count_valid_strings(n, k, char_counts):
"""
Calculate the number of valid permutations of a string with given character counts.
"""
# calculate numerator: n!
numerator = factorial(n) % MOD
# calculate denominator: product of factorials of counts
... | from solution import process_input_and_calculate
def test_example_1():
n, k = 6, 3
char_data = [('a', 2), ('b', 2), ('c', 2)]
assert process_input_and_calculate(n, k, char_data) == 90
def test_example_2():
n, k = 4, 2
char_data = [('x', 2), ('y', 2)]
assert process_input_and_calculate(n, k, ch... | [
{
"docstring": "Calculate the number of valid permutations of a string with given character counts.",
"function_declaration": "def count_valid_strings(n, k, char_counts):",
"function_name": "count_valid_strings",
"parameter_list": "(n, k, char_counts)"
},
{
"docstring": "Process the input an... | [
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\nMOD = 10**9 + 7\n\ndef count_valid_strings(n, k, char_counts):\n \"\"\"\n Returns the number of valid strings of length n with exactly... | trial_gpt4o_1 | {
"original_instruction": "Wall-E loves exploring the world of strings and one day he stumbled upon a special problem. He came across a compressed way of representing string sequences using counts of each character. For example, a string \"aabbcc\" can be represented as {(a, 2), (b, 2), (c, 2)}. Wall-E wants to gener... | 0.689725 | Code_Contests_49227 | C | [
"count_valid_strings",
"process_input_and_calculate"
] | 2 | [
[
"process_input_and_calculate",
"count_valid_strings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 89bf34328332f9e80fbe156b602f990b6bcb8f47 | 99b431484ec33fb36378409c2f0861e9ceaa414b | |||
v1.0 | complete | Code_Contests | Code_Contests_48826_C | from typing import List
def combined_sum(n: int, numbers: List[int]) -> int:
""" Returns combined sum of A and B's active numbers after all integers are chosen.
>>> combined_sum(5, [1, 2, 3, 4, 5])
15
>>> combined_sum(3, [10, 20, 30])
60
>>> combined_sum(1, [42])
42
>>> combined_sum(4, ... | def combined_sum(n, numbers):
"""
Returns combined sum of A and B's active numbers after all integers are chosen.
As we can add the integers to either A or B, the final combined sum will simply be the sum of all integers in the list.
"""
return sum(numbers)
# Function to parse the input, compute th... | from solution import combined_sum, calculate_combined_sum
def test_combined_sum_simple_case():
assert combined_sum(5, [1, 2, 3, 4, 5]) == 15
def test_combined_sum_another_case():
assert combined_sum(3, [10, 20, 30]) == 60
def test_combined_sum_single_element():
assert combined_sum(1, [42]) == 42
def tes... | [
{
"docstring": "Returns combined sum of A and B's active numbers after all integers are chosen.\nAs we can add the integers to either A or B, the final combined sum will simply be the sum of all integers in the list.",
"function_declaration": "def combined_sum(n, numbers):",
"function_name": "combined_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 combined_sum_of_game_numbers(n, numbers):\n \"\"\"\n Returns the combined total sum of all chosen numbers for A and B in the game.\n \n Arg... | trial_gpt4o_2 | {
"original_instruction": "Given two cousins A and B, both play a number game to test their arithmetic skills. They take turns to choose a single positive integer from a list of integers and the chosen number is added to either A or B's active number according to predefined rules. The purpose of the game is to find o... | 0.650372 | Code_Contests_48826 | C | [
"combined_sum",
"calculate_combined_sum"
] | 2 | [
[
"calculate_combined_sum",
"combined_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4195e86cf34112396961b9896c89adf4c982f6f0 | 3fe7633472a525ac0c8710335b25be61c27e9fb6 | |||
v1.0 | complete | Code_Contests | Code_Contests_49734_C | from typing import List, Tuple
def find_max_difference_brige(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Determines if there exists an edge in the graph that, when removed, will separate the graph into exactly two connected components.
If such an edge exists, find the edge whose removal ... | def find_max_difference_brige(n, m, edges):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
def dfs(u, visited, disc, low, parent):
nonlocal time, bridge, max_edge
visited[u] = True
disc[u] = low[u] = time
time += 1
for v, w in gr... | from solution import find_max_difference_brige
def test_example1():
n = 4
m = 3
edges = [(1, 2, 10), (2, 3, 5), (3, 4, 6)]
assert find_max_difference_brige(n, m, edges) == 10
def test_example2():
n = 5
m = 4
edges = [(1, 2, 1), (2, 3, 2), (2, 4, 3), (4, 5, 4)]
assert find_max_differenc... | [
{
"docstring": null,
"function_declaration": "def find_max_difference_brige(n, m, edges):",
"function_name": "find_max_difference_brige",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def example():",
"function_name": "example",
"parameter_lis... | [
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_critical_edge(n, m, edges):\n from collections import defaultdict\n import copy\n\n # Step 1: Build the adjacency list of the graph\n ... | trial_gpt4o_1 | {
"original_instruction": "You're given an undirected and connected graph with n vertices and m edges. Each edge has a weight associated with it. Your task is to determine if there exists an edge in the graph that, when removed, will separate the graph into exactly two connected components. If such an edge exists, al... | 0.674586 | Code_Contests_49734 | C | [
"find_max_difference_brige",
"example"
] | 2 | [
[
"example",
"find_max_difference_brige"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d1507bfccac3a3619fce73e63ba3f3fe971e04d1 | f64b419da52031e33c81a7ace06a2b0dd877e0c3 | |||
v1.0 | complete | Code_Contests | Code_Contests_49301_C | from typing import List, Dict
def merge_sort(arr: List[int]) -> None:
if len(arr) > 1:
mid = len(arr) // 2
L = arr[:mid]
R = arr[mid:]
merge_sort(L)
merge_sort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] <= R[j]:
a... | def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
L = arr[:mid]
R = arr[mid:]
merge_sort(L)
merge_sort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] <= R[j]:
arr[k] = L[i]
i += 1
el... | from solution import sort_heights
def test_sort_heights_case1():
heights = [170, 155, 160, 175, 165]
result = sort_heights(heights)
assert result["merge_sort"] == [155, 160, 165, 170, 175]
assert result["merge_sort_stability"] == "Stable"
assert result["quick_sort"] == [155, 160, 165, 170, 175]
... | [
{
"docstring": null,
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
... | [
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": "import math\n\ndef merge_sort(arr):\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n right_half = arr[mid:]\n\n ... | trial_gpt4o_2 | {
"original_instruction": "A line of people need to be arranged based on their heights. The heights of all people standing in the line can be represented by an array of integers where each integer denotes the height of a person.\n\nYour task is to write a program to sort the given array of heights in ascending order ... | 0.531445 | Code_Contests_49301 | C | [
"merge_sort",
"partition",
"quick_sort",
"sort_heights"
] | 4 | [
[
"quick_sort",
"partition"
],
[
"sort_heights",
"merge_sort"
],
[
"sort_heights",
"quick_sort"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7de7397068ad4ba8faf4389f424bc48659eede2d | 177fed5589789673210982bfeffd3d9fd3c69692 | |||
v1.0 | complete | Code_Contests | Code_Contests_49154_C | from typing import List
def tsp(distance_matrix: List[List[int]]) -> int:
"""Calculate the shortest possible route for the Travelling Salesman Problem
that visits each city exactly once and returns to the original city.
>>> tsp([
... [0, 10, 15, 20],
... [10, 0, 35, 25],
... [15, 3... | from itertools import permutations
def tsp(distance_matrix):
N = len(distance_matrix)
cities = list(range(N))
min_dist = float('inf')
for perm in permutations(cities[1:]):
curr_dist = 0
prev_city = 0
for city in perm:
curr_dist += distance_matrix[prev_city][city... | from solution import tsp, solve_tsp, parse_input
def test_tsp_case_1():
distance_matrix = [
[0, 10, 15, 20],
[10, 0, 35, 25],
[15, 35, 0, 30],
[20, 25, 30, 0]
]
assert tsp(distance_matrix) == 80
def test_tsp_case_2():
distance_matrix = [
[0, 29, 20],
[29... | [
{
"docstring": null,
"function_declaration": "def tsp(distance_matrix):",
"function_name": "tsp",
"parameter_list": "(distance_matrix)"
},
{
"docstring": null,
"function_declaration": "def solve_tsp(test_cases):",
"function_name": "solve_tsp",
"parameter_list": "(test_cases)"
}... | [
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 itertools import permutations\n\ndef tsp(distance_matrix):\n N = len(distance_matrix)\n cities = list(range(N))\n min_dist = float('inf')\n ... | trial_gpt4o_0 | {
"original_instruction": "The Travelling Salesman Problem (TSP) is a classic algorithmic problem in the fields of computer science and operations research. Given a list of cities and the distances between each pair of cities, the objective is to find the shortest possible route that visits each city exactly once and... | 0.584466 | Code_Contests_49154 | C | [
"tsp",
"solve_tsp",
"parse_input",
"main"
] | 4 | [
[
"solve_tsp",
"tsp"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | d3c2703eb830c3e54e1958f2bcb15a9daadb2040 | e9e7b0f927be7fa5f7891f7f894f7079808e104a | |||
v1.0 | complete | Code_Contests | Code_Contests_49474_C | def prefix_sums(arr):
"""
Returns a list of prefix sums for the given array.
"""
...
def range_sum(arr, queries):
"""
For each query (l, r) calculate the sum of the elements
from the l-th to the r-th position in the list (inclusive).
>>> arr = [1, 2, 3, 4, 5]
>>> queries =... | def prefix_sums(arr):
"""
Returns a list of prefix sums for the given array.
"""
prefix = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix[i] = prefix[i - 1] + arr[i - 1]
return prefix
def range_sum(arr, queries):
"""
For each query (l, r) calculate the sum of the el... | def test_prefix_sums():
assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
assert prefix_sums([-1, -2, 3, 4, 5]) == [0, -1, -3, 0, 4, 9]
assert prefix_sums([0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0]
assert prefix_sums([1]) == [0, 1]
def test_range_sum():
arr = [1, 2, 3, 4, 5]
queries = [(1... | [
{
"docstring": "Returns a list of prefix sums for the given array.",
"function_declaration": "def prefix_sums(arr):",
"function_name": "prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "For each query (l, r) calculate the sum of the elements \nfrom the l-th to the r-th position in t... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def prefix_sums(arr):\n \"\"\"\n Compute prefix sums array for the given list of integers.\n \n Args:\n arr (list):... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of n integers and a list of m queries. Each query consists of two integers l and r (1 ≤ l ≤ r ≤ n). For each query, calculate the sum of the integers from the l-th to the r-th position in the list (inclusive).\n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 10... | 0.63084 | Code_Contests_49474 | C | [
"prefix_sums",
"range_sum"
] | 2 | [
[
"range_sum",
"prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2b6c97be41c02f9bdeae3c395c750eec0c01a3a7 | 4b8e4b3853c7dc73982320da003b4ae82d4af60d | |||
v1.0 | complete | Code_Contests | Code_Contests_49952_C | def count_paths(mazes):
""" Returns a list with the number of distinct paths from the top-left to the bottom-right corner for each maze.
>>> count_paths([(3, 3, [['.', '.', '.'], ['.', 'X', '.'], ['.', '.', '.']])]) [2]
>>> count_paths([(3, 3, [['X', 'X', '.'], ['.', 'X', '.'], ['.', '.', '.']])]) [0]
"... | def count_paths(mazes):
"""
Returns a list with the number of distinct paths from the top-left to the bottom-right corner for each maze.
"""
results = []
for maze in mazes:
R, C, grid = maze
if grid[0][0] == 'X' or grid[R-1][C-1] == 'X':
results.append(0)
co... | def test_count_paths():
assert count_paths([(3, 3, [['.', '.', '.'], ['.', 'X', '.'], ['.', '.', '.']])]) == [2]
assert count_paths([(3, 3, [['X', 'X', '.'], ['.', 'X', '.'], ['.', '.', '.']])]) == [0]
assert count_paths([(1, 1, [['.']])]) == [1]
assert count_paths([(2, 2, [['.', 'X'], ['X', '.']])]) ==... | [
{
"docstring": "Returns a list with the number of distinct paths from the top-left to the bottom-right corner for each maze. ",
"function_declaration": "def count_paths(mazes):",
"function_name": "count_paths",
"parameter_list": "(mazes)"
},
{
"docstring": "Parses the input data and returns ... | [
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 count_paths_in_maze(maze, R, C):\n # Create a 2D dp array initialized with 0\n dp = [[0] * C for _ in range(R)]\n \n # Initialize the start... | trial_gpt4o_2 | {
"original_instruction": "Super Vizorix the Wizard is known for his complex and difficult mazes. He has a collection of T mazes, each of which is represented as a grid with R rows and C columns. Each cell in the grid can either be empty (.) or blocked (X). Super Vizorix wants to know the number of distinct paths fro... | 0.601833 | Code_Contests_49952 | C | [
"count_paths",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"count_paths"
],
[
"solve",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 942c7aae021e58e926fdf8b043eb1638d0069b05 | 09e7aa8a071d709886633e24a03bc4261ca51908 | |||
v1.0 | complete | Code_Contests | Code_Contests_49470_C | from typing import List, Tuple
def max_waste_flow(N: int, E: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the maximum amount of waste that can be treated by the plant from the main waste inlet to the final treatment station.
>>> max_waste_flow(4, 5, [(0, 1, 100), (0, 2, 100), (1, 2, 1), (1, 3,... | from collections import deque, defaultdict
def bfs_capacity(graph, start, end, parent):
visited = [False] * len(graph)
queue = deque([start])
visited[start] = True
while queue:
u = queue.popleft()
for ind, val in enumerate(graph[u]):
if not visited[ind] and val > 0:
... | import pytest
from solution import max_waste_flow
def test_example_case():
N = 4
E = 5
edges = [
(0, 1, 100),
(0, 2, 100),
(1, 2, 1),
(1, 3, 100),
(2, 3, 100)
]
assert max_waste_flow(N, E, edges) == 200
def test_disjoint_paths():
N = 4
E = 4
edge... | [
{
"docstring": null,
"function_declaration": "def bfs_capacity(graph, start, end, parent):",
"function_name": "bfs_capacity",
"parameter_list": "(graph, start, end, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(graph, start, end):",
"function_name": "edmo... | [
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 collections import deque\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = [False] * len(graph)\n queue = deque([source])\n visit... | trial_gpt4o_1 | {
"original_instruction": "As an engineer, you are tasked with the design and analysis of a waste treatment plant for a small town. The plant consists of various treatment stations connected by pipes. Each station has a capacity limit, and the pipes indicate the possible flow of waste between these stations. The goal... | 0.551352 | Code_Contests_49470 | C | [
"bfs_capacity",
"edmonds_karp",
"max_waste_flow"
] | 3 | [
[
"edmonds_karp",
"bfs_capacity"
],
[
"max_waste_flow",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a8c26372ffcf8f9a6d16152c691c85adf16bef05 | 94203e80f5b81b4041767100a2a601e65ed64f4c | |||
v1.0 | complete | Code_Contests | Code_Contests_48236_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def delete_node(root: TreeNode, value: int) -> TreeNode:
""" Delete a given node from the BST while preserving the properties of the BST.
>>> root = build_tree([5, 3,... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def delete_node(root: TreeNode, value: int) -> TreeNode:
if root is None:
return None
if value < root.val:
root.left = delete_node(root.left, value)
... | from solution import TreeNode, delete_node
def build_tree(values, index=0):
if index >= len(values) or values[index] is None:
return None
node = TreeNode(values[index])
node.left = build_tree(values, 2*index + 1)
node.right = build_tree(values, 2*index + 2)
return node
def tree_to_list(roo... | [] | [
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 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_2 | {
"original_instruction": "You are given a binary search tree (BST) with n nodes. Each node of the BST contains an integer value and a pointer to its left and right child nodes. Your task is to implement a function that deletes a given node from the BST while preserving the properties of the BST.\n\nThe properties of... | 0.632585 | Code_Contests_48236 | C | [
"delete_node",
"get_min"
] | 2 | [
[
"delete_node",
"get_min"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8f353d7d6af04a1431762e008528758c069abf7c | a8f044e77b298ddb72516405197a5ff2008b9ee7 | |||
v1.0 | complete | Code_Contests | Code_Contests_4797_C | from typing import List, Tuple
def min_cables_to_add(n: int, m: int, connections: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of additional cables required to connect the entire network.
Args:
n: The number of computers.
m: The number of existing direct connections.
connect... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return 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[r... | from solution import min_cables_to_add
def test_case_1():
assert min_cables_to_add(5, 3, [(1, 2), (2, 3), (4, 5)]) == 1
def test_case_2():
assert min_cables_to_add(5, 1, [(1, 2)]) == 3
def test_case_3():
assert min_cables_to_add(1, 0, []) == 0
def test_case_4():
assert min_cables_to_add(4, 2, [(1, 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)"
},
... | [
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 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_0 | {
"original_instruction": "Consider a network of computers where certain pairs are directly connected by cables. You are given the number of computers and a list of pairs of computers that are directly connected. Two computers are said to be connected if there is a direct cable between them. Your task is to determine... | 0.598414 | Code_Contests_4797 | C | [
"find",
"union",
"min_cables_to_add"
] | 3 | [
[
"min_cables_to_add",
"find"
],
[
"min_cables_to_add",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ad6a21ad91ab2d16bb67489ffae73dc170378afc | 09fbd618f3ba2284dccee75e74fc1986deb912ca | |||
v1.0 | complete | Code_Contests | Code_Contests_4824_C | def solve(n: int, m: int, edge_list: List[Tuple[int, int, int]]) -> int:
""" Given an undirected graph with n vertices and m edges, find the weight of the Minimum Spanning Tree (MST).
Returns -1 if no spanning tree exists.
>>> solve(4, 4, [(1, 2, 3), (2, 3, 1), (3, 4, 4), (4, 1, 2)]) 6
>>> solve(4, 3, ... | class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, u):
if self.parent[u] != u:
self.parent[u] = self.find(self.parent[u])
return self.parent[u]
def union(self, u, v):
root_u = self.find(u)
... | from solution import solve
def test_example_1():
n, m = 4, 4
edge_list = [
(1, 2, 3),
(2, 3, 1),
(3, 4, 4),
(4, 1, 2)
]
assert solve(n, m, edge_list) == 6
def test_example_2():
n, m = 4, 3
edge_list = [
(1, 2, 3),
(1, 3, 4),
(1, 4, 5)
... | [] | [
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(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_2 | {
"original_instruction": "You are given an undirected graph with n vertices and m edges. Each edge connects two different vertices and has an integer weight. The graph might contain loops or multiple edges with different weights.\n\nYou want to choose a subset of the edges such that it forms a tree that spans all th... | 0.745739 | Code_Contests_4824 | C | [
"kruskal_minimum_spanning_tree",
"solve"
] | 2 | [
[
"solve",
"kruskal_minimum_spanning_tree"
]
] | 1 | [] | false | [
"UnionFind"
] | true | pytest | true | [] | true | 9a8fe23ef30a9053d191d2025a1eeb16591bc381 | 348c8d0d44a61376d739d5969969313994cb1fce | |||
v1.0 | complete | Code_Contests | Code_Contests_4913_C | def maximal_rectangle(grid: List[str]) -> int:
""" Compute the maximum area of a rectangle containing only '1's in the given grid.
>>> maximal_rectangle(["1010", "1011", "1111", "0111"])
6
>>> maximal_rectangle(["001", "111"])
3
>>> maximal_rectangle(["110", "110", "001"])
4
>>> maximal_... | def maximal_rectangle(grid):
if not grid:
return 0
n = len(grid)
m = len(grid[0])
max_area = 0
heights = [0] * (m + 1)
for row in grid:
for i in range(m):
heights[i] = heights[i] + 1 if row[i] == '1' else 0
stack = [-1]
for i in range(m + 1):
... | def test_max_rectangle_1():
assert compute_max_rectangle(4, 4, ["1010", "1011", "1111", "0111"]) == 6
def test_max_rectangle_2():
assert compute_max_rectangle(2, 3, ["001", "111"]) == 3
def test_max_rectangle_3():
assert compute_max_rectangle(3, 3, ["110", "110", "001"]) == 4
def test_max_rectangle_empty... | [
{
"docstring": null,
"function_declaration": "def maximal_rectangle(grid):",
"function_name": "maximal_rectangle",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def compute_max_rectangle(n, m, grid_lines):",
"function_name": "compute_max_rectangle",
... | [
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 maximal_rectangle(grid):\n if not grid:\n return 0\n\n n = len(grid)\n m = len(grid[0])\n max_area = 0\n heights = [0] * (m + 1)\... | trial_gpt4o_0 | {
"original_instruction": "Alex has a rectangular grid consisting of '1's and '0's. He wants to find the maximum area of a rectangle (containing only '1's) that can be formed within this grid.\n\nThe rectangular grid is represented as a list of strings, where each string represents a row in the grid and contains only... | 0.687249 | Code_Contests_4913 | C | [
"maximal_rectangle",
"compute_max_rectangle"
] | 2 | [
[
"compute_max_rectangle",
"maximal_rectangle"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7cfd673661f2a3efc4c4e6482430cc5a7048ddfa | cd79f49a3531451ea2c91ab8c8fd115698cd81c2 | |||
v1.0 | complete | Code_Contests | Code_Contests_4986_C | def count_twin_prime_pairs(n, numbers):
""" Returns the count of numbers in the collection that are part of at least one twin prime pair.
>>> count_twin_prime_pairs(5, [3, 5, 6, 11, 13]) 4
>>> count_twin_prime_pairs(4, [1, 2, 4, 10]) 0
""" | def is_prime(n):
"""
Determines if a number is a prime number.
"""
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
i += 6
... | from solution import count_twin_prime_pairs
def test_example_1():
assert count_twin_prime_pairs(5, [3, 5, 6, 11, 13]) == 4
def test_example_2():
assert count_twin_prime_pairs(4, [1, 2, 4, 10]) == 0
def test_single_element_no_twin():
assert count_twin_prime_pairs(1, [17]) == 0
def test_single_element_twi... | [
{
"docstring": "Determines if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of numbers in the collection that are part of at least one twin prime pair.",
"function_declar... | [
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": "def is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return ... | trial_gpt4o_6 | {
"original_instruction": "Anna is fascinated by prime numbers and recently learned about twin primes.\n\nTwin primes are pairs of prime numbers (p1, p2) such that p2 = p1 + 2. For example, (3, 5) and (11, 13) are twin primes.\n\nAnna has a collection of n integers and she wants to know how many of those integers are... | 0.613876 | Code_Contests_4986 | C | [
"is_prime",
"count_twin_prime_pairs"
] | 2 | [
[
"count_twin_prime_pairs",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4f6baa41d1c6304ffca174a4840cf37795eaae01 | 06c4e9870cb121675e769b2744f79c31b3cb508b | |||
v1.0 | complete | Code_Contests | Code_Contests_5418_C | def min_max_latency(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum possible value of the maximum latency between any two buildings which ensures that all buildings are still connected.
Args:
n (int): Number of buildings.
m (int): Number of communication... | def find(parent, i):
if parent[i] == i:
return i
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_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] = ro... | from solution import min_max_latency
def test_sample_input_1():
n = 4
m = 5
edges = [
(1, 2, 4),
(2, 3, 5),
(3, 4, 6),
(4, 2, 2),
(1, 3, 8)
]
assert min_max_latency(n, m, edges) == 5
def test_sample_input_2():
n = 3
m = 3
edges = [
(1, 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)"
},
... | [
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 find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(pare... | trial_gpt4o_2 | {
"original_instruction": "The company XYTech has several departments, each operating in their own building and connected via direct communication links. Each building is represented as a node, and each communication link is represented as an edge with an associated latency value. For the proper functioning of certai... | 0.484915 | Code_Contests_5418 | C | [
"find",
"union",
"min_max_latency"
] | 3 | [
[
"min_max_latency",
"find"
],
[
"min_max_latency",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b1f6f4dff08b6159f91ab0c37be321d33fe5780b | fc70fca7bae6215b7f2990d12b3ac83d0c6ae9c5 | |||
v1.0 | complete | Code_Contests | Code_Contests_5494_C | def process_operations(Q: int, operations: List[str]) -> List[int]:
"""
Processes a list of operations on an initially empty array and returns the results
of operation type 2 which determine the maximum sum of any contiguous subarray.
Parameters:
Q (int): Number of operations.
operations (l... | def process_operations(Q, operations):
"""
Processes a list of operations on an initially empty array and returns the results
of operation type 2 which determine the maximum sum of any contiguous subarray.
Parameters:
Q (int): Number of operations.
operations (list of str): List of operatio... | from solution import process_operations, max_contiguous_subarray_sum
def test_max_contiguous_subarray_sum():
assert max_contiguous_subarray_sum([1, 2, -4]) == 3
assert max_contiguous_subarray_sum([1, 2, -4, 3, -1]) == 3
assert max_contiguous_subarray_sum([-1, -2, -3, -4]) == -1
assert max_contiguous_su... | [
{
"docstring": "Processes a list of operations on an initially empty array and returns the results\nof operation type 2 which determine the maximum sum of any contiguous subarray.\n\nParameters:\nQ (int): Number of operations.\noperations (list of str): List of operations in string format.\n\nReturns:\nlist of ... | [
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_subarray_sum(queries):\n \"\"\"\n Returns a list of results for the maximum sum of any contiguous subarray after each type 2 query.\n \n ... | trial_gpt4o_1 | {
"original_instruction": "You are given an initially empty array A consisting of integers. There are two types of operations you can perform on this array:\n\n1. Add a given integer x (1 ≤ x ≤ 10^9) to the end of the array.\n2. Determine the maximum sum of any contiguous subarray within A.\n\nInput\n\nThe first line... | 0.715468 | Code_Contests_5494 | C | [
"process_operations",
"max_contiguous_subarray_sum"
] | 2 | [
[
"process_operations",
"max_contiguous_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b2ccc437b86ffbd18473340dd56f711f428fdfc | 8563d12623614411e33f002f857b3e63974bc441 | |||
v1.0 | complete | Code_Contests | Code_Contests_6151_C | from typing import List
def is_balanced_number(number: int) -> bool:
"""
Function to check if a number is balanced.
>>> is_balanced_number(12321)
True
>>> is_balanced_number(5225)
True
>>> is_balanced_number(441)
False
"""
def check_balanced_numbers(numbers: List[int]) -> List[str]... | def is_balanced_number(number):
"""
Function to check if a number is balanced.
"""
number_str = str(number)
length = len(number_str)
if length == 1:
return True # A single digit number is trivially balanced
if length % 2 == 0: # Even length
left_half = number_str[... | def test_is_balanced_number_single_digit():
assert is_balanced_number(1) == True
def test_is_balanced_number_odd_length_balanced():
assert is_balanced_number(12321) == True
def test_is_balanced_number_odd_length_not_balanced():
assert is_balanced_number(441) == False
def test_is_balanced_number_even_leng... | [
{
"docstring": "Function to check if a number is balanced.",
"function_declaration": "def is_balanced_number(number):",
"function_name": "is_balanced_number",
"parameter_list": "(number)"
},
{
"docstring": "Function to check if each number in the list is balanced or not.",
"function_decl... | [
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 is_balanced_number(number):\n \"\"\"\n Function to check if a number is balanced.\n \"\"\"\n number_str = str(number)\n length = len(num... | trial_gpt4o_0 | {
"original_instruction": "In a distant land, there exists a special type of number known as \"Balanced Numbers.\" A number is considered balanced if the sum of digits on the left side of the middle digit(s) is equal to the sum of digits on the right side. The middle digit(s) in a number with an even number of digits... | 0.685257 | Code_Contests_6151 | C | [
"is_balanced_number",
"check_balanced_numbers"
] | 2 | [
[
"check_balanced_numbers",
"is_balanced_number"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c43d772bb3c1ccddfc639c016dc8f1d12d95d25c | fff780b4e403ac3c561417d8b8f35d1cf4df5167 | |||
v1.0 | complete | Code_Contests | Code_Contests_6041_C | def caesar_cipher_encrypt(text: str, shift: int) -> str:
""" Encrypts the given text using Caesar Cipher with the given shift.
>>> caesar_cipher_encrypt('HELLO', 3)
'KHOOR'
>>> caesar_cipher_encrypt('WORLD', 2)
'YQTNF'
"""
pass
def caesar_cipher_decrypt(text: str, shift: int) -> str:
""... | def caesar_cipher_encrypt(text, shift):
"""
Encrypts the given text using Caesar Cipher with the given shift.
"""
result = []
for char in text:
if char.isalpha():
shift_amount = shift % 26
if char.islower():
start = ord('a')
result.appe... | def test_caesar_cipher_encrypt():
assert caesar_cipher_encrypt('HELLO', 3) == 'KHOOR'
assert caesar_cipher_encrypt('WORLD', 2) == 'YQTNF'
assert caesar_cipher_encrypt('ABC', 1) == 'BCD'
assert caesar_cipher_encrypt('XYZ', 2) == 'ZAB'
assert caesar_cipher_encrypt('abc', 3) == 'def'
assert caesar_... | [
{
"docstring": "Encrypts the given text using Caesar Cipher with the given shift.",
"function_declaration": "def caesar_cipher_encrypt(text, shift):",
"function_name": "caesar_cipher_encrypt",
"parameter_list": "(text, shift)"
},
{
"docstring": "Decrypts the given text using Caesar Cipher wi... | [
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 caesar_cipher_encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar Cipher with the given shift.\n \"\"\"\n encrypted_text ... | trial_gpt4o_1 | {
"original_instruction": "Problem description\nYou are given a task to handle data encryption and decryption for secure communications. The encryption method uses a basic Caesar Cipher, where each letter in the plaintext is shifted a certain number of places down or up the alphabet.\n\nFor instance, with a shift of ... | 0.677211 | Code_Contests_6041 | C | [
"caesar_cipher_encrypt",
"caesar_cipher_decrypt",
"encrypt_and_decrypt_cases"
] | 3 | [
[
"caesar_cipher_decrypt",
"caesar_cipher_encrypt"
],
[
"encrypt_and_decrypt_cases",
"caesar_cipher_decrypt"
],
[
"encrypt_and_decrypt_cases",
"caesar_cipher_encrypt"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 752ec4948382dde032e00d1d34daf76349f5fcaf | 5f668cd1691855f99c35109bb9b77ddb105def63 | |||
v1.0 | complete | Code_Contests | Code_Contests_6267_C | def shift_char(c, rotation):
"""
Shifts a single character by the given rotation value.
"""
alpha_start = ord('a')
return chr((ord(c) - alpha_start + rotation) % 26 + alpha_start)
def encrypt_decrypt(mode, rotation, message):
"""
Encrypts or decrypts a message based on the mode and rotation... | def shift_char(c, rotation):
"""
Shifts a single character by the given rotation value.
"""
alpha_start = ord('a')
new_char = chr((ord(c) - alpha_start + rotation) % 26 + alpha_start)
return new_char
def encrypt_decrypt(mode, rotation, message):
"""
Encrypts or decrypts the given messag... | from solution import encrypt_decrypt
def test_encrypt_positive_rotation():
assert encrypt_decrypt("encrypt", 2, "abc") == "cde"
assert encrypt_decrypt("encrypt", 1, "z") == "a"
def test_encrypt_negative_rotation():
assert encrypt_decrypt("encrypt", -1, "xyz") == "wxy"
def test_decrypt_positive_rotation()... | [
{
"docstring": "Shifts a single character by the given rotation value.",
"function_declaration": "def shift_char(c, rotation):",
"function_name": "shift_char",
"parameter_list": "(c, rotation)"
},
{
"docstring": "Encrypts or decrypts the given message based on the mode and rotation value.",
... | [
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 rotate_char(c, rotation, mode):\n \"\"\"\n Rotate a single character by the specified rotation amount.\n \n Parameters:\n - c (char): Th... | trial_gpt4o_1 | {
"original_instruction": "Nicole is trying to develop a unique encryption system for her secret messages. The process involves rotating a set of characters by a certain number of positions, wrapping around from the end to the beginning as necessary. The set of characters she is working with includes the lowercase le... | 0.83953 | Code_Contests_6267 | C | [
"shift_char",
"encrypt_decrypt"
] | 2 | [
[
"encrypt_decrypt",
"shift_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 715cd722e3e2ee9e195305070eedec0fb6c7e47b | c050da2ffd94ea3ad9b1984cb5ed6f1ce0adee94 | |||
v1.0 | complete | Code_Contests | Code_Contests_5956_C | from typing import List
def rotate_matrix_90_clockwise(matrix: List[List[int]]) -> List[List[int]]:
"""
Rotate the given n x n matrix 90 degrees clockwise.
>>> rotate_matrix_90_clockwise([
... [1, 2, 3],
... [4, 5, 6],
... [7, 8, 9]
... ])
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
... | def rotate_matrix_90_clockwise(matrix):
"""
Rotate the given n x n matrix 90 degrees clockwise.
"""
n = len(matrix)
new_matrix = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
new_matrix[j][n - i - 1] = matrix[i][j]
return new_matrix
def rotate_matrix_... | from solution import rotate_matrix_90_clockwise, rotate_matrix_k_times, process_test_case
def test_rotate_90_clockwise():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
rotated = rotate_matrix_90_clockwise(matrix)
expected = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3... | [
{
"docstring": "Rotate the given n x n matrix 90 degrees clockwise.",
"function_declaration": "def rotate_matrix_90_clockwise(matrix):",
"function_name": "rotate_matrix_90_clockwise",
"parameter_list": "(matrix)"
},
{
"docstring": "Rotate the given n x n matrix k times 90 degrees clockwise."... | [
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 rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a given matrix 90 degrees clockwise.\n\n Parameters:\n matrix (List[List[int]]): The... | trial_gpt4o_4 | {
"original_instruction": "You are provided with an n x n matrix filled with unique integers from 1 to n^2 arranged in some order. The task is to rotate the matrix 90 degrees clockwise k times. Here, k is an integer (0 ≤ k ≤ 10^9).\n\nInput\n\nThe first line contains a single integer t (1 ≤ t ≤ 100) — the number of t... | 0.575033 | Code_Contests_5956 | C | [
"rotate_matrix_90_clockwise",
"rotate_matrix_k_times",
"process_test_case"
] | 3 | [
[
"process_test_case",
"rotate_matrix_k_times"
],
[
"rotate_matrix_k_times",
"rotate_matrix_90_clockwise"
]
] | 2 | [
"process_test_case"
] | false | [] | false | pytest | true | [] | true | 73e730344fafe8c6055b891cb063779c16cba8f5 | 47da81afa2e2197e7a234163422cfda5fbec3f0a | |||
v1.0 | complete | Code_Contests | Code_Contests_5885_C | def sieve(n):
"""
Generate a list of prime numbers up to `n`.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_numbers = []
for p in range(2, n... | def sieve(n):
"""
Generate a list of prime numbers up to `n`.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_numbers = []
for p in range(2, n... | from solution import process_input
def test_single_case_yes():
T = 1
cases = [34]
assert process_input(T, cases) == ["YES"]
def test_single_case_no():
T = 1
cases = [17]
assert process_input(T, cases) == ["NO"]
def test_multiple_cases():
T = 2
cases = [34, 17]
assert process_input... | [
{
"docstring": "Generate a list of prime numbers up to `n`.",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": "Check if the given number N can be represented as a sum of two prime numbers.",
"function_declaration": "def can_be_... | [
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 is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal... | trial_gpt4o_2 | {
"original_instruction": "Given an integer N, determine if it's possible to represent it as a sum of two prime numbers. If it is possible, print \"YES\", otherwise print \"NO\".\n\nInput\n\nFirst line of the input contains an integer T denoting number of test cases.\n\nFor each test case, there is a single line cont... | 0.690884 | Code_Contests_5885 | C | [
"sieve",
"can_be_sum_of_two_primes",
"process_input",
"read_input",
"main"
] | 5 | [
[
"process_input",
"can_be_sum_of_two_primes"
],
[
"process_input",
"sieve"
]
] | 2 | [
"process_input",
"read_input"
] | false | [] | false | pytest | true | [] | true | 285ebded3c08901ccddf323d6a44cbdefe647caf | 2ac439ffb4d96f7e934f14e6cdf706825eae0f79 | |||
v1.0 | complete | Code_Contests | Code_Contests_6429_C | def classify_review(review_text: str) -> int:
""" Classify the sentiment of a given review text. Sentiments are represented by integers:
1 for positive, 2 for neutral, and 3 for negative.
>>> classify_review("Great product, very helpful!")
1
>>> classify_review("The product is okay, but could be im... | import re
from collections import defaultdict
def load_training_data():
# This is a placeholder implementation to represent loading the training data.
training_data = defaultdict(list)
# Simulating loading data (you would replace this with actual file reading logic)
training_data[1].append("Great ... | def test_classify_positive_review():
review_text = "Great product, very helpful!"
assert classify_review(review_text) == 1
def test_classify_neutral_review():
review_text = "The product is okay, but could be improved."
assert classify_review(review_text) == 2
def test_classify_negative_review():
r... | [
{
"docstring": null,
"function_declaration": "def load_training_data():",
"function_name": "load_training_data",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def classify_review(review_text):",
"function_name": "classify_review",
"parameter_list": "(rev... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport re\n\ndef classify_review(review_text):\n \"\"\"\n Classifies the sentiment of the review based on provided review text.\n Here,... | trial_gpt4o_9 | {
"original_instruction": "You are a participant in a coding competition organized by XYZ Inc. This time the challenge is about analyzing and classifying customer reviews based on their sentiment. The reviews can be categorized into three sentiments: positive, neutral, and negative. Each of these sentiments is repres... | 0.675861 | Code_Contests_6429 | C | [
"load_training_data",
"classify_review"
] | 2 | [
[
"classify_review",
"load_training_data"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b65f6f683faa7ffc42ffc39f2d8393881c47cbf4 | 08c8ed4b8940ae5c36015bf89bb3ba34cdcc9f60 | |||
v1.0 | complete | Code_Contests | Code_Contests_5977_C | def reconstruct_magic_square(square: List[List[int]]) -> Union[List[List[int]], int]:
""" Reconstruct the original 3x3 magic square if possible.
If there is exactly one way to reconstruct the magic square, return a completed 3x3 magic square.
Otherwise, return -1.
>>> reconstruct_magic_square([
... | import itertools
def is_magic(square):
magic_sum = 15 # Every row, column, and diagonal must sum to 15 in a 3x3 magic square where numbers 1-9 are used.
rows = square
cols = [[square[row][col] for row in range(3)] for col in range(3)]
diags = [[square[i][i] for i in range(3)], [square[i][2-i] for i in... | from solution import reconstruct_magic_square
def test_reconstruct_magic_square():
input_square = [
[8, 0, 0],
[0, 5, 0],
[0, 0, 2]
]
expected_output = [
[8, 1, 6],
[3, 5, 7],
[4, 9, 2]
]
assert reconstruct_magic_square(input_square) == expected_outpu... | [
{
"docstring": null,
"function_declaration": "def is_magic(square):",
"function_name": "is_magic",
"parameter_list": "(square)"
},
{
"docstring": null,
"function_declaration": "def reconstruct_magic_square(square):",
"function_name": "reconstruct_magic_square",
"parameter_list": ... | [
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 itertools\n\ndef is_magic(square):\n magic_sum = 15 # Every row, column, and diagonal must sum to 15 in a 3x3 magic square where numbers 1-9 are... | trial_gpt4o_0 | {
"original_instruction": "Peter is fond of magic squares. A magic square is a grid where the sum of elements in each row, each column, and the two diagonals are equal. Peter has a special 3x3 magic square where the numbers 1 to 9 are used exactly once. However, some digits have been erased from the magic square.\n\n... | 0.648514 | Code_Contests_5977 | C | [
"is_magic",
"reconstruct_magic_square"
] | 2 | [
[
"reconstruct_magic_square",
"is_magic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a071bd0e548fbd8e5d69cb87cb47a9b098c1fbf2 | 46446bbbdc8208496c24efd1572b392006ab5965 | |||
v1.0 | complete | Code_Contests | Code_Contests_6027_C | from typing import List, Tuple
def largest_square(matrix: List[str]) -> int:
""" Find the side length of the largest square containing only 1s in the given grid.
>>> largest_square([
... "11000",
... "11000",
... "11100",
... "00000"
... ])
2
>>> largest_square([
... "111",
... | def largest_square(matrix):
if not matrix:
return 0
m, n = len(matrix), len(matrix[0])
dp = [[0] * (n + 1) for _ in range(m + 1)]
max_side = 0
for i in range(1, m + 1):
for j in range(1, n + 1):
if matrix[i-1][j-1] == '1':
dp[i][j] = min(dp[i-1][j], dp[i... | from solution import largest_square, get_largest_squares, process_input_output
def test_largest_square_1():
matrix = [
'11000',
'11000',
'11100',
'00000'
]
assert largest_square(matrix) == 2
def test_largest_square_2():
matrix = [
'111',
'111',
'... | [
{
"docstring": null,
"function_declaration": "def largest_square(matrix):",
"function_name": "largest_square",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def get_largest_squares(test_cases):",
"function_name": "get_largest_squares",
"parameter_l... | [
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 largest_square_side_length(t, test_cases):\n results = []\n \n for case in test_cases:\n m, n, grid = case\n dp = [[0] * (n + 1)... | trial_gpt4o_1 | {
"original_instruction": "Carmen is organizing her collection of digital photographs, and she wants them to be properly arranged in a visually appealing way. Each photograph is represented by a rectangle in a 2D grid. Carmen would like to form the largest possible square subgrid where all cells are covered by these ... | 0.584306 | Code_Contests_6027 | C | [
"largest_square",
"get_largest_squares",
"process_input_output"
] | 3 | [
[
"get_largest_squares",
"largest_square"
],
[
"process_input_output",
"get_largest_squares"
]
] | 2 | [
"process_input_output"
] | false | [] | false | pytest | true | [] | true | edffdf236b838dca7a21bf31f31d12343931ba62 | d91afb97d61b29c4f8c8a3967112c131032e872f | |||
v1.0 | complete | Code_Contests | Code_Contests_6238_C | def sum_of_digits(n: int) -> int:
"""
Given a number, returns the sum of its digits.
>>> sum_of_digits(123) 6
>>> sum_of_digits(0) 0
>>> sum_of_digits(10) 1
>>> sum_of_digits(999) 27
"""
def max_beauty_score_in_range(L: int, R: int) -> int:
"""
Returns the street number in the range... | def sum_of_digits(n):
"""
Returns the sum of the digits of a number.
"""
return sum(map(int, str(n)))
def max_beauty_score_in_range(L, R):
"""
Returns the street number in the range [L, R] which has the highest beauty score.
If there are multiple numbers with the same score, the smallest on... | from solution import sum_of_digits, max_beauty_score_in_range, find_max_beauty_scores
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(0) == 0
assert sum_of_digits(10) == 1
assert sum_of_digits(999) == 27
def test_max_beauty_score_in_range():
assert max_beauty_score_in... | [
{
"docstring": "Returns the sum of the digits of a number.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Returns the street number in the range [L, R] which has the highest beauty score.\nIf there are multiple ... | [
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 sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of a number.\n \"\"\"\n return sum(map(int, str(n)))\n\ndef max_beauty_score_in_... | trial_gpt4o_0 | {
"original_instruction": "In a small town, there is a unique way of organizing street numbers. Each street number is assigned a \"beauty score\" which is calculated as the sum of all the digits in the number. For example, the beauty score of 123 is 1 + 2 + 3 = 6.\n\nGiven a range of street numbers [L, R], the town c... | 0.630836 | Code_Contests_6238 | C | [
"sum_of_digits",
"max_beauty_score_in_range",
"find_max_beauty_scores"
] | 3 | [
[
"find_max_beauty_scores",
"max_beauty_score_in_range"
],
[
"max_beauty_score_in_range",
"sum_of_digits"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 31b1efb9b2eaac8999a6acc57e4a80e301fbfd80 | d1ea0efd5dc0a24b952b4e0f4337bcaf2e60966f | |||
v1.0 | complete | Code_Contests | Code_Contests_6206_C | def min_adjacent_swaps_to_sort(N, A):
"""
Determines the minimum number of adjacent swaps needed to sort the array in
non-decreasing order. If it is not possible, returns -1.
Args:
N : int : the number of elements in the array
A : list : the array of integers
Returns:
int : th... | def min_adjacent_swaps_to_sort(N, A):
"""
Determines the minimum number of adjacent swaps needed to sort the array in
non-decreasing order. If it is not possible, returns -1.
Args:
N : int : the number of elements in the array
A : list : the array of integers
Returns:
int : th... | from solution import min_adjacent_swaps_to_sort
def test_sorted_array():
assert min_adjacent_swaps_to_sort(4, [1, 2, 3, 4]) == 0
def test_reverse_sorted_array():
assert min_adjacent_swaps_to_sort(5, [5, 4, 3, 2, 1]) == 10
def test_mixed_array():
assert min_adjacent_swaps_to_sort(5, [3, 1, 2, 5, 4]) == 3
... | [
{
"docstring": "Determines the minimum number of adjacent swaps needed to sort the array in \nnon-decreasing order. If it is not possible, returns -1.\n\nArgs:\nN : int : the number of elements in the array\nA : list : the array of integers\n\nReturns:\nint : the minimum number of adjacent swaps needed or -1 if... | [
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 minimum_swaps_to_sort(array):\n \"\"\"\n Returns the minimum number of adjacent swaps needed to sort the array in non-decreasing order.\n If i... | trial_gpt4o_6 | {
"original_instruction": "Given an array A of length N, perform the following operations:\n\n- Select any two elements in the array that are adjacent (i.e. have indices i and i+1) and swap them.\n\nYou are required to sort the array in non-decreasing order using the minimum number of such adjacent swaps. If it is po... | 0.679809 | Code_Contests_6206 | C | [
"min_adjacent_swaps_to_sort",
"is_possible_to_sort",
"bubble_sort_count_swaps"
] | 3 | [
[
"min_adjacent_swaps_to_sort",
"bubble_sort_count_swaps"
],
[
"min_adjacent_swaps_to_sort",
"is_possible_to_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0d8f85fc67ce399c51904503be6f0a4493fa7cf0 | 4c9721f41bfdc68ad31ca9ad1968dc52249a0ded | |||
v1.0 | complete | Code_Contests | Code_Contests_6470_C | from typing import List, Tuple, Union
def gemstones_rearrangement(n: int, k: int, gemstones: List[int]) -> Union[str, Tuple[str, List[int]]]:
""" Determines if it's possible to rearrange the gemstones such that the sum of every two adjacent gemstones' identifiers is divisible by k.
Returns "YES" and one possib... | from itertools import permutations
def can_rearrange_gemstones(n, k, gemstones):
for perm in permutations(gemstones):
is_valid = True
for i in range(n - 1):
if (perm[i] + perm[i + 1]) % k != 0:
is_valid = False
break
if is_valid:
retur... | from solution import can_rearrange_gemstones, gemstones_rearrangement
def test_gemstones_rearrangement_possible_case_1():
assert gemstones_rearrangement(4, 5, [2, 3, 7, 8]) == ("YES", [2, 3, 7, 8])
def test_gemstones_rearrangement_impossible_case_2():
assert gemstones_rearrangement(3, 4, [1, 5, 6]) == "NO"
d... | [
{
"docstring": null,
"function_declaration": "def can_rearrange_gemstones(n, k, gemstones):",
"function_name": "can_rearrange_gemstones",
"parameter_list": "(n, k, gemstones)"
},
{
"docstring": null,
"function_declaration": "def gemstones_rearrangement(n, k, gemstones):",
"function_n... | [
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": "from itertools import permutations\n\ndef rearrange_gemstones(n, k, identifiers):\n \"\"\"\n Determine if it's possible to rearrange gemstones such t... | trial_gpt4o_2 | {
"original_instruction": "Kayla loves to collect gemstones. She has a collection of `n` gemstones, each having a unique integer identifier. She wants to reorganize her collection such that the sum of every two adjacent gemstones' identifiers is divisible by a given integer `k`.\n\nYour task is to determine if it's p... | 0.549378 | Code_Contests_6470 | C | [
"can_rearrange_gemstones",
"gemstones_rearrangement"
] | 2 | [
[
"gemstones_rearrangement",
"can_rearrange_gemstones"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3abddf7f0887f18cd502b4fb6cf670a039d58f0a | a6805d816690e9dd91f86ebc62038878864c13a4 | |||
v1.0 | complete | Code_Contests | Code_Contests_5532_C | def min_cost_to_connect_reservoirs(N: int, M: int, pipes: List[Tuple[int, int, int]]) -> int:
"""Determine the minimum cost required to connect all the reservoirs.
Args:
N (int): The number of reservoirs.
M (int): The number of possible pipes.
pipes (List[Tuple[int, int, int]]): Each tuple cont... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] ... | from solution import min_cost_to_connect_reservoirs
def test_example_case():
N = 4
M = 5
pipes = [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (2, 4, 5)]
assert min_cost_to_connect_reservoirs(N, M, pipes) == 6
def test_no_reservoirs():
N = 0
M = 0
pipes = []
assert min_cost_to_connect_r... | [
{
"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,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "# Importing required libraries for Kruskal's algorithm\nimport sys\ninput = sys.stdin.read\nfrom heapq import heappop, heappush\n\n# Disjoint set (Union-Fi... | trial_gpt4o_2 | {
"original_instruction": "A city needs to lay down a network of pipes to connect several reservoirs together to ensure a steady water supply throughout the area. The city authorities want to minimize the cost of laying the pipes while ensuring that there is a direct or indirect path between every pair of reservoirs.... | 0.620762 | Code_Contests_5532 | C | [
"find",
"union",
"min_cost_to_connect_reservoirs",
"process_input_data",
"main"
] | 5 | [
[
"min_cost_to_connect_reservoirs",
"find"
],
[
"min_cost_to_connect_reservoirs",
"union"
],
[
"union",
"find"
]
] | 3 | [
"process_input_data"
] | false | [] | false | pytest | true | [] | true | 6fb9edee907612f79a687d1c8306efd39923730a | 497e34b28c7ab0fb165d28a7ad40852669861108 | |||
v1.0 | complete | Code_Contests | Code_Contests_6088_C | def prefix_sums(arr):
"""
Returns the prefix sum array of the given array.
>>> prefix_sums([1, 2, 3, 4, 5]) [0, 1, 3, 6, 10, 15]
>>> prefix_sums([0, -1, 2]) [0, 0, -1, 1]
"""
pass
def query_subarray_sum(prefix_sum_arr, li, ri):
"""
Returns the sum of elements from index li to ri using t... | def prefix_sums(arr):
"""
Returns the prefix sum array of the given array.
"""
prefix_sum_arr = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sum_arr[i] = prefix_sum_arr[i - 1] + arr[i - 1]
return prefix_sum_arr
def query_subarray_sum(prefix_sum_arr, li, ri):
"""
... | def test_prefix_sums():
assert prefix_sums([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15]
assert prefix_sums([0, -1, 2]) == [0, 0, -1, 1]
assert prefix_sums([2, 2, 2, 2]) == [0, 2, 4, 6, 8]
def test_query_subarray_sum():
prefix_sum_arr = [0, 1, 3, 6, 10, 15]
assert query_subarray_sum(prefix_sum_arr, 1, 3... | [
{
"docstring": "Returns the prefix sum array of the given array.",
"function_declaration": "def prefix_sums(arr):",
"function_name": "prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of elements from index li to ri using the prefix sum array.",
"function_declara... | [
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 subarray_sums(arr, queries):\n \"\"\"\n Returns the sums of subarrays for each query.\n \n Parameters:\n arr (list): A list of integers.... | trial_gpt4o_1 | {
"original_instruction": "Given a list of integers and N queries, each querying about the subarray defined by indices Li and Ri (both inclusive), determine the sum of elements in the subarray for each query.\n\nInput\nFirst line: An integer M, the number of elements in the list.\nNext line: M integers, the elements ... | 0.630058 | Code_Contests_6088 | C | [
"prefix_sums",
"query_subarray_sum",
"solve_subarray_sums"
] | 3 | [
[
"solve_subarray_sums",
"prefix_sums"
],
[
"solve_subarray_sums",
"query_subarray_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 5b787ad8dc95bda74c4b5d7f60a4adb307664d21 | 0696b7c8ec78dffccfcb0a1a4749b4a03dbf2882 | |||
v1.0 | complete | Code_Contests | Code_Contests_6523_C | def max_water_flow(n: int, m: int, pipes: List[Tuple[int, int, int]]) -> int:
"""
A city's water distribution system consists of various tanks connected by pipes. Each tank can send water to other tanks,
and each pipe has a maximum capacity of water it can carry per hour. The city needs to determine the ma... | from collections import defaultdict, deque
def bfs(capacity, source, sink, parent):
visited = [False] * len(capacity)
queue = deque([source])
visited[source] = True
while queue:
u = queue.popleft()
for ind, val in enumerate(capacity[u]):
if visited[ind] == Fals... | def test_max_water_flow_ex1():
assert max_water_flow(4, 5, [
(1, 2, 10),
(1, 3, 5),
(2, 3, 15),
(2, 4, 10),
(3, 4, 10)
]) == 15
def test_max_water_flow_ex2():
assert max_water_flow(4, 2, [
(1, 2, 100),
(3, 4, 100)
]) == 0
def test_max_water_flow_... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, source, sink, parent):",
"function_name": "bfs",
"parameter_list": "(capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(n, adj_matrix, source, sink):",
"function_name": "ed... | [
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 defaultdict, deque\n\ndef bfs_capacity(graph, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited... | trial_gpt4o_2 | {
"original_instruction": "A city's water distribution system consists of various tanks connected by pipes. Each tank can send water to other tanks, and each pipe has a maximum capacity of water it can carry per hour. The city needs to determine the maximum amount of water that can be sent from the main source tank t... | 0.681873 | Code_Contests_6523 | C | [
"bfs",
"edmonds_karp",
"max_water_flow"
] | 3 | [
[
"edmonds_karp",
"bfs"
],
[
"max_water_flow",
"edmonds_karp"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e66a78379efe5e8c056c0df2d0d8c571ae2f7ddc | f863bed4fbef7929d82b235ceee91e78fc87a5d6 | |||
v1.0 | complete | Code_Contests | Code_Contests_7180_C | from typing import List
def generate_pattern(n: int) -> List[str]:
""" Generates an NxN grid pattern with given rules:
- '*' on the main diagonal
- '.' everywhere else
>>> generate_pattern(3)
['*..', '.*.', '..*']
>>> generate_pattern(5)
['*....', '.*...', '..*..', '...*.', '....*']
"""... | def generate_pattern(n):
"""
Generates an NxN grid pattern with given rules:
- '*' on the main diagonal
- '.' everywhere else
"""
pattern = []
for i in range(n):
row = ['.'] * n
row[i] = '*'
pattern.append(''.join(row))
return pattern
def iris_patterns(test_cases... | def test_generate_pattern():
result = generate_pattern(3)
assert result == ["*..", ".*.", "..*"]
result = generate_pattern(5)
assert result == ["*....", ".*...", "..*..", "...*.", "....*"]
def test_iris_patterns():
test_cases = [3, 5]
results = iris_patterns(test_cases)
expected = [
... | [
{
"docstring": "Generates an NxN grid pattern with given rules:\n- '*' on the main diagonal\n- '.' everywhere else",
"function_declaration": "def generate_pattern(n):",
"function_name": "generate_pattern",
"parameter_list": "(n)"
},
{
"docstring": "Generates the patterns for each test case a... | [
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 generate_pattern(N):\n \"\"\"\n Generates an NxN grid with a specific pattern.\n - The diagonal from the top-left to the bottom-right is fille... | trial_gpt4o_2 | {
"original_instruction": "Iris is a young artist who loves to draw intricate patterns using small shapes. Recently, she has become interested in creating patterns using only two types of characters: '*' and '.'. Her goal is to draw symmetric patterns that follow specific rules.\n\nFor a given integer `N`, Iris will ... | 0.579334 | Code_Contests_7180 | C | [
"generate_pattern",
"iris_patterns",
"format_patterns"
] | 3 | [
[
"iris_patterns",
"generate_pattern"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 93cebc6286f1594034c907910b4a3c91925de890 | 9fc3785e9d85e425b56a76efb480d2b2fefe13d2 | |||
v1.0 | complete | Code_Contests | Code_Contests_12732_C | def distinct_ways_to_reach_top(n: int, steps: List[int]) -> int:
"""
Determines the number of distinct ways to reach the top of a sequence of steps.
Example:
>>> distinct_ways_to_reach_top(3, [1, 2, 1])
3
>>> distinct_ways_to_reach_top(2, [1, 2])
2
""" | def num_ways(n, steps):
"""
Returns the number of distinct ways to reach the top of n steps given the sequence of steps
that can be climbed in one move (either 1 step or 2 steps).
"""
# Handling edge cases where n is 0
if n == 0:
return 1
# Initialize dp array where dp[i] means the ... | from solution import distinct_ways_to_reach_top
def test_example_1():
assert distinct_ways_to_reach_top(3, [1, 2, 1]) == 3
def test_example_2():
assert distinct_ways_to_reach_top(2, [1, 2]) == 2
def test_single_step():
assert distinct_ways_to_reach_top(1, [1]) == 1
def test_two_single_steps():
asser... | [
{
"docstring": "Returns the number of distinct ways to reach the top of n steps given the sequence of steps\nthat can be climbed in one move (either 1 step or 2 steps).",
"function_declaration": "def num_ways(n, steps):",
"function_name": "num_ways",
"parameter_list": "(n, steps)"
},
{
"docs... | [
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 num_ways(n, steps):\n \"\"\"\n Returns the number of distinct ways to reach the top of n steps given the sequence of steps\n that can be climb... | trial_gpt4o_0 | {
"original_instruction": "Thomas loves climbing. He has found a sequence of steps and wants to figure out all the distinct ways to reach the top. The sequence of steps can be represented as an array where each element denotes the number of steps that can be climbed in one move (either 1 step or 2 steps only).\n\nFor... | 0.584607 | Code_Contests_12732 | C | [
"num_ways",
"distinct_ways_to_reach_top"
] | 2 | [
[
"distinct_ways_to_reach_top",
"num_ways"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cba68845da2cd19af979cbee53984c2d266855f2 | 8e6b40da70e39dedce621c678edd1f42f3f537ec | |||
v1.0 | complete | Code_Contests | Code_Contests_6299_C | def find_cycles(grid, N, M):
""" Determine the number of valid cycles present in the given matrix.
>>> find_cycles([['R', 'R', 'D'], ['L', 'U', 'L'], ['L', 'D', 'L']], 3, 3)
1
>>> find_cycles([['R', 'R'], ['L', 'L']], 2, 2)
0
"""
def count_cycles(test_cases):
""" Count cycles for given ... | def find_cycles(grid, N, M):
def move(i, j):
if grid[i][j] == 'L': return i, j - 1
if grid[i][j] == 'R': return i, j + 1
if grid[i][j] == 'U': return i - 1, j
if grid[i][j] == 'D': return i + 1, j
visited = [[False] * M for _ in range(N)]
cycle_count = 0
for i in range(... | def test_find_cycles():
grid = [
['R', 'R', 'D'],
['L', 'U', 'L'],
['L', 'D', 'L']
]
assert find_cycles(grid, 3, 3) == 1
grid = [
['R', 'R'],
['L', 'L']
]
assert find_cycles(grid, 2, 2) == 0
def test_count_cycles():
test_cases = [
(3, 3, ... | [
{
"docstring": null,
"function_declaration": "def find_cycles(grid, N, M):",
"function_name": "find_cycles",
"parameter_list": "(grid, N, M)"
},
{
"docstring": null,
"function_declaration": "def count_cycles(test_cases):",
"function_name": "count_cycles",
"parameter_list": "(test... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 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_cycles(matrix):\n n = len(matrix)\n m = len(matrix[0])\n visited = [[False] * m for _ in range(n)]\n parent = [[None] * m for _ in ran... | trial_gpt4o_9 | {
"original_instruction": "You are given a matrix of size N x M consisting of characters 'L', 'R', 'U', 'D', representing left, right, up, and down respectively. A path can be formed if adjacent cells contain valid movements according to the given characters.\n\nFor instance, a valid path starting at (i, j) with 'L' ... | 0.622099 | Code_Contests_6299 | C | [
"find_cycles",
"count_cycles",
"process_input",
"solution"
] | 4 | [
[
"count_cycles",
"find_cycles"
],
[
"solution",
"count_cycles"
],
[
"solution",
"process_input"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 22f0f4fd9066ae48575a5af0dbe448381f4f023d | b895b394644fdcd8cb91a67d3ec35e3d5d49351c | |||
v1.0 | complete | Code_Contests | Code_Contests_12479_C | def max_distance_travel(N, K, connections):
""" Calculate the maximum distance Rama can travel to visit exactly K unique shops starting from shop 1 in a marketplace represented as a tree.
>>> max_distance_travel(5, 3, [(1, 2), (1, 3), (2, 4), (2, 5)]) 2
>>> max_distance_travel(3, 2, [(1, 2), (1, 3)]) 1
... | from collections import deque
def bfs_to_find_furthest(node, edges):
queue = deque([node])
visited = {node}
furthest_node = node
while queue:
current_node = queue.popleft()
furthest_node = current_node
for neighbor in edges[current_node]:
if neighbor not in visited:
... | from solution import max_distance_travel
def test_example_case():
assert max_distance_travel(5, 3, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 2
def test_small_case():
assert max_distance_travel(3, 2, [(1, 2), (1, 3)]) == 1
def test_large_k_case():
assert max_distance_travel(4, 4, [(1, 2), (2, 3), (3, 4)]) == 3... | [
{
"docstring": null,
"function_declaration": "def bfs_to_find_furthest(node, edges):",
"function_name": "bfs_to_find_furthest",
"parameter_list": "(node, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs_to_find_distance(node, target, edges, K):",
"function_name": "bfs... | [
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 max_distance_to_k_shops(N, K, edges):\n if K == 1:\n return 0\n \n tree = defaultdict(lis... | trial_gpt4o_1 | {
"original_instruction": "In a small village, there is a unique marketplace where all the paths connecting the various shops form a tree. The local vendor, Rama, wants to maximize his profit by visiting exactly K unique shops in a single day, starting from his own shop (shop 1). However, to avoid exhaustion and plan... | 0.614791 | Code_Contests_12479 | C | [
"bfs_to_find_furthest",
"bfs_to_find_distance",
"max_distance_travel"
] | 3 | [
[
"max_distance_travel",
"bfs_to_find_distance"
],
[
"max_distance_travel",
"bfs_to_find_furthest"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b964a8ab077a1b41dd9429f7f2ef34748d51ed7c | 35aa66ce2699299ad09e40eb200c469df4e930cc | |||
v1.0 | complete | Code_Contests | Code_Contests_12191_C | from typing import List
def find_minimized_maximum_pages(pages: List[int], students: int) -> int:
""" Divide books into the given number of students such that the maximum number of pages assigned to a student is minimized.
>>> find_minimized_maximum_pages([12, 34, 67, 90], 2)
113
>>> find_minimized_max... | def is_possible(pages, students, max_pages):
required_students = 1
current_pages = 0
for page in pages:
if current_pages + page > max_pages:
required_students += 1
current_pages = page
if required_students > students:
return False
else:
... | def test_find_minimized_maximum_pages():
assert find_minimized_maximum_pages([12, 34, 67, 90], 2) == 113
assert find_minimized_maximum_pages([10, 20, 30, 40], 2) == 60
assert find_minimized_maximum_pages([5, 17, 100, 11], 4) == 100
assert find_minimized_maximum_pages([12, 34, 67, 90], 3) == 90
asser... | [
{
"docstring": null,
"function_declaration": "def is_possible(pages, students, max_pages):",
"function_name": "is_possible",
"parameter_list": "(pages, students, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_minimized_maximum_pages(pages, students):",
"functio... | [
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_possible(pages, students, max_pages):\n required_students = 1\n current_pages = 0\n\n for page in pages:\n if current_pages + page >... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of integers where each integer represents the number of pages in a book. Your task is to divide these books into a given number of students in such a way that the maximum number of pages assigned to a student is minimized. Each student gets a contiguous sequence of book... | 0.672262 | Code_Contests_12191 | C | [
"is_possible",
"find_minimized_maximum_pages"
] | 2 | [
[
"find_minimized_maximum_pages",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 713e9e2bd2625ca0badbe606a5d37142343b57b9 | be25ed7ed7a6490f84e2e97e35f026067ebdf448 | |||
v1.0 | complete | Code_Contests | Code_Contests_12288_C | def is_prime(n: int) -> bool:
"""
Helper function to determine if a number n is prime.
>>> is_prime(2)
True
>>> is_prime(9)
False
"""
def largest_prime_leq(n: int) -> int:
"""
Find the largest prime number less than or equal to n.
Returns -1 if no such prime exists.
>>> larg... | def is_prime(n):
"""
Helper function to determine if a number n is prime.
"""
if n <= 1:
return False
if n == 2 or 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 F... | from solution import is_prime, largest_prime_leq
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(9) == False
assert is_prime(11) == True
assert is_prime(1) == False
def test_largest_prime_leq(... | [
{
"docstring": "Helper function to determine if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the largest prime number less than or equal to n.\nReturns -1 if no such prime exists.",
"functi... | [
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(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3... | trial_gpt4o_2 | {
"original_instruction": "Little Hana loves solving mathematical puzzles, especially if it involves prime numbers. One day her friend Little Maya gave her an interesting challenge. Given a number `n`, Hana needs to find the largest prime number `p` such that `p <= n`. If no such prime number exists, she should retur... | 0.752987 | Code_Contests_12288 | C | [
"is_prime",
"largest_prime_leq"
] | 2 | [
[
"largest_prime_leq",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1c0637dc7dd1c00ee2315a68af6d0576c7dfeb5e | e9c60ca43c9e2a024ca5479703006c3c2b0643a9 | |||
v1.0 | complete | Code_Contests | Code_Contests_7026_C | def count_B_W_pairs(strings):
"""
Given a list of strings, this function counts the number of times 'B' is
followed by 'W'.
"""
pass
def input_handler(n, strings):
"""
Handles the input and calls the appropriate function to get the result.
"""
pass
# Unit Tests
def test_count_B_W_p... | def count_B_W_pairs(strings):
"""
Given a list of strings, this function counts the number of times 'B' is
followed by 'W'.
"""
total_count = 0
for s in strings:
total_count += s.count('BW')
return total_count
def input_handler(n, strings):
"""
Handles the input and calls th... | from solution import count_B_W_pairs, input_handler
def test_count_B_W_pairs():
assert count_B_W_pairs(["B"]) == 0
assert count_B_W_pairs(["WB"]) == 0
assert count_B_W_pairs(["BWB"]) == 1
assert count_B_W_pairs(["WWB"]) == 0
assert count_B_W_pairs(["BWWB"]) == 1
assert count_B_W_pairs(["WBWB"])... | [
{
"docstring": "Given a list of strings, this function counts the number of times 'B' is\nfollowed by 'W'.",
"function_declaration": "def count_B_W_pairs(strings):",
"function_name": "count_B_W_pairs",
"parameter_list": "(strings)"
},
{
"docstring": "Handles the input and calls the appropria... | [
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": "def calculate_positions_sum(n, strings):\n total_sum = 0\n for string in strings:\n for idx, char in enumerate(string):\n if char =... | trial_gpt4o_6 | {
"original_instruction": "Input\n\n6\nB\nWB\nBWB\nWWB\nBWWB\nWBWB\n\nOutput\n\n14",
"prompt_id": "00007026",
"row_id": 7026,
"seed_ids": "[10507]"
} | 0.594889 | Code_Contests_7026 | C | [
"count_B_W_pairs",
"input_handler"
] | 2 | [
[
"input_handler",
"count_B_W_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dd7e0e1abd6553b7f0de3758a8fabffdfa492fef | 7bb8980544de00942d17bcb7f0969ec5ada4d5f3 | |||
v1.0 | complete | Code_Contests | Code_Contests_6966_C | import math
def is_perfect_square(n: int) -> bool:
""" Check if a number is a perfect square.
>>> is_perfect_square(1)
True
>>> is_perfect_square(4)
True
>>> is_perfect_square(9)
True
>>> is_perfect_square(10)
False
>>> is_perfect_square(15)
False
"""
pass
def seque... | import math
def is_perfect_square(n):
"""Check if a number is a perfect square."""
return math.isqrt(n) ** 2 == n
def sequence_product_or_not_all_perfect_squares(sequences):
"""
Given a list of sequences, return the product of all elements in the sequence
if all elements are perfect squares, other... | def test_is_perfect_square():
assert is_perfect_square(1) == True
assert is_perfect_square(4) == True
assert is_perfect_square(9) == True
assert is_perfect_square(10) == False
assert is_perfect_square(15) == False
def test_sequence_product_all_perfect_squares():
assert sequence_product_or_not_a... | [
{
"docstring": "Check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of sequences, return the product of all elements in the sequence\nif all elements are pe... | [
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": "import math\n\ndef is_perfect_square(n):\n \"\"\"\n Checks if a number is a perfect square.\n \"\"\"\n root = int(math.sqrt(n))\n return n =... | trial_gpt4o_2 | {
"original_instruction": "Arman is learning about number sequences and he is fascinated by sequences whose elements are perfect squares. A sequence is considered to be composed of perfect squares if every element in it is a perfect square integer (i.e., 1, 4, 9, 16, etc.).\n\nArman has a list of sequences and he wan... | 0.6579 | Code_Contests_6966 | C | [
"is_perfect_square",
"sequence_product_or_not_all_perfect_squares"
] | 2 | [
[
"sequence_product_or_not_all_perfect_squares",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ab4ebf25fd51701a92c4d5354cfdc425602989ba | fabfdda077eeb6901f09b3525fef01e2384de948 | |||
v1.0 | complete | Code_Contests | Code_Contests_12971_C | def sieve_of_eratosthenes(n):
"""
Returns a list of primes <= n using the Sieve of Eratosthenes algorithm.
"""
def sum_of_primes_up_to_n(n):
"""
Returns the sum of all prime numbers less than or equal to n.
"""
def solve_primes_sums(test_cases):
"""
Given a list of test cases with valu... | def sieve_of_eratosthenes(n):
"""
Returns a list of primes <= n using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
prime_num... | from solution import solve_primes_sums
def test_single_test_case():
assert solve_primes_sums([10]) == [17]
def test_multiple_test_cases():
assert solve_primes_sums([10, 100]) == [17, 1060]
def test_edge_case_1():
assert solve_primes_sums([1]) == [0]
def test_edge_case_2():
assert solve_primes_sums([... | [
{
"docstring": "Returns a list of primes <= n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers less than or equal to ... | [
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_primes_up_to(n):\n if n < 2:\n return 0\n\n sieve = [True] * (n + 1)\n sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers... | trial_gpt4o_1 | {
"original_instruction": "Morty has recently started learning about prime numbers and their properties. To test his understanding, Rick gives him a challenge. Morty has to find the sum of all prime numbers up to a given positive integer N.\n\nThe problem: Given a positive integer N, find the sum of all prime numbers... | 0.678748 | Code_Contests_12971 | C | [
"sieve_of_eratosthenes",
"sum_of_primes_up_to_n",
"solve_primes_sums"
] | 3 | [
[
"solve_primes_sums",
"sum_of_primes_up_to_n"
],
[
"sum_of_primes_up_to_n",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a6919e124734a676e8c3811096be7723bc06564e | da58226176fb3a8303f25ea0192ba2abf3fc2453 | |||
v1.0 | complete | Code_Contests | Code_Contests_12361_C | from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
# (Implementation needed)
def count_beautiful_subarrays(t: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
""... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def c... | from solution import is_prime, count_beautiful_subarrays, main
def test_is_prime():
# Test some prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(17) == True
assert is_prime(19) == True
# Test some non-prime numbers
assert is_prime(1) == False
assert i... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to count the number of beautiful subarrays for each test case.",
"function_declaration": "def ... | [
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_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_5 | {
"original_instruction": "You are given an integer array `arr` of size `n` consisting of positive integers. A subarray is defined as the contiguous portion of the array. A subarray is considered \"beautiful\" if the sum of its elements is a prime number. Write a function to determine the count of beautiful subarrays... | 0.683887 | Code_Contests_12361 | C | [
"is_prime",
"count_beautiful_subarrays",
"main"
] | 3 | [
[
"count_beautiful_subarrays",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7870d2420a1906e3f1c26e741ace5b61481f0acf | e5f17b3dedc1cc9bd4d9b1c54ba107f46fd19be4 | |||
v1.0 | complete | Code_Contests | Code_Contests_12668_C | def classify_books(n, titles):
"""
Classifies a list of book titles into subject sets based on training data of book title frequencies.
Args:
n (int): Number of book titles to classify.
titles (List[str]): List of book titles to classify.
Returns:
List[int]: List of integers repre... | from collections import defaultdict, Counter
import os
def load_training_data():
training_data = defaultdict(list)
for i in range(1, 6):
directory = str(i)
for filename in os.listdir(directory):
filepath = os.path.join(directory, filename)
with open(filepath, 'r') as fil... | from solution import classify_books
import pytest
def mock_load_training_data():
return {
1: ["data mining techniques", "machine learning", "deep learning"],
2: ["modern physics for engineers", "quantum mechanics", "general relativity"],
3: ["ancient history of rome", "medieval europe", "re... | [
{
"docstring": null,
"function_declaration": "def load_training_data():",
"function_name": "load_training_data",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def build_word_subject_map(training_data):",
"function_name": "build_word_subject_map",
"parame... | [
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": "import os\nimport zipfile\nfrom collections import Counter\nfrom pathlib import Path\n\ndef download_and_extract_zip(url, extract_to='.'):\n # Function ... | trial_gpt4o_1 | {
"original_instruction": "The library of a university stores numerous books and categorizes them based on different subjects. Each book belongs to only one subject from subject sets identified by integers from 1 to 5. Your task is to write a program that classifies a given book into one of the subject sets based on ... | 0.555938 | Code_Contests_12668 | C | [
"load_training_data",
"build_word_subject_map",
"predict_subject",
"classify_books"
] | 4 | [
[
"classify_books",
"build_word_subject_map"
],
[
"classify_books",
"load_training_data"
],
[
"classify_books",
"predict_subject"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7917e4f171f8666ec61cbdd0e29d34e7c716daab | a6e9a9108bc9abd2733d186dce028ca752e7f5fb | |||
v1.0 | complete | Code_Contests | Code_Contests_12636_C | def encrypt_message(message: str) -> str:
"""Encrypts the message using a substitution cipher strategy where each letter in the alphabet is mapped to its reverse counterpart.
>>> encrypt_message("Hello World")
'Svool Dliow'
>>> encrypt_message("Hello, World!")
'Svool, Dliow!'
>>> encrypt_me... | def create_cipher_map():
"""
Creates a dictionary to map each letter to its reverse counterpart.
"""
from string import ascii_lowercase, ascii_uppercase
cipher_map = {}
for a, z in zip(ascii_lowercase, reversed(ascii_lowercase)):
cipher_map[a] = z
cipher_map[a.upper()] = z.u... | from solution import encrypt_message
def test_encrypt_message_simple():
assert encrypt_message("Hello World") == "Svool Dliow"
def test_encrypt_message_with_punctuation():
assert encrypt_message("Hello, World!") == "Svool, Dliow!"
def test_encrypt_message_all_lowercase():
assert encrypt_message("abcdefgh... | [
{
"docstring": "Creates a dictionary to map each letter to its reverse counterpart.",
"function_declaration": "def create_cipher_map():",
"function_name": "create_cipher_map",
"parameter_list": "()"
},
{
"docstring": "Encrypts the message using the substitution cipher strategy.\n\nParameters... | [
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 substitution_cipher(text):\n \"\"\"\n Encrypt the input text using a substitution cipher where each letter in the alphabet\n is mapped to its ... | trial_gpt4o_2 | {
"original_instruction": "A secret agent wants to send encrypted messages to avoid the risk of being intercepted. He decides to use a substitution cipher to transform his messages. The strategy involves mapping each letter in the alphabet to its reverse counterpart, where 'a' becomes 'z', 'b' becomes 'y', and so on.... | 0.756324 | Code_Contests_12636 | C | [
"create_cipher_map",
"encrypt_message"
] | 2 | [
[
"encrypt_message",
"create_cipher_map"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f847fe0d7d7cc5d35e6321e4b5306155bf81b0d4 | eada6e24c5c635b96fde7b93e370f47bd743cce8 | |||
v1.0 | complete | Code_Contests | Code_Contests_6449_C | def is_prime(num: int) -> bool:
"""Checks if a number is a prime number."""
pass
def max_prime_difference(array: List[int]) -> int:
"""Finds the maximum difference between any two prime numbers in the array."""
pass
def process_test_cases(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
... | def is_prime(num):
""" Checks if a number is a prime number. """
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def max_prime_difference(array):
""" Finds the maximum difference between any two prime numbers in... | from solution import process_test_cases
def test_case_1():
T = 3
test_cases = [
(6, [8, 3, 15, 5, 14, 9]),
(4, [4, 10, 6, 15]),
(7, [2, 5, 11, 3, 17, 18, 19])
]
assert process_test_cases(T, test_cases) == [2, -1, 17]
def test_case_no_primes():
T = 1
test_cases = [
... | [
{
"docstring": "Checks if a number is a prime number. ",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the maximum difference between any two prime numbers in the array. ",
"function_declaration": "def max_pr... | [
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 \"\"\" Checks if a number is a prime number. \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) ... | trial_gpt4o_0 | {
"original_instruction": "Ward loves prime numbers and he likes to play with arrays. Today, he got an array A of N positive integers. He wants to find the maximum difference between any two prime numbers in the array. If the array contains less than two prime numbers, print -1.\n\nWrite a program that helps Ward fin... | 0.620008 | Code_Contests_6449 | C | [
"is_prime",
"max_prime_difference",
"process_test_cases"
] | 3 | [
[
"max_prime_difference",
"is_prime"
],
[
"process_test_cases",
"max_prime_difference"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 04ed7ff6a668981e16a3d81c2b8f3f970ac9c27e | a70d2356f83fc42a3843d626a8945436200b2e59 | |||
v1.0 | complete | Code_Contests | Code_Contests_12281_C | def num_distinct_subsequences(s: str, dictionary: List[str]) -> int:
""" Determine how many distinct words from the dictionary can be formed as subsequences of s.
>>> num_distinct_subsequences("abcde", ["a", "bb", "ace"]) 2
>>> num_distinct_subsequences("abcdef", ["ab", "cf", "ef", "gh"]) 3
"""
pass... | def num_distinct_subsequences(s, dictionary):
def is_subsequence(s, word):
it = iter(s)
return all(char in it for char in word)
count = 0
for word in dictionary:
if is_subsequence(s, word):
count += 1
return count
# Function to process the input
def process_inpu... | from solution import num_distinct_subsequences
def test_example_1():
s = "abcde"
dictionary = ["a", "bb", "ace"]
assert num_distinct_subsequences(s, dictionary) == 2
def test_example_2():
s = "abcdef"
dictionary = ["ab", "cf", "ef", "gh"]
assert num_distinct_subsequences(s, dictionary) == 3
d... | [
{
"docstring": null,
"function_declaration": "def num_distinct_subsequences(s, dictionary):",
"function_name": "num_distinct_subsequences",
"parameter_list": "(s, dictionary)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_compute(s, n, word_list):",
"function... | [
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 num_distinct_subsequences(s, dictionary):\n def is_subsequence(s, word):\n it = iter(s)\n return all(char in it for char in word)\n ... | trial_gpt4o_0 | {
"original_instruction": "You are given a string s consisting of lowercase English letters, and a list of strings dictionary containing unique words. Your task is to determine how many distinct words from the dictionary can be formed as subsequences of s.\n\nA subsequence of a string is a new string generated from t... | 0.671085 | Code_Contests_12281 | C | [
"num_distinct_subsequences",
"process_input_and_compute"
] | 2 | [
[
"process_input_and_compute",
"num_distinct_subsequences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fba21e915a63937f9803a06291fb2e0c36a6a1e8 | 636ce8634d88b9895a6cccd921e635b6d88347dd | |||
v1.0 | complete | Code_Contests | Code_Contests_6662_C | class TreeNode:
def __init__(self, value=0):
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
""" Build a binary tree from a list of node tuples. """
pass
def longest_increasing_path(root):
""" Find the longest path in the tree where the values along... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
if not nodes:
return None
tree_nodes = {}
for value, left, right in nodes:
if value not in tree_nodes:
tree_nodes[value] = T... | from solution import longest_path_in_binary_tree
def test_example_1():
n = 5
nodes = [
(4, 2, 5),
(2, -1, -1),
(5, 3, -1),
(3, -1, -1),
(1, -1, -1)
]
assert longest_path_in_binary_tree(n, nodes) == 2
def test_example_2():
n = 7
nodes = [
(8, 3, 1... | [] | [
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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\... | trial_gpt4o_8 | {
"original_instruction": "You are given a binary tree, where each node has two potential children and each node contains a unique integer value. A leaf node is a node that does not have any children.\n\nYour task is to find the longest path in the tree where the values along the path form a strictly increasing seque... | 0.554899 | Code_Contests_6662 | C | [
"build_tree",
"longest_increasing_path",
"longest_path_in_binary_tree"
] | 3 | [
[
"longest_path_in_binary_tree",
"build_tree"
],
[
"longest_path_in_binary_tree",
"longest_increasing_path"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 717675e6b9d8289724ad6cfdb9c7030c5bbe4594 | bebcaba819ff4215c04c3656ff3be8d7bc58da35 | |||
v1.0 | complete | Code_Contests | Code_Contests_12166_C | from typing import List
class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert(root: TreeNode, value: int) -> TreeNode:
"""Insert a value into the BST."""
if root is None:
return TreeNode(value)
if value < root.value:... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert(root.left, value)
else:
root.right = insert(root.ri... | from solution import bst_in_order_traversal
def test_bst_in_order_traversal():
assert bst_in_order_traversal([5, 3, 7, 2, 4, 6, 8]) == [2, 3, 4, 5, 6, 7, 8]
assert bst_in_order_traversal([]) == []
assert bst_in_order_traversal([1]) == [1]
assert bst_in_order_traversal([5, 4, 6, 3, 7, 2, 8]) == [2, 3, 4... | [] | [
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 typing import List\n\nclass TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = None\n\n... | trial_gpt4o_1 | {
"original_instruction": "A **binary search tree (BST)** is a binary tree in which each node has at most two children. For any node $v$ with left subtree $L$ and right subtree $R$, all nodes in $L$ have values smaller than $v$, and all nodes in $R$ have values greater than $v$.\n\nGiven a list of integers, construct... | 0.530048 | Code_Contests_12166 | C | [
"insert",
"bst_in_order_traversal"
] | 2 | [
[
"bst_in_order_traversal",
"insert"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e9e7485642f114d96459bc7954c98b62a0f0464b | 993b873eac760fc0ba0dc14d804a431c88ad6f5d | |||
v1.0 | complete | Code_Contests | Code_Contests_12268_C | def fetch_data(max_calls_per_minute: int) -> list:
"""
Fetches data from the API while adhering to the rate limit.
Parameters:
max_calls_per_minute (int): The maximum number of API calls allowed per minute.
Returns:
list: A list of all successfully fetched data.
"""
from solution import f... | import time
def fetch_data(max_calls_per_minute: int) -> list:
"""
Fetches data from the API while adhering to the rate limit.
Parameters:
max_calls_per_minute (int): The maximum number of API calls allowed per minute.
Returns:
list: A list of all successfully fetched data.
"""
... | from solution import fetch_data, mock_api_call
def test_fetch_data_rate_limit():
data = fetch_data(10)
assert len(data) <= 10
assert all(d == "Some data" for d in data)
def test_fetch_data_handles_errors():
data = fetch_data(100)
assert len(data) <= 100
def test_fetch_data_rate_limit_exceeded():
... | [
{
"docstring": "Fetches data from the API while adhering to the rate limit.\n\nParameters:\nmax_calls_per_minute (int): The maximum number of API calls allowed per minute.\n\nReturns:\nlist: A list of all successfully fetched data.",
"function_declaration": "def fetch_data(max_calls_per_minute):",
"func... | [
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": "import time\n\ndef mock_api_call():\n import random\n if random.randint(1, 10) <= 2:\n return {\n \"status\": \"error\",\n ... | trial_gpt4o_2 | {
"original_instruction": "You are working on a software feature that occasionally needs to make API calls to fetch data. Each API call should return a JSON object that contains the following structure:\n\n```json\n{\n \"status\": \"ok\" or \"error\",\n \"data\": \"the requested data\" or null,\n \"error_mes... | 0.674006 | Code_Contests_12268 | C | [
"fetch_data",
"mock_api_call"
] | 2 | [
[
"fetch_data",
"mock_api_call"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 807174f3bb5e5b336287f7d3e0e1bfa95bd49e08 | 0c492d07a8771c0889b26f8dbd92dd3fbf88e3fc | |||
v1.0 | complete | Code_Contests | Code_Contests_12396_C | def is_prime(num):
""" Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(4) False
>>> is_prime(11) True
>>> is_prime(-1) False
"""
...
def can_be_partitioned(arr):
""" Check if the array can be partitioned such that each subarray's sum is a prime number.
>>> can_be_parti... | def is_prime(num):
if num <= 1:
return False
elif num <= 3:
return True
elif 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 can_be_partitioned(arr... | 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(-1) == False
def test_can_be_partitioned():
assert can_be_partitioned([2, 3, 5, 7]) == True
assert can_be_partitioned([1, -1, 3]) == False
a... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def can_be_partitioned(arr):",
"function_name": "can_be_partitioned",
"parameter_list": "(arr)"
},
{
... | [
0,
0,
0,
0,
0,
0,
1,
1,
0,
0
] | 2 | hard | 0.2 | {
"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 Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_7 | {
"original_instruction": "Susan loves playing with numbers and is particularly fascinated with prime numbers. One day, she decides to create a game involving an array of integers. The game is played as follows:\n\n1. Given an array of integers, Susan partitions the array into contiguous subarrays.\n2. She checks if ... | 0.6202 | Code_Contests_12396 | C | [
"is_prime",
"can_be_partitioned",
"susans_game"
] | 3 | [
[
"can_be_partitioned",
"is_prime"
],
[
"susans_game",
"can_be_partitioned"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | c83b650f256a52654bd12c25d0fadcba0febe92e | ab969f1ddad88728244517a6caccbacc667f6adb | |||
v1.0 | complete | Code_Contests | Code_Contests_13550_C | def is_prime(num: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def longest_prime_subarray_length(n: int, array: List[int]) -> int:
""" Find the length of the longest contiguous subarray consisting of only prime numbers.
... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def longest_prime_subarray_length(n, array):
longest_length = 0
... | from solution import is_prime, longest_prime_subarray_length
def test_is_prime():
assert is_prime(2) is True
assert is_prime(3) is True
assert is_prime(4) is False
assert is_prime(29) is True
assert is_prime(1) is False
assert is_prime(-7) is False
def test_longest_prime_subarray_length():
... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_subarray_length(n, array):",
"function_name": "longest_prime_subarray_length",
"parameter_l... | [
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 Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n ... | trial_gpt4o_2 | {
"original_instruction": "You're given an array of integers of length n. Your task is to find the length of the longest subarray consisting of only prime numbers from the array. The subarray should be contiguous.\n\nA prime number is a positive integer greater than 1, with no positive integer divisors other than 1 a... | 0.721179 | Code_Contests_13550 | C | [
"is_prime",
"longest_prime_subarray_length"
] | 2 | [
[
"longest_prime_subarray_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c51afd168de8a8be613d17122dc821de5435fdc5 | 439e4920532ab721b4b0060ad5c18472d4268ccd | |||
v1.0 | complete | Code_Contests | Code_Contests_12444_C | def flip_subgrid(grid, x1, y1):
for i in range(2):
for j in range(2):
grid[x1 + i][y1 + j] = 1 - grid[x1 + i][y1 + j]
def transform_grid(n, m, initial, final):
""" Transform the initial grid to the final grid state using the minimum number of 2x2 sub-grid flips.
Args:
n (int): Numbe... | def flip_subgrid(grid, x1, y1):
for i in range(2):
for j in range(2):
grid[x1 + i][y1 + j] = 1 - grid[x1 + i][y1 + j]
def transform_grid(n, m, initial, final):
ops = []
initial = [list(map(int, row)) for row in initial]
final = [list(map(int, row)) for row in final]
for i in ra... | from solution import transform_grid
def test_transform_grid_example_1():
n, m = 3, 3
initial = ["011", "101", "110"]
final = ["000", "111", "000"]
ops = transform_grid(n, m, initial, final)
assert len(ops) <= n * m # Ensure the number of operations is within bounds
for x1, y1, x2, y2 in ops:
... | [
{
"docstring": null,
"function_declaration": "def flip_subgrid(grid, x1, y1):",
"function_name": "flip_subgrid",
"parameter_list": "(grid, x1, y1)"
},
{
"docstring": null,
"function_declaration": "def transform_grid(n, m, initial, final):",
"function_name": "transform_grid",
"par... | [
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 transform_grid(n, m, initial, final):\n operations = []\n\n # Defining utility function to flip a 2x2 sub-grid\n def flip(x1, y1):\n fo... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid with n rows and m columns. Each cell in the grid contains either a 0 or a 1. Your task is to transform this grid into a desired pattern using the following operation:\n\n* Select any sub-grid of dimensions 2x2 and flip all the bits within this sub-grid (turn 0s into 1s ... | 0.63067 | Code_Contests_12444 | C | [
"flip_subgrid",
"transform_grid"
] | 2 | [
[
"transform_grid",
"flip_subgrid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 698b9180639e4aaa43c2ee9d0dd44c2be84505a7 | 197d523c59a2ce91029ed46089a325b075660258 | |||
v1.0 | complete | Code_Contests | Code_Contests_13396_C | def find_longest_word(n: int, dictionary: List[str], s: str) -> str:
"""
Find the longest word in the dictionary that can be formed by deleting some characters from S
without reordering the remaining characters.
>>> find_longest_word(5, ["able", "ale", "apple", "bale", "kangaroo"], "abpcplea")
... | def is_subsequence(word, s):
it = iter(s)
return all(char in it for char in word)
def find_longest_word(n, dictionary, s):
longest_word = ""
for word in dictionary:
if is_subsequence(word, s):
if len(word) > len(longest_word) or (len(word) == len(longest_word) and word < longest_wor... | from solution import find_longest_word
def test_case_1():
dictionary = ["able", "ale", "apple", "bale", "kangaroo"]
s = "abpcplea"
assert find_longest_word(5, dictionary, s) == "apple"
def test_case_2():
dictionary = ["a", "b", "c", "d"]
s = "abcd"
assert find_longest_word(4, dictionary, s) ==... | [
{
"docstring": null,
"function_declaration": "def is_subsequence(word, s):",
"function_name": "is_subsequence",
"parameter_list": "(word, s)"
},
{
"docstring": null,
"function_declaration": "def find_longest_word(n, dictionary, s):",
"function_name": "find_longest_word",
"paramet... | [
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_subsequence(word, s):\n it = iter(s)\n return all(char in it for char in word)\n\ndef find_longest_word(n, dictionary, s):\n longest_word =... | trial_gpt4o_0 | {
"original_instruction": "In a small village, there is a peculiar lock that can only be opened with a unique keyphrase. The village chief has entrusted you with the task of finding this keyphrase. The keyphrase is represented by a string S consisting of lowercase English letters.\n\nYou are given a dictionary contai... | 0.772896 | Code_Contests_13396 | C | [
"is_subsequence",
"find_longest_word"
] | 2 | [
[
"find_longest_word",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0b16ba9d0f95e2a1a7dcd7bf86fefc387fe6ec59 | 5c15bae438fbc6dd34ad586b4a9be3f2f8bf1d9c | |||
v1.0 | complete | Code_Contests | Code_Contests_13239_C | from typing import List
def find_hamiltonian_path(n: int, graph: List[List[int]]) -> str:
""" Determine if there is a Hamiltonian path in the graph.
>>> find_hamiltonian_path(4, [
[0, 1, 0, 0],
[1, 0, 1, 0],
[0, 1, 0, 1],
[0, 0, 1, 0]
])
"Yes"
>>>... | from itertools import permutations
def query_edge(graph, u, v):
return "Yes" if graph[u-1][v-1] == 1 else "No"
def find_hamiltonian_path(n, graph):
nodes = range(1, n + 1)
for perm in permutations(nodes):
is_path = True
for i in range(n - 1):
u, v = perm[i], perm[i+1]
... | def test_hamiltonian_path_yes_case():
n = 4
graph = [
[0, 1, 0, 0],
[1, 0, 1, 0],
[0, 1, 0, 1],
[0, 0, 1, 0]
]
assert find_hamiltonian_path(n, graph) == "Yes"
def test_hamiltonian_path_no_case():
n = 4
graph = [
[0, 1, 0, 0],
[1, 0, 0, 0],
... | [
{
"docstring": null,
"function_declaration": "def query_edge(graph, u, v):",
"function_name": "query_edge",
"parameter_list": "(graph, u, v)"
},
{
"docstring": null,
"function_declaration": "def find_hamiltonian_path(n, graph):",
"function_name": "find_hamiltonian_path",
"paramet... | [
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 itertools\n\ndef hamiltonian_path_exist(adj_matrix):\n n = len(adj_matrix)\n \n def has_edge(u, v):\n return adj_matrix[u-1][v-1] ==... | trial_gpt4o_1 | {
"original_instruction": "You are given a graph with n nodes numbered 1 through n. The graph is represented as an adjacency matrix A where Ai, j = 1 if there is an edge between node i and node j, and Ai, j = 0 otherwise.\n\nYour task is to determine if there is a Hamiltonian path in the graph. A Hamiltonian path is ... | 0.50562 | Code_Contests_13239 | C | [
"query_edge",
"find_hamiltonian_path"
] | 2 | [
[
"find_hamiltonian_path",
"query_edge"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3127b3c089ece4f46823f2c68fa90df8c8dbd15c | f122421d3031c406291a99400084590dfee51f32 | |||
v1.0 | complete | Code_Contests | Code_Contests_7351_C | def minimum_cost_to_connect_islands(n: int, m: int, bridges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum total cost required to build the network of bridges that connects all islands.
Args:
n (int): The number of islands.
m (int): The number of potential bridges.
bridges (List... | def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
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
elif rank[rootX... | from solution import minimum_cost_to_connect_islands
def test_example_case():
n = 4
m = 5
bridges = [
(1, 2, 10),
(2, 3, 15),
(3, 4, 20),
(4, 1, 25),
(2, 4, 30)
]
assert minimum_cost_to_connect_islands(n, m, bridges) == 45
def test_disconnected_graph():
... | [
{
"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,
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 minimum_cost_to_connect_islands(N, M, bridges):\n \"\"\"\n Calculate the minimum cost to connect all islands using the potential bridges.\n \n... | trial_gpt4o_2 | {
"original_instruction": "BingLand is famous for its scenic river channels and floating markets. As tourism is growing, the government has decided to build a network of bridges to connect various islands. There are N islands in BingLand, each uniquely numbered from 1 to N. Each island must be connected with at least... | 0.765681 | Code_Contests_7351 | C | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_islands"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_islands",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | b13c7c2573d7c83da3a343500c36dd631c6db4e2 | 51a0e1de40390d58f4ba2c9f7c50fcea9f93b250 | |||
v1.0 | complete | Code_Contests | Code_Contests_12883_C | def min_byes_required(n: int) -> int:
"""
Returns the minimum number of byes required to proceed in a single-elimination tournament
with n participants.
>>> min_byes_required(5)
3
>>> min_byes_required(8)
0
>>> min_byes_required(13)
3
"""
def process_tournaments(m: int, par... | import math
def min_byes_required(n):
"""
Returns the minimum number of byes required to proceed in a single-elimination tournament
with n participants.
"""
# Calculate the next power of 2 greater than or equal to n
if n & (n - 1) == 0:
# n is already a power of 2
return 0
n... | from solution import min_byes_required, process_tournaments
def test_min_byes_required():
assert min_byes_required(5) == 3
assert min_byes_required(8) == 0
assert min_byes_required(13) == 3
assert min_byes_required(1) == 0
assert min_byes_required(31) == 1
assert min_byes_required(32) == 0
... | [
{
"docstring": "Returns the minimum number of byes required to proceed in a single-elimination tournament\nwith n participants.",
"function_declaration": "def min_byes_required(n):",
"function_name": "min_byes_required",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declarati... | [
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 min_byes_required(n):\n \"\"\"\n Returns the minimum number of byes required to proceed in a single-elimination tournament\n wi... | trial_gpt4o_0 | {
"original_instruction": "In a gaming tournament, n participants compete in a single-elimination format (i.e., if you lose once, you are out). Each match results in either win or loss, and there is no draw. Given n participants, the tournament proceeds in rounds until one champion is determined. \n\nHowever, during ... | 0.584252 | Code_Contests_12883 | C | [
"min_byes_required",
"process_tournaments"
] | 2 | [
[
"process_tournaments",
"min_byes_required"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a0fd99c4427a72c2f60f6d00cf9adf902b60d30b | e517902cbb27783fcb013dff87d7995df126a038 | |||
v1.0 | complete | Code_Contests | Code_Contests_12877_C | from typing import List
def length_of_lds(nums: List[int]) -> int:
"""
Given an array of integers nums, return the length of the longest strictly decreasing subsequence (LDS) in nums.
A strictly decreasing subsequence is defined as a subsequence where for all i < j, nums[i] > nums[j].
Constraints:
... | def length_of_lds(nums):
"""
Returns the length of the longest strictly decreasing subsequence (LDS) in nums.
"""
if not nums:
return 0
n = len(nums)
dp = [1] * n # Initialize dp array where dp[i] is the length of LDS ending at index i
for i in range(1, n):
for j in range... | from solution import length_of_lds
def test_length_of_lds():
assert length_of_lds([9, 4, 3, 8, 6, 7]) == 3
assert length_of_lds([10, 20, 30, 0]) == 2
assert length_of_lds([5, 3, 4, 8, 6, 7]) == 2
assert length_of_lds([1, 2, 3, 4, 5]) == 1
assert length_of_lds([5, 4, 3, 2, 1]) == 5
assert length... | [
{
"docstring": "Returns the length of the longest strictly decreasing subsequence (LDS) in nums.",
"function_declaration": "def length_of_lds(nums):",
"function_name": "length_of_lds",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_find_... | [
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 length_of_lds(nums):\n \"\"\"\n Returns the length of the longest strictly decreasing subsequence (LDS) in nums.\n \"\"\"\n\n if not nums:\... | trial_gpt4o_0 | {
"original_instruction": "Given an array of integers nums, return the length of the longest strictly decreasing subsequence (LDS) in nums.\n\nA strictly decreasing subsequence is defined as a subsequence where for all i < j, nums[i] > nums[j].\n\nConstraints\n\n* 1 ≤ nums.length ≤ 100000\n* -109 ≤ nums[i] ≤ 109\n\nI... | 0.755898 | Code_Contests_12877 | C | [
"length_of_lds",
"process_input_and_find_lds"
] | 2 | [
[
"process_input_and_find_lds",
"length_of_lds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77bc607b1c28503de5561933b47bb9bb8e1fc40e | bd4f98b70552822e4d254aacd22a2d1ef5b19c9c | |||
v1.0 | complete | Code_Contests | Code_Contests_6542_C | def caesar_cipher(t, cases):
"""Applies Caesar Cipher encryption technique to a list of cases.
Each case consists of a tuple where the first element is a string S of
lowercase English characters, and the second element is an integer K,
the number of positions each character in S should be shifted... | def caesar_cipher(t, cases):
results = []
for case in cases:
s, k = case
encrypted = []
for char in s:
new_char = chr(((ord(char) - ord('a') + k) % 26) + ord('a'))
encrypted.append(new_char)
results.append(''.join(encrypted))
return results
def parse_... | import pytest
from solution import caesar_cipher, run_caesar_cipher
def test_single_case():
input_str = "1\nhello 3"
expected_output = "khoor"
assert run_caesar_cipher(input_str) == expected_output
def test_multiple_cases():
input_str = "2\nhello 3\nxyz 2"
expected_output = "khoor\nzab"
assert... | [
{
"docstring": null,
"function_declaration": "def caesar_cipher(t, cases):",
"function_name": "caesar_cipher",
"parameter_list": "(t, cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input_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 caesar_cipher(test_cases):\n results = []\n for s, k in test_cases:\n encrypted_string = ''\n for char in s:\n new_char ... | trial_gpt4o_2 | {
"original_instruction": "Problem Description\n\nJane has recently started discovering the world of cryptography and is fascinated by simple encryption techniques. She challenges herself by creating and deciphering ciphers using basic letter shifts. One of her favorite techniques is the Caesar Cipher, where each let... | 0.665535 | Code_Contests_6542 | C | [
"caesar_cipher",
"parse_input",
"run_caesar_cipher"
] | 3 | [
[
"run_caesar_cipher",
"caesar_cipher"
],
[
"run_caesar_cipher",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | aa04e64ed7508990c5cfcc1556052b417f4ba479 | e5ad5e124bd9c5411b73fcbe3404906b5dad7b55 | |||
v1.0 | complete | Code_Contests | Code_Contests_12100_C | from collections import defaultdict, deque
import sys
from typing import List, Tuple
def bfs_min_time(N: int, adjacency_list: defaultdict) -> List[int]:
""" Calculate minimum time required for every house to be reached from house 1.
Args:
N: int: Number of houses.
adjacency_list: defaultdict: Adjacenc... | from collections import defaultdict, deque
import sys
def bfs_min_time(N, adjacency_list):
dist = [-1] * (N + 1)
dist[1] = 0
queue = deque([1])
while queue:
current = queue.popleft()
for neighbor, time in adjacency_list[current]:
if dist[neighbor] == -1:
dis... | from solution import bfs_min_time, solve, process_input
def test_bfs_min_time():
test_cases = [
(4, [(1, 2, 5), (1, 3, 10), (2, 4, 3), (3, 4, 1)]),
(3, [(1, 2, 1), (1, 3, 4)])
]
expected_results = [
[5, 10, 8],
[1, 4]
]
for i, (N, roads) in enumerate(test_cases)... | [
{
"docstring": null,
"function_declaration": "def bfs_min_time(N, adjacency_list):",
"function_name": "bfs_min_time",
"parameter_list": "(N, adjacency_list)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(te... | [
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 collections import defaultdict, deque\nimport sys\n\ndef bfs_min_time(N, adjacency_list):\n dist = [-1] * (N + 1)\n dist[1] = 0\n\n queue = d... | trial_gpt4o_0 | {
"original_instruction": "A village contains several houses connected by bidirectional roads. Each road has a certain length, which represents the time it takes to travel from one house to another. The village chief wants to ensure that every house is reachable from his house, which is labeled as house number 1, in ... | 0.673706 | Code_Contests_12100 | C | [
"bfs_min_time",
"solve",
"process_input"
] | 3 | [
[
"solve",
"bfs_min_time"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | ce2b899b5d948012a8d42374cfb5a73f212c3d04 | 2ac5d7bb19d79db1036f101c646422aea2893464 | |||
v1.0 | complete | Code_Contests | Code_Contests_13348_C | def garden_watering(N: int, M: int, garden: List[List[int]], requests: List[Tuple[int, int, int, int]]) -> List[int]:
""" Calculate the amount of water needed to water sub-rectangles in a garden.
Args:
N (int): Number of rows in the garden.
M (int): Number of columns in the garden.
garden (List... | def preprocess_garden(garden):
N = len(garden)
M = len(garden[0])
prefix_sum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, M + 1):
prefix_sum[i][j] = (garden[i-1][j-1]
+ prefix_sum[i-1][j]
... | from solution import garden_watering
def test_garden_watering_single_request():
N, M = 4, 4
garden = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
requests = [(1, 1, 2, 2)]
assert garden_watering(N, M, garden, requests) == [14]
def test_garden_wa... | [
{
"docstring": null,
"function_declaration": "def preprocess_garden(garden):",
"function_name": "preprocess_garden",
"parameter_list": "(garden)"
},
{
"docstring": null,
"function_declaration": "def water_amount(prefix_sum, r1, c1, r2, c2):",
"function_name": "water_amount",
"par... | [
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 preprocess_plants(garden, N, M):\n # Create a prefix sum matrix\n prefix_sum = [[0] * (M + 1) for _ in range(N + 1)]\n \n for i in range(1,... | trial_gpt4o_1 | {
"original_instruction": "Garden Watering System\n\nYou are tasked with designing an efficient watering system for a rectangular garden represented as an $N \\times M$ grid where each cell in the grid contains a certain number of plants. You want to water all the plants in the garden, but you also aim to minimize th... | 0.629637 | Code_Contests_13348 | C | [
"preprocess_garden",
"water_amount",
"garden_watering"
] | 3 | [
[
"garden_watering",
"preprocess_garden"
],
[
"garden_watering",
"water_amount"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d3c03a4b42f64f4a044fe00f10e77843dd4f1756 | afa3fe19ce2e5a5d71c17dbacc272d7e364d83d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_13666_C | from typing import List
def find_exactly_half_prime(t: int, primes: List[int]) -> List[str]:
""" Alice defines an exactly half prime as a number that is prime and exactly half of another prime number.
Given a list of prime numbers, find if there is an exactly half prime such that when doubled is also a pr... | from sympy import isprime
def find_exactly_half_prime(t, primes):
results = []
for p in primes:
q = p // 2
if p % 2 == 0 and isprime(q):
results.append(f"YES {q}")
else:
results.append("NO")
return results
def prime_as_half_of_another_prime(test_cases):
... | from solution import prime_as_half_of_another_prime
def test_case_1():
input_data = ["3", "7", "11", "13"]
expected_output = ["NO", "NO", "NO"]
assert prime_as_half_of_another_prime(input_data) == expected_output
def test_case_2():
input_data = ["3", "3", "5", "7"]
expected_output = ["NO", "NO", "... | [
{
"docstring": null,
"function_declaration": "def find_exactly_half_prime(t, primes):",
"function_name": "find_exactly_half_prime",
"parameter_list": "(t, primes)"
},
{
"docstring": null,
"function_declaration": "def prime_as_half_of_another_prime(test_cases):",
"function_name": "pri... | [
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 sympy import isprime\n\ndef find_exactly_half_prime(t, primes):\n results = []\n for p in primes:\n q = p // 2\n if p % 2 == 0 and... | trial_gpt4o_0 | {
"original_instruction": "Alice loves prime numbers and has recently found an interesting property related to them. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Alice defines an **exactly half prime** as a number that is prime and exactly half of another pr... | 0.693376 | Code_Contests_13666 | C | [
"find_exactly_half_prime",
"prime_as_half_of_another_prime"
] | 2 | [
[
"prime_as_half_of_another_prime",
"find_exactly_half_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [
"sympy"
] | false | 55afb4d98f83ca28f60cc9566298a38fb05c2a57 | b4d6be7697504d3a8a537487d911f583804d26c6 | |||
v1.0 | complete | Code_Contests | Code_Contests_13086_C | def shortest_travel_times(n: int, m: int, subway_lines: List[Tuple[int, int, int]], q: int, queries: List[Tuple[int, int]]) -> List[int]:
""" Given the subway network details and a number of commuter inquiries, provides the shortest travel time for each query.
If it is not possible to travel between two station... | def floyd_warshall(n, edges):
# Initialize the distance matrix
inf = float('inf')
dist = [[inf] * n for _ in range(n)]
# Distance to itself is 0
for i in range(n):
dist[i][i] = 0
# Initialize distances based on direct edges
for u, v, t in edges:
dist[u-1][v-1] = t
... | def test_shortest_travel_times():
n = 4
m = 4
subway_lines = [
(1, 2, 5),
(2, 3, 10),
(3, 4, 3),
(1, 4, 20)
]
q = 3
queries = [
(1, 3),
(1, 4),
(2, 4)
]
expected_results = [15, 18, 13]
assert shortest_travel_times(n, m, subway_l... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_travel_times(n, m, subway_lines, q, queries):",
"function_name": "shortest_tra... | [
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": "import heapq\n\ndef dijkstra(graph, start, n):\n \"\"\"\n Helper function to perform Dijkstra's algorithm for shortest paths.\n :param graph: adja... | trial_gpt4o_2 | {
"original_instruction": "A city named Metroville has been expanding its subway network. The city has a series of subway stations connected by bi-directional lines. Each subway station has a unique identifier, and each line connecting two stations has an associated travel time. Commuters want to find the shortest tr... | 0.692374 | Code_Contests_13086 | C | [
"floyd_warshall",
"shortest_travel_times"
] | 2 | [
[
"shortest_travel_times",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 96b0323eac2c9e8b024afd9415c7bf3cee514638 | 824c229ebef0de603238e14dfd0f85ab2dd35696 | |||
v1.0 | complete | Code_Contests | Code_Contests_14061_C | from typing import List
def is_prime(num: int) -> bool:
"""
Check if the given number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def evaluate_expressions(expressions: List[str]) -> List[str]:
"""
Evaluate a list of mathematical expressions and... | def is_prime(num):
"""
Check if the given number is a prime number.
"""
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 Fal... | from solution import is_prime, evaluate_expressions
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(30) == False
def test_evaluate_expressions():
expressions = [
... | [
{
"docstring": "Check if the given number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Evaluate a list of mathematical expressions and determine if\ntheir results are prime numbers.",
"functio... | [
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": "import math\n\ndef is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return ... | trial_gpt4o_4 | {
"original_instruction": "Write a program that reads an integer $n$ (2 ≤ n ≤ 50) and then reads $n$ strings each representing a mathematical expression containing only non-negative integers and the operators '+', '-', '*', and '/'. Determine if each expression evaluates to a prime number.\n\nConstraints\n\n- Each ma... | 0.752525 | Code_Contests_14061 | C | [
"is_prime",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5b5835ea675c1cc201e8cd4c21d5fee81ceff9d9 | 7aa5d8fef265128a6a0a9060e60e19f5985c0bc8 | |||
v1.0 | complete | Code_Contests | Code_Contests_13501_C | from typing import List, Tuple
def find(parent, i):
# Find the root of the set in which element i is located
pass
def union(parent, rank, x, y):
# Perform union of two subsets x and y
pass
def min_cost_to_connect_islands(m: int, n: int, bridges: List[Tuple[int, int, int]]) -> int:
""" Mayank th... | 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_y] = root_x
elif rank[r... | from solution import min_cost_to_connect_islands
def test_example():
assert min_cost_to_connect_islands(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 3, 2), (2, 4, 3)]) == 6
def test_minimal_case():
assert min_cost_to_connect_islands(2, 1, [(1, 2, 1)]) == 1
def test_small_case():
assert min_cost_to_connect... | [
{
"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)"
},
... | [
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 find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, ... | trial_gpt4o_1 | {
"original_instruction": "Mayank the Architect is designing an archipelago of islands connected by bridges. The goal is to ensure that every island can be visited starting from any other island, by using one or more bridges. Each bridge connects exactly two islands and can be traversed in both directions.\n\nInitial... | 0.664241 | Code_Contests_13501 | C | [
"find",
"union",
"min_cost_to_connect_islands"
] | 3 | [
[
"min_cost_to_connect_islands",
"find"
],
[
"min_cost_to_connect_islands",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fb1316557f07c121c438750397e5f1e20026f59e | 2ad71e028028d4f06bb7381fc192e241a8ee9b65 | |||
v1.0 | complete | Code_Contests | Code_Contests_13441_C | from typing import List, Tuple, Union
def deliver_message(n: int, m: int, initial_open_routes: List[Tuple[int, int]]) -> Union[int, Tuple[int, List[int]]]:
"""
A secret agent needs to travel through a network of safe houses in different cities to deliver an important message.
The network consists of `n` s... | from collections import deque, defaultdict
def find_shortest_path(n, m, routes):
if n == 2 and m == 0:
return -1
graph = defaultdict(list)
for u, v in routes:
graph[u].append(v)
graph[v].append(u)
dist = [-1] * (n + 1)
visited = [False] * (n + 1)
dist[1... | def test_find_shortest_path():
assert deliver_message(6, 7, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (1, 3), (4, 6)]) == (3, [1, 3, 4, 6])
assert deliver_message(6, 2, [(1, 2), (5, 6)]) == -1
assert deliver_message(3, 1, [(1, 2)]) == -1
assert deliver_message(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) == (... | [
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, routes):",
"function_name": "find_shortest_path",
"parameter_list": "(n, m, routes)"
},
{
"docstring": null,
"function_declaration": "def deliver_message(n, m, initial_open_routes):",
"function_name": "deliver... | [
0,
0,
0,
0,
0,
0,
0,
1,
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 deque, defaultdict\n\ndef min_route_changes(n, m, routes):\n # Graph adjacency list\n graph = defaultdict(list)\n for u, v... | trial_gpt4o_8 | {
"original_instruction": "A secret agent needs to travel through a network of safe houses in different cities to deliver an important message. The network consists of `n` safe houses, where each pair of safe houses is connected by a two-way route that can be open or closed. The mission starts at the first safe house... | 0.637788 | Code_Contests_13441 | C | [
"find_shortest_path",
"deliver_message"
] | 2 | [
[
"deliver_message",
"find_shortest_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d35ead5f722fdf40c39affbf095439834165a3aa | aa375746da805d197bded6fa8a9042858307309e | |||
v1.0 | complete | Code_Contests | Code_Contests_13392_C | import math
def is_prime(n: int) -> bool:
""" Determine if a given number is prime.
"""
pass # Implement this function
def is_beautiful_number(binary_string: str) -> str:
""" Determines if a given binary-like number is beautiful according to the alien numeral system.
A beautiful number is de... | import math
def is_prime(n):
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
i += 6
return True
def is_beautiful_number(binary_st... | from solution import is_beautiful_number
def test_is_beautiful_number():
assert is_beautiful_number("101011") == "NO"
assert is_beautiful_number("100000") == "NO"
assert is_beautiful_number("11100") == "YES"
assert is_beautiful_number("1") == "NO"
assert is_beautiful_number("1111") == "NO"
asse... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_beautiful_number(binary_string):",
"function_name": "is_beautiful_number",
"parameter_list": "(binary_stri... | [
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": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n retur... | trial_gpt4o_0 | {
"original_instruction": "In a distant galaxy, there is a peculiar alien species that communicates via a very unique number system. Each number they use is composed of digits 0 and 1, much like binary numbers. However, the aliens have a special rule: they consider the numbers to be beautiful if the number of '1's in... | 0.703352 | Code_Contests_13392 | C | [
"is_prime",
"is_beautiful_number"
] | 2 | [
[
"is_beautiful_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5038d9fe00eefcfe3d39ca31e63f9c5b12ffae39 | bcc2a40f8df30db33b9c54c30b7f2002b17eaa18 | |||
v1.0 | complete | Code_Contests | Code_Contests_13596_C | def sum_of_digits(n: int) -> int:
"""Returns the sum of the digits of the given number n.
>>> sum_of_digits(123)
6
>>> sum_of_digits(456)
15
>>> sum_of_digits(789)
24
"""
pass
def categorize_books_by_digit_sum(datasets: List[List[int]]) -> List[Dict[int, List[int]]]:
"""Categori... | def sum_of_digits(n):
"""
Returns the sum of the digits of the given number n.
"""
return sum(int(digit) for digit in str(n))
def categorize_books_by_digit_sum(datasets):
"""
Categorizes book IDs by the sum of their digits.
Args:
datasets (list of list): A list where each element i... | from solution import sum_of_digits, categorize_books_by_digit_sum
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(101112) == 6
assert sum_of_digits(131415) == 15
assert sum_of_digits(111111) == 6
a... | [
{
"docstring": "Returns the sum of the digits of the given number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Categorizes book IDs by the sum of their digits.\n\nArgs:\ndatasets (list of list): A list wher... | [
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 sum_of_digits(n):\n return sum(int(digit) for digit in str(n))\n\ndef categorize_books_by_digit_sum(datasets):\n results = []\n for dataset in... | trial_gpt4o_6 | {
"original_instruction": "A digital library system keeps records of books being borrowed. Each book is associated with a unique ID number, and for simplicity, the library has decided to categorize books by their ID number based on the sum of their digits. \n\nYour task is to create a program that categorizes and lis... | 0.543733 | Code_Contests_13596 | C | [
"sum_of_digits",
"categorize_books_by_digit_sum"
] | 2 | [
[
"categorize_books_by_digit_sum",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7d388eb4fab1b6aaa3f3375f9b9c19eba38c9a99 | 370621bd65b8d1d4f11212efe8fb725710811817 | |||
v1.0 | complete | Code_Contests | Code_Contests_12518_C | def surviving_trees(trees):
"""
Determines the number of trees that survive in the row after adjacent trees
fight for sunlight repeatedly, until no more trees can die.
Parameters:
trees (List[int]): A list of integers representing the heights of the trees.
Returns:
int: The number of tree... | def surviving_trees(trees):
while True:
new_trees = [trees[0]]
for i in range(1, len(trees)):
if trees[i] <= trees[i-1]:
new_trees.append(trees[i])
if len(new_trees) == len(trees):
return len(new_trees)
trees = new_trees
def solution(test_case... | from solution import solution, read_input
def test_solution_with_example_cases():
input_str = """2
6
1 3 2 1 4 5
5
4 4 4 4 4"""
test_cases = read_input(input_str)
results = solution(test_cases)
assert results == [2, 5]
def test_solution_with_all_same_height():
input_str = """1
4
2 2 2 2"""
tes... | [
{
"docstring": null,
"function_declaration": "def surviving_trees(trees):",
"function_name": "surviving_trees",
"parameter_list": "(trees)"
},
{
"docstring": null,
"function_declaration": "def solution(test_cases):",
"function_name": "solution",
"parameter_list": "(test_cases)"
... | [
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": "def surviving_trees(T, test_cases):\n \"\"\"\n Determines the number of surviving trees at the end of the process where shorter trees between any two... | trial_gpt4o_7 | {
"original_instruction": "In a forest, there are N trees in a row, each with a certain height. Adjacent trees are fighting for sunlight, and the shorter tree between any two adjacent trees will die. This process repeats until no more trees can die because there are no more adjacent trees where one is shorter than th... | 0.576897 | Code_Contests_12518 | C | [
"surviving_trees",
"solution",
"read_input"
] | 3 | [
[
"solution",
"surviving_trees"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | 8ebfce06a506ca64b72bc465b4d4c6b5026fd960 | de2279808c802d41594dd4d1f46e47f9d86eef23 | |||
v1.0 | complete | Code_Contests | Code_Contests_13767_C | def can_assign(preferences, N, M, limit):
""" Helper function to check if it is possible to assign projects within the given limit."""
pass
def find_minimum_maximum(N, M, preferences):
""" Determine the minimum possible maximum number of students assigned to any single project by optimal assignment of stud... | import collections
def can_assign(preferences, N, M, limit):
counters = [0] * M
for pref in preferences:
assigned = False
for i in range(M):
project_index = pref[i] - 1
if counters[project_index] < limit:
counters[project_index] += 1
assig... | def test_case_1():
input_str = "3 4\n2 1 3 4\n1 3 2 4\n3 2 4 1"
assert main(input_str) == 1
def test_case_2():
input_str = "5 5\n1 2 3 4 5\n2 3 1 5 4\n3 4 2 1 5\n4 5 3 2 1\n5 1 4 3 2"
assert main(input_str) == 1
def test_case_3():
input_str = "4 3\n1 2 3\n2 1 3\n3 1 2\n2 3 1"
assert main(input... | [
{
"docstring": null,
"function_declaration": "def can_assign(preferences, N, M, limit):",
"function_name": "can_assign",
"parameter_list": "(preferences, N, M, limit)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_maximum(N, M, preferences):",
"function_name": "fi... | [
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 collections\n\ndef can_assign(preferences, N, M, limit):\n counters = [0] * M\n for pref in preferences:\n assigned = False\n fo... | trial_gpt4o_0 | {
"original_instruction": "Peter is organizing a science fair. There are N students who will participate in the fair. Each of these students has exactly M projects they are interested in, conveniently numbered from 1 to M. Each student ranks these projects by preference where 1 indicates their most preferred and M in... | 0.603292 | Code_Contests_13767 | C | [
"can_assign",
"find_minimum_maximum",
"main"
] | 3 | [
[
"find_minimum_maximum",
"can_assign"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2f5b03b7b858bf8848a0ef1e46fdfef5aa13bc7f | 30ae74c7c77d6bbc7688b2a8fd4eeca539a640c7 | |||
v1.0 | complete | Code_Contests | Code_Contests_13629_C | from typing import List
def lcm(a: int, b: int) -> int:
""" Returns the least common multiple of a and b.
>>> lcm(1, 2) 2
>>> lcm(2, 3) 6
"""
pass # Replace with implementation
def lcm_multiple(numbers: List[int]) -> int:
""" Returns the least common multiple of a list of numbers.
>>> lcm... | import math
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // math.gcd(a, b)
def lcm_multiple(numbers):
"""
Returns the least common multiple of a list of numbers.
"""
return reduce(lcm, numbers)
def earliest_report_... | def test_lcm():
assert lcm(1, 2) == 2
assert lcm(2, 3) == 6
assert lcm(3, 5) == 15
assert lcm(4, 5) == 20
def test_lcm_multiple():
assert lcm_multiple([1, 2, 3]) == 6
assert lcm_multiple([5, 10, 15, 20]) == 60
assert lcm_multiple([2, 3, 4, 5]) == 60
assert lcm_multiple([10, 20, 30]) == ... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the least common multiple of a list of numbers.",
"function_declaration": "def lcm_multiple(numbers):",
... | [
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 lcm(a, b):\n return a * b // math.gcd(a, b)\n\ndef earliest_complete_report_time(n, update_intervals):\... | trial_gpt4o_2 | {
"original_instruction": "A programmer is designing an automatic alarm system for a building with multiple sensors distributed across different rooms. Each sensor can detect either fire or smoke but not both. Each sensor has a periodic update interval, indicating how often it sends data to the central monitoring sys... | 0.559942 | Code_Contests_13629 | C | [
"lcm",
"lcm_multiple",
"earliest_report_time"
] | 3 | [
[
"earliest_report_time",
"lcm_multiple"
],
[
"lcm_multiple",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 929fe712f028c45709d032b6c85e472bb7ea60fe | fca993721423ca0cdbc846983dfe02a8a5beac42 | |||
v1.0 | complete | Code_Contests | Code_Contests_14251_C | from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(20)
False
"""
def generate_rotations(s: str) -> List[str]:
... | def is_prime(n):
"""
Helper function to check if a number 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 % (i + 2) == 0:
return False
i +... | from solution import is_circular_prime, generate_rotations, is_prime
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(20) == False
def test_generate_rotations():
assert generate_rotations("123") =... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate all rotations of the string s.",
"function_declaration": "def generate_rotations(s):",
"functi... | [
0,
0,
0,
0,
0,
1,
1,
1,
1,
0
] | 4 | medium | 0.4 | {
"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 a prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return Tru... | trial_gpt4o_7 | {
"original_instruction": "A group of explorers discovered an ancient, secretive code in the depths of a hidden cave. The code revealed a mysterious language known as \"Circular Prime\". This language involves evaluating string sequences that circle around a wheel with digits from 0 to 9.\n\nGiven a string of digits,... | 0.690728 | Code_Contests_14251 | C | [
"is_prime",
"generate_rotations",
"is_circular_prime"
] | 3 | [
[
"is_circular_prime",
"generate_rotations"
],
[
"is_circular_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2e2206a6b1f6ef3d365b1ea9648ad70d103cbbcf | fd797e4d67b05c6639bf5806f6a74d5b485865c6 | |||
v1.0 | complete | Code_Contests | Code_Contests_13683_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def isValidBST(root):
""" Determine if a binary tree is a valid Binary Search Tree (BST).
The left subtree of a node contains only nodes with values less than the nod... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def isValidBST(root):
def validate(node, low=float('-inf'), high=float('inf')):
# Empty trees are valid BSTs
if not node:
return True
... | import pytest
from solution import validate_bst_for_test_cases, process_input
def test_case_1():
input_str = "2\n3\n2 1 3\n1 -1 -1\n3 -1 -1\n3\n2 3 1\n3 -1 -1\n1 -1 -1"
test_cases = process_input(input_str)
assert validate_bst_for_test_cases(test_cases) == [True, False]
def test_case_2():
input_str =... | [] | [
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": "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_0 | {
"original_instruction": "You are given a binary tree of n nodes, where each node has a unique integer value. You need to determine if the tree is a valid Binary Search Tree (BST). A binary search tree is defined as follows:\n\n- The left subtree of a node contains only nodes with values less than the node's value.\... | 0.618035 | Code_Contests_13683 | C | [
"isValidBST",
"create_tree_from_list",
"validate_bst_for_test_cases",
"process_input"
] | 4 | [
[
"validate_bst_for_test_cases",
"create_tree_from_list"
],
[
"validate_bst_for_test_cases",
"isValidBST"
]
] | 2 | [
"validate_bst_for_test_cases",
"process_input"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 0231705ca3a6737ad7c9b5d268c5e90eae9b2f21 | d31ad0fd91562ac2f8d1d281da43fe352ed3c6a2 | |||
v1.0 | complete | Code_Contests | Code_Contests_15650_C | def knapsack(N, W, items):
"""
Returns the maximum total value of items that can be put into the box
with capacity W using the given items with their weights and values.
Example:
>>> knapsack(3, 50, [(10, 60), (20, 100), (30, 120)])
220
>>> knapsack(4, 10, [(5, 10), (4, 40), (6, 30), (... | def knapsack(N, W, items):
"""
Returns the maximum total value of items that can be put into the box
with capacity W using the given items with their weights and values.
"""
# Initialize DP table
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
weight, value... | from solution import knapsack
def test_knapsack_example_1():
assert knapsack(3, 50, [(10, 60), (20, 100), (30, 120)]) == 220
def test_knapsack_example_2():
assert knapsack(4, 10, [(5, 10), (4, 40), (6, 30), (3, 50)]) == 90
def test_knapsack_edge_case_1():
assert knapsack(1, 5, [(10, 60)]) == 0
def test_... | [
{
"docstring": "Returns the maximum total value of items that can be put into the box \nwith capacity W using the given items with their weights and values.",
"function_declaration": "def knapsack(N, W, items):",
"function_name": "knapsack",
"parameter_list": "(N, W, items)"
},
{
"docstring"... | [
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 knapsack_max_value(N, W, items):\n \"\"\"\n Returns the maximum total value of items that can be put into the box\n without exceeding the weig... | trial_gpt4o_2 | {
"original_instruction": "You have N unique items and a box that can hold up to a maximum capacity of W units. Each item has a weight and a value. Your task is to determine the maximum total value of items you can put into the box without exceeding the weight limit.\n\nConstraints\n\n* 1 ≤ N ≤ 1000\n* 1 ≤ W ≤ 10000\... | 0.590171 | Code_Contests_15650 | C | [
"knapsack",
"knapsack_from_input"
] | 2 | [
[
"knapsack_from_input",
"knapsack"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 20bba254df2d59ee393f9e1aa356ce3a6f462215 | 7f9fbcbb2a07a20e6ce1178c9dd649db14578df7 | |||
v1.0 | complete | Code_Contests | Code_Contests_14427_C | def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, False otherwise.
>>> is_prime(2) True
>>> is_prime(4) False
"""
pass
def sum_of_primes_subarray(arr: List[int], L: int, R: int) -> int:
"""
Returns the sum of prime numbers in the subarray defined by the indices L an... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
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_subarray, process_queries
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
assert is_prime(19) == True
def test_sum_of_primes_subarray():
... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers in the subarray defined by the indices L and R (inclusive).",
"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 is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of integers and a series of queries. For each query, you will be given two integers `L` and `R`, representing the left and right indices of a subarray within the list (inclusive). Your task is to find the sum of all the prime numbers in that subarray.\n\nA prime number ... | 0.660986 | Code_Contests_14427 | C | [
"is_prime",
"sum_of_primes_subarray",
"process_queries"
] | 3 | [
[
"process_queries",
"sum_of_primes_subarray"
],
[
"sum_of_primes_subarray",
"is_prime"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 21d382780f97b64c465f6d656744dbea188bed05 | 8051b13318b73b374c430d9d17d3f5effcd85ec6 | |||
v1.0 | complete | Code_Contests | Code_Contests_13893_C | def find_max_area_histogram(heights):
"""Calculate the largest rectangular area possible in a given histogram.
:param heights: List of non-negative integers representing the heights of the histogram's bars.
:return: The area of the largest possible rectangle.
"""
def parse_input(input_str):
"""
... | def find_max_area_histogram(heights):
"""
Calculate the largest rectangular area possible in a given histogram.
:param heights: List of non-negative integers representing the heights of the histogram's bars.
:return: The area of the largest possible rectangle.
"""
stack = []
max_area = ... | def test_parse_input():
input_str = "6\n2 1 5 6 2 3\n"
assert parse_input(input_str) == [2, 1, 5, 6, 2, 3]
def test_find_max_area_histogram():
assert find_max_area_histogram([2, 1, 5, 6, 2, 3]) == 10
assert find_max_area_histogram([4, 4, 4, 4, 4]) == 20
assert find_max_area_histogram([6, 2, 5, 4, 5... | [
{
"docstring": "Calculate the largest rectangular area possible in a given histogram.\n\n:param heights: List of non-negative integers representing the heights of the histogram's bars.\n:return: The area of the largest possible rectangle.",
"function_declaration": "def find_max_area_histogram(heights):",
... | [
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_histogram_area(heights):\n \"\"\"\n Calculate the maximum rectangular area in a histogram.\n\n :param heights: List of non-negative intege... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of non-negative integers representing the heights of walls in a histogram. Each bar in the histogram is 1 unit wide. Your task is to calculate the maximum rectangular area that can be formed within the bounds of the histogram.\n\nInput\n\nThe first line contains a singl... | 0.593541 | Code_Contests_13893 | C | [
"find_max_area_histogram",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"find_max_area_histogram"
],
[
"solve",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 28712e77b0523aa5fa98b39b156863ee9e263faa | ad411a716241ba4195886050629ad3f796692cde | |||
v1.0 | complete | Code_Contests | Code_Contests_14028_C | from typing import List, Tuple
def possible_to_retain_roads(test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[Tuple[str, int, List[Tuple[int, int]]]]:
""" Bob is designing a traffic system in his city. The city consists of n intersections connected by m one-way roads.
Due to budget constraints... | from collections import defaultdict, deque
def find_sccs(n, graph):
index = [None] * n
lowlink = [None] * n
on_stack = [False] * n
stack = []
sccs = []
current_index = 0
def strongconnect(node):
nonlocal current_index
index[node] = current_index
lowlink[node] = curr... | def test_possible_to_retain_roads():
test_cases = [
(4, 5, [(1, 2), (2, 3), (3, 4), (4, 1), (2, 4)]),
(3, 3, [(1, 2), (2, 3), (3, 1)]),
(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)])
]
expected_output = [
("YES", 5, [(1, 2), (2, 3), (3, 4), (4, 1), (2, 4)]),
("YES", 3, [(1... | [
{
"docstring": null,
"function_declaration": "def find_sccs(n, graph):",
"function_name": "find_sccs",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def possible_to_retain_roads(test_cases):",
"function_name": "possible_to_retain_roads",
"paramet... | [
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_minimum_roads(t, test_cases):\n from collections import defaultdict, deque\n results = []\n \n def kosaraju(n, edges):\n graph ... | trial_gpt4o_1 | {
"original_instruction": "Bob is designing a traffic system in his city. The city consists of n intersections connected by m one-way roads. Due to budget constraints, Bob needs to minimize the number of roads to keep only essential ones while ensuring that it is still possible to travel from any intersection to any ... | 0.650903 | Code_Contests_14028 | C | [
"find_sccs",
"possible_to_retain_roads"
] | 2 | [
[
"possible_to_retain_roads",
"find_sccs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e2a12551bcecbf661f2bf1a3309c9c9376f1ea55 | 4578274f581ce6de9bd0a3dd213e49caefd5ad0a | |||
v1.0 | complete | Code_Contests | Code_Contests_14480_C | def check_palindrome_and_longest_substring(s: str) -> Tuple[str, str]:
""" Create a program that checks if a given string is a valid palindrome and then determines the longest palindromic substring within that string.
>>> check_palindrome_and_longest_substring("racecar")
("YES", "racecar")
>>> check_pal... | def is_palindrome(s):
"""
Checks if the entire string s is a palindrome.
"""
return s == s[::-1]
def longest_palindromic_substring(s):
"""
Finds the longest palindromic substring in s.
"""
n = len(s)
if n == 0:
return ""
# Initialize the table to store palindrome st... | from solution import check_palindrome_and_longest_substring
def test_palindrome_string():
assert check_palindrome_and_longest_substring("racecar") == ("YES", "racecar")
def test_non_palindrome_string():
assert check_palindrome_and_longest_substring("banana") == ("NO", "anana")
def test_mixed_case():
asse... | [
{
"docstring": "Checks if the entire string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Finds the longest palindromic substring in s.",
"function_declaration": "def longest_palindromic_... | [
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_palindrome(s):\n \"\"\"\n Returns 'YES' if the string s is a palindrome, otherwise returns 'NO'.\n \"\"\"\n return \"YES\" if s == s[::-... | trial_gpt4o_1 | {
"original_instruction": "Create a program that checks if a given string is a valid palindrome and then determines the longest palindromic substring within that string.\n\nInput\n\nA single string consisting of lowercase letters.\n\nOutput\n\nFirst, output \"YES\" if the entire input string is a palindrome, otherwis... | 0.708818 | Code_Contests_14480 | C | [
"is_palindrome",
"longest_palindromic_substring",
"check_palindrome_and_longest_substring"
] | 3 | [
[
"check_palindrome_and_longest_substring",
"is_palindrome"
],
[
"check_palindrome_and_longest_substring",
"longest_palindromic_substring"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e0b79b43dee30f34da34e1eb4ac3eb62a7a82885 | 74e96c86ce9140c7c6b950c81758ba920b18fbd8 | |||
v1.0 | complete | Code_Contests | Code_Contests_15439_C | def graph_diameter(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
""" Given an undirected graph with n nodes and m edges, determine the maximum distance between any two nodes in the graph, also known as the diameter of the graph. If the graph is not connected, return -1.
>>> graph_diameter(5, 4, [(1, 2... | from collections import deque
def bfs_max_distance(graph, start_node, n):
distances = [-1] * n
queue = deque([(start_node, 0)])
distances[start_node] = 0
max_distance = 0
while queue:
node, distance = queue.popleft()
for neighbor in graph[node]:
if distances[neighbo... | from solution import graph_diameter
def test_graph_diameter_example_1():
n = 5
m = 4
edges = [(1, 2), (1, 3), (3, 4), (4, 5)]
assert graph_diameter(n, m, edges) == 4
def test_graph_diameter_example_2():
n = 4
m = 3
edges = [(1, 2), (2, 3), (2, 4)]
assert graph_diameter(n, m, edges) == ... | [
{
"docstring": null,
"function_declaration": "def bfs_max_distance(graph, start_node, n):",
"function_name": "bfs_max_distance",
"parameter_list": "(graph, start_node, n)"
},
{
"docstring": null,
"function_declaration": "def graph_diameter(n, m, edges):",
"function_name": "graph_diam... | [
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 bfs(farthest, graph, n):\n visited = [-1] * (n + 1)\n max_distance = 0\n queue = deque([(farthest, 0)])\n ... | trial_gpt4o_2 | {
"original_instruction": "Given an undirected graph with `n` nodes and `m` edges, you are to determine the maximum distance between any two nodes in the graph, also known as the diameter of the graph. If the graph is not connected, return `-1`.\n\nInput\n\nThe first line contains two integers `n` and `m` (1 ≤ n ≤ 10... | 0.674302 | Code_Contests_15439 | C | [
"bfs_max_distance",
"graph_diameter"
] | 2 | [
[
"graph_diameter",
"bfs_max_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 598c6db9b1a72a7cf82d8228200765b57820a9ad | 5a009a3506c9895fed12a7c0eaccaf525208f6a9 | |||
v1.0 | complete | Code_Contests | Code_Contests_14206_C | def is_palindrome(word: str) -> str:
"""
Check if a given word is a palindrome, ignoring case.
Returns "YES" if word is a palindrome, otherwise "NO".
"""
def process_words(words: List[str]) -> List[str]:
"""
Process a list of words to determine if each is a palindrome.
Returns a list of... | def is_palindrome(word):
"""
Check if a given word is a palindrome, ignoring case.
Returns "YES" if word is a palindrome, otherwise "NO".
"""
word = word.lower()
if word == word[::-1]:
return "YES"
else:
return "NO"
def process_words(words):
"""
Process a list of wor... | from solution import is_palindrome, process_words
def test_is_palindrome():
assert is_palindrome("Madam") == "YES"
assert is_palindrome("Hello") == "NO"
assert is_palindrome("Racecar") == "YES"
assert is_palindrome("World") == "NO"
assert is_palindrome("a") == "YES"
assert is_palindrome("Aa") =... | [
{
"docstring": "Check if a given word is a palindrome, ignoring case.\nReturns \"YES\" if word is a palindrome, otherwise \"NO\".",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Process a list of words to d... | [
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(word):\n \"\"\"\n Determines if a word is a palindrome. A word is considered a palindrome \n if it reads the same backward as fo... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with processing a list of words. For each word in the list, you need to determine if it is a palindrome. A word is considered a palindrome if it reads the same backward as forward (ignoring case). You should return the results for all words in the list.\n\nA palindrome is a w... | 0.67965 | Code_Contests_14206 | C | [
"is_palindrome",
"process_words"
] | 2 | [
[
"process_words",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 99a41344f8bc129c637d93b2babc82f4a33c18a1 | b0b89fe4ffcf5ea6c78a44ac487c7933c74a928b | |||
v1.0 | complete | Code_Contests | Code_Contests_16179_C | def num_ways_to_traverse(n: int, m: int, grid: List[str]) -> int:
""" Determine the number of ways to traverse from the top-left corner of the grid to the bottom-right corner.
You are given a grid with n rows and m columns. Each cell in the grid can either be empty or occupied by an obstacle.
You can o... | def num_ways_to_traverse(n, m, grid):
MOD = 1000000007
dp = [[0]*m for _ in range(n)]
if grid[0][0] == '#':
return 0
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '#':
dp[i][j] = 0
else:
if i... | def test_example_1():
input_str = "2 3\n...\n.#."
expected_output = 1
assert grid_ways_from_input(input_str) == expected_output
def test_example_2():
input_str = "3 3\n...\n.#.\n..."
expected_output = 2
assert grid_ways_from_input(input_str) == expected_output
def test_blocked_start():
inp... | [
{
"docstring": null,
"function_declaration": "def num_ways_to_traverse(n, m, grid):",
"function_name": "num_ways_to_traverse",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def grid_ways_from_input(input_str):",
"function_name": "grid_ways_from_inp... | [
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": "MOD = 1_000_000_007\n\ndef count_paths(n, m, grid):\n # Initialize the dp table with zeros\n dp = [[0] * m for _ in range(n)]\n \n # If the sta... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid with n rows and m columns. Each cell in the grid can either be empty or occupied by an obstacle. You are asked to determine the number of ways to traverse from the top-left corner of the grid to the bottom-right corner, moving only right or down at each step, while avoi... | 0.757434 | Code_Contests_16179 | C | [
"num_ways_to_traverse",
"grid_ways_from_input"
] | 2 | [
[
"grid_ways_from_input",
"num_ways_to_traverse"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2f91cc7c8e183884597bc67a2fe45563a828bf1c | d3eec35f58151d356c899813948ba3b9c0965046 | |||
v1.0 | complete | Code_Contests | Code_Contests_14327_C | def find_auction_winner(n, bids, t):
"""
Returns the winner's name in the auction or "No bids" if no valid bids exist.
Args:
n (int): Number of bids
bids (List[Tuple[str, int, int]]): List of tuples containing bidder's name, bid time, and bid amount
t (int): Auction end time
Return... | def find_auction_winner(n, bids, t):
"""
Returns the winner's name in the auction or "No bids" if no valid bids exist.
"""
valid_bids = [bid for bid in bids if bid[1] <= t]
if not valid_bids:
return "No bids"
valid_bids.sort(key=lambda x: (-x[2], x[1]))
return valid_bi... | def test_auction():
input_data1 = "5\nalice 100 150\nbob 200 200\ncarol 300 150\nalice 250 200\nbob 150 200\n250"
assert auction(input_data1) == "bob"
input_data2 = "2\nalice 50 100\nbob 60 100\n30"
assert auction(input_data2) == "No bids"
input_data3 = "3\nalice 100 150\nbob 200 200\ncarol 300 15... | [
{
"docstring": "Returns the winner's name in the auction or \"No bids\" if no valid bids exist.",
"function_declaration": "def find_auction_winner(n, bids, t):",
"function_name": "find_auction_winner",
"parameter_list": "(n, bids, t)"
},
{
"docstring": null,
"function_declaration": "def ... | [
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 determine_winner(bids, end_time):\n \"\"\"\n Determines the winner of the auction based on the highest bid amount and \n earliest bid time in ... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with designing a program to simulate an online auction. In an online auction, bidders can place bids on items within a certain timeframe. Each bid consists of the bidder's name and the bid amount. At the end of the auction, the highest bid wins the item. If there are multiple... | 0.544523 | Code_Contests_14327 | C | [
"find_auction_winner",
"auction"
] | 2 | [
[
"auction",
"find_auction_winner"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b02f9ed4a9112e40b4cd80c4e3c192b494802373 | 232bc2cefb2d87a8d89ddf7000d03bdab38d4ae7 | |||
v1.0 | complete | Code_Contests | Code_Contests_14454_C | def factorial(n):
"""Returns the factorial of n.
>>> factorial(1)
1
>>> factorial(2)
2
>>> factorial(3)
6
>>> factorial(4)
24
"""
pass
def sum_of_factorials(N):
"""Returns the sum of factorials from 1 to N.
>>> sum_of_factorials(1)
1
>>> sum_of_factorials(3)
... | def factorial(n):
"""
Returns the factorial of n.
"""
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
def sum_of_factorials(N):
"""
Returns the sum of factorials from 1 to N.
"""
return sum(factorial(i) for i in range(1, N + 1)) | from solution import factorial, sum_of_factorials
def test_factorial():
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120
assert factorial(6) == 720
def test_sum_of_factorials():
assert sum_of_factorials(1) == 1
... | [
{
"docstring": "Returns the factorial of n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of factorials from 1 to N.",
"function_declaration": "def sum_of_factorials(N):",
"function_name": "sum_... | [
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 sum_of_factorials(N):\n \"\"\"\n Returns the sum of factorials from 1 to N.\n \n Parameters:\n N (int): An integer up to ... | trial_gpt4o_2 | {
"original_instruction": "Calculate the sum of factorials from 1 to N.\n\nConstraints\n\n* 1 ≤ N ≤ 10\n* All values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\n\nN\n\n\nOutput\n\nPrint the sum of factorials from 1 to N.\n\nExamples\n\nInput\n\n3\n\n\nOutput\n\n9\... | 0.684908 | Code_Contests_14454 | C | [
"factorial",
"sum_of_factorials"
] | 2 | [
[
"sum_of_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af7a71a602c3881c85a27a1e811680b586781b14 | d9deaf8f142e656f31b0b52bbc8f2af243b62ec7 | |||
v1.0 | complete | Code_Contests | Code_Contests_20742_C | from typing import List
def min_energy_path(grid: List[List[int]]) -> int:
"""Find the minimum energy required for the robot to reach the bottom-right corner of the grid from the top-left corner.
>>> min_energy_path([[1, 3, 2], [4, 3, 8], [5, 3, 1]])
4
>>> min_energy_path([[1, 2], [3, 4]])
3
>>... | def min_energy_path(grid):
import heapq
if not grid or not grid[0]:
return 0
n = len(grid)
directions = [(0, 1), (1, 0)] # Only right and down movements
heap = [(0, 0, 0)] # (energy, x, y)
visited = set((0, 0))
energy_matrix = [[float('inf')] * n for _ in range(n)]
en... | from solution import min_energy_path
def test_min_energy_path_1():
grid = [
[1, 3, 2],
[4, 3, 8],
[5, 3, 1]
]
assert min_energy_path(grid) == 4
def test_min_energy_path_2():
grid = [
[1, 2],
[3, 4]
]
assert min_energy_path(grid) == 3
def test_min_energy... | [
{
"docstring": null,
"function_declaration": "def min_energy_path(grid):",
"function_name": "min_energy_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_compute_min_energy():",
"function_name": "read_input_and_compute_min_energy",
... | [
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_energy(n, elevation):\n \"\"\"\n Finds the minimum energy required for the robot to traverse from the top-left corner\n to the bottom-righ... | trial_gpt4o_2 | {
"original_instruction": "A city grid consists of n x n intersections. At each intersection, there is a building with a certain height given in a matrix of integers where the elevation matrix[i][j] represents the height of the building at the i-th row and j-th column.\n\nA robot starts at the top-left corner of the ... | 0.627622 | Code_Contests_20742 | C | [
"min_energy_path",
"read_input_and_compute_min_energy"
] | 2 | [
[
"read_input_and_compute_min_energy",
"min_energy_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5dfda222e79d27dc609ecfd82bc26bda2ca02eaa | d6bb7574586c2d16ab6713859413d191073240ea | |||
v1.0 | complete | Code_Contests | Code_Contests_20684_C | def is_prime(num: int) -> bool:
""" Returns True if num is a prime number, otherwise False.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
"""
def largest_prime_in_sequence(n: int, sequence: List[int]) -> int:
""" Returns the largest pri... | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
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:
... | from solution import is_prime, largest_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(1) == False
assert is_prime(0) == False
assert is_prime(17) == True
assert is_prime(... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the largest prime number in the given sequence.\nIf there are no prime numbers, returns -1... | [
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(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n... | trial_gpt4o_2 | {
"original_instruction": "Alice has recently got interested in mathematics, especially prime numbers. She was given a sequence of integers and was asked to find the largest prime number in the sequence. However, Alice is a beginner and needs your help to solve this problem.\n\nInput\n\nThe first line contains an int... | 0.73399 | Code_Contests_20684 | C | [
"is_prime",
"largest_prime_in_sequence"
] | 2 | [
[
"largest_prime_in_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0efe97ee9a7cac385a4f2a4842e9fbad75701cb8 | ef66cb091d464b728ca47d5906a72d97db7f7535 | |||
v1.0 | complete | Code_Contests | Code_Contests_16025_C | from typing import List
def find_max_sum_rectangle(n: int, m: int, grid: List[List[int]]) -> int:
"""
Finds the maximum sum of any rectangle within the grid.
:param n: Number of rows in the grid
:param m: Number of columns in the grid
:param grid: 2D list representing the grid
:return: Maximum... | def find_max_sum_rectangle(n, m, grid):
"""
Finds the maximum sum of any rectangle within the grid.
:param n: Number of rows in the grid
:param m: Number of columns in the grid
:param grid: 2D list representing the grid
:return: Maximum sum of any rectangle in the grid
"""
max_sum = flo... | from solution import find_max_sum_rectangle
def test_case_1():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert find_max_sum_rectangle(3, 3, grid) == 45
def test_case_2():
grid = [
[1, 2, 3],
[4, 5, 6]
]
assert find_max_sum_rectangle(2, 3, grid) == 21
... | [
{
"docstring": "Finds the maximum sum of any rectangle within the grid.\n\n:param n: Number of rows in the grid\n:param m: Number of columns in the grid\n:param grid: 2D list representing the grid\n:return: Maximum sum of any rectangle in the grid",
"function_declaration": "def find_max_sum_rectangle(n, m, ... | [
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 max_sum_subrectangle(grid):\n \"\"\"\n Finds the maximum possible sum of any subrectangle within the given grid.\n \"\"\"\n def max_subarra... | trial_gpt4o_3 | {
"original_instruction": "You are given a grid of size n x m filled with non-negative integers. You need to find a rectangle within this grid such that the sum of the elements of the rectangle is as large as possible. The rectangle can be of any size, but must have at least one element.\n\nInput\n\nThe first line co... | 0.734459 | Code_Contests_16025 | C | [
"find_max_sum_rectangle",
"kadane_algorithm"
] | 2 | [
[
"find_max_sum_rectangle",
"kadane_algorithm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c26a3f7327494cb4b8900c01d607bdea1152298d | dc9f07f8e8bfc49350d7b0bef654dedaa4426911 | |||
v1.0 | complete | Code_Contests | Code_Contests_21476_C | def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
>>> is_prime(2) # True
>>> is_prime(4) # False
>>> is_prime(17) # True
"""
def longest_prime_subsequence_length(arr: List[int]) -> int:
"""
Given an array, returns the length of the longest prime subsequenc... | def is_prime(n):
"""
Helper function to check if a number 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 % (i + 2) == 0:
return False
i +... | from solution import longest_prime_subsequence_length
def test_prime_subsequence():
assert longest_prime_subsequence_length([10, 3, 7, 8, 5, 2]) == 4
assert longest_prime_subsequence_length([1, 4, 6, 8, 10]) == 0
assert longest_prime_subsequence_length([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 10
assert... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given an array, returns the length of the longest prime subsequence.",
"function_declaration": "def longest... | [
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(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_1 | {
"original_instruction": "Riya loves to play with arrays and prime numbers. She defines a \"prime subsequence\" as a subsequence of an array where all the elements are prime numbers. Given an integer array of size N, Riya wants to know the length of the longest prime subsequence within the array. A subsequence is de... | 0.749115 | Code_Contests_21476 | C | [
"is_prime",
"longest_prime_subsequence_length"
] | 2 | [
[
"longest_prime_subsequence_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1874a84517bb608db9b9a962b7de884795f5ee1f | 0e3c4df419be3c98eb42258f56ea61de23b0bf31 | |||
v1.0 | complete | Code_Contests | Code_Contests_15028_C | def find_parent(parents, city):
if parents[city] == city:
return city
parents[city] = find_parent(parents, parents[city])
return parents[city]
def union(parents, rank, u, v):
rootU = find_parent(parents, u)
rootV = find_parent(parents, v)
if rootU != rootV:
if rank[rootU] >... | def find_parent(parents, city):
if parents[city] == city:
return city
parents[city] = find_parent(parents, parents[city])
return parents[city]
def union(parents, rank, u, v):
rootU = find_parent(parents, u)
rootV = find_parent(parents, v)
if rootU != rootV:
if rank[rootU] >... | from solution import additional_roads_needed
def test_sample():
assert additional_roads_needed(4, 2, [(1, 2), (2, 3)]) == 1
def test_single_city():
assert additional_roads_needed(1, 0, []) == 0
def test_fully_connected():
assert additional_roads_needed(3, 3, [(1, 2), (2, 3), (3, 1)]) == 0
def test_disco... | [
{
"docstring": null,
"function_declaration": "def find_parent(parents, city):",
"function_name": "find_parent",
"parameter_list": "(parents, city)"
},
{
"docstring": null,
"function_declaration": "def union(parents, rank, u, v):",
"function_name": "union",
"parameter_list": "(par... | [
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_parent(parents, city):\n if parents[city] == city:\n return city\n parents[city] = find_parent(parents, parents[city])\n return pa... | trial_gpt4o_0 | {
"original_instruction": "In a faraway land, there's a kingdom with N cities connected by M bidirectional roads. The kingdom is currently at peace and wants to maintain a minimum level of connectivity between its cities. The king has decided that at least one path should exist between any pair of cities. It's your t... | 0.679588 | Code_Contests_15028 | C | [
"find_parent",
"union",
"additional_roads_needed"
] | 3 | [
[
"additional_roads_needed",
"find_parent"
],
[
"additional_roads_needed",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 025aea8f5a31d3a6a93ba7dd466a70c9d2a47058 | f9b7d981cf3a811992206c857a18d3ed1e4330c3 | |||
v1.0 | complete | Code_Contests | Code_Contests_15238_C | def minimum_cost_road_network(t: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]]]]) -> List[Union[int, str]]:
""" Given the number of test cases, and for each test case the number of cities and roads,
finds the minimum cost to connect all the cities or determine if it is impossible.
>>... | from heapq import heappop, heappush
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_x] = root_y
elif r... | def test_minimum_cost_road_network():
t = 2
test_cases = [
(4, 2, [(1, 2, 3), (3, 4, 4)]),
(3, 3, [(1, 2, 1), (2, 3, 2), (3, 1, 4)])
]
expected = ["Impossible", 3]
assert minimum_cost_road_network(t, test_cases) == expected
def test_no_existing_roads():
t = 1
test_cases = [
... | [
{
"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,
1
] | 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 find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n r... | trial_gpt4o_2 | {
"original_instruction": "Dušan has also developed a fascination with road networks, modeled as graphs where vertices represent cities and edges represent roads between them. He wants to improve the road network by adding new roads to minimize travel time between cities. Each road has a specific travel time, represe... | 0.726261 | Code_Contests_15238 | C | [
"find",
"union",
"kruskal",
"minimum_cost_road_network"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_road_network",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | b758f029872c631fa7066875d775e119769386ff | 2d825189d512433aac577e9322a045f5cabd7f4c | |||
v1.0 | complete | Code_Contests | Code_Contests_16490_C | def polygon_area(n: int, vertices: List[Tuple[int, int]]) -> float:
"""
Calculate the area of an n-sided polygon using the shoelace formula.
Args:
n (int): The number of vertices of the polygon.
vertices (List[Tuple[int, int]]): The coordinates of the vertices in counter-clockwise order.
R... | def polygon_area(n, vertices):
"""
Calculate the area of an n-sided polygon using the shoelace formula.
Args:
n (int): The number of vertices of the polygon.
vertices (List[Tuple[int, int]]): The coordinates of the vertices in counter-clockwise order.
Returns:
float: The area of the po... | import pytest
from solution import polygon_area, string_to_polygon_area
def test_polygon_area():
assert polygon_area(4, [(0, 0), (4, 0), (4, 3), (0, 3)]) == 12.000000
assert polygon_area(3, [(1, 1), (2, 3), (3, 1)]) == 2.000000
def test_polygon_area_large_coordinates():
assert polygon_area(4, [(1000000, 1... | [
{
"docstring": "Calculate the area of an n-sided polygon using the shoelace formula.\n\nArgs:\nn (int): The number of vertices of the polygon.\nvertices (List[Tuple[int, int]]): The coordinates of the vertices in counter-clockwise order.\n\nReturns:\nfloat: The area of the polygon rounded to six decimal places.... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def polygon_area(n, coordinates):\n \"\"\"\n Calculate the area of a polygon using the shoelace formula.\n \n Arguments:\n n : int : Number ... | trial_gpt4o_7 | {
"original_instruction": "An n-sided polygon can be defined by its vertices, each represented in a two-dimensional plane by coordinates (x, y). A vertex belongs to the polygon if it is connected by an edge, i.e., a straight line, to two other vertices. The polygon is said to be simple if its edges do not intersect e... | 0.640758 | Code_Contests_16490 | C | [
"polygon_area",
"string_to_polygon_area"
] | 2 | [
[
"string_to_polygon_area",
"polygon_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 88e665bf61e6f3713bc571ab6058e01e4c2e292f | fd0c6412cf39e2b54eba4a3475551035e00b0c76 | |||
v1.0 | complete | Code_Contests | Code_Contests_20789_C | def isValid(sequence: str) -> str:
"""
Returns 'Valid' if the bracket sequence is valid, otherwise 'Invalid'.
>>> isValid("()") "Valid"
>>> isValid("()[]{}") "Valid"
>>> isValid("({[]})") "Valid"
>>> isValid("(]") "Invalid"
>>> isValid("([)]") "Invalid"
>>> isValid("{[()]}") "Valid"
... | def isValid(sequence):
"""
Returns 'Valid' if the bracket sequence is valid, otherwise 'Invalid'.
"""
stack = []
close_map = {')': '(', '}': '{', ']': '['}
for char in sequence:
if char in close_map.values():
stack.append(char)
elif char in close_map.keys():
... | from solution import isValid, validate_sequences
def test_isValid():
assert isValid("()") == "Valid"
assert isValid("()[]{}") == "Valid"
assert isValid("({[]})") == "Valid"
assert isValid("(]") == "Invalid"
assert isValid("([)]") == "Invalid"
assert isValid("") == "Valid"
assert isValid("((... | [
{
"docstring": "Returns 'Valid' if the bracket sequence is valid, otherwise 'Invalid'.",
"function_declaration": "def isValid(sequence):",
"function_name": "isValid",
"parameter_list": "(sequence)"
},
{
"docstring": "Takes a list of bracket sequences and returns a list with \"Valid\" or \"In... | [
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 isValid(sequence):\n \"\"\"\n Returns 'Valid' if the bracket sequence is valid, otherwise 'Invalid'.\n \"\"\"\n stack = []\n close_map =... | trial_gpt4o_0 | {
"original_instruction": "You are given a sequence of brackets. Your task is to determine whether the sequence is valid. A valid sequence of brackets is one where every opening bracket has a corresponding closing bracket and the brackets are properly nested.\n\nThe following constraints apply:\n- The brackets are li... | 0.710065 | Code_Contests_20789 | C | [
"isValid",
"validate_sequences"
] | 2 | [
[
"validate_sequences",
"isValid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 33f85a688e88c766d266825016a51f064792e276 | eae04c7bf459a6850c45a2d216bbca69e29dac12 | |||
v1.0 | complete | Code_Contests | Code_Contests_15254_C | def are_anagrams(word1: str, word2: str) -> bool:
"""
Helper function to check if two words are anagrams.
>>> are_anagrams("listen", "silent") True
>>> are_anagrams("evil", "vile") True
>>> are_anagrams("apple", "pale") False
"""
pass
def check_anagrams(T: int, test_cases: List[Tuple[str, i... | def are_anagrams(word1, word2):
"""
Helper function to check if two words are anagrams.
"""
return sorted(word1) == sorted(word2)
def check_anagrams(T, test_cases):
results = []
for i in range(T):
W = test_cases[i][0]
N = test_cases[i][1]
words_collection = test_cases[i]... | from solution import are_anagrams, check_anagrams
def test_are_anagrams():
assert are_anagrams("listen", "silent") == True
assert are_anagrams("evil", "vile") == True
assert are_anagrams("apple", "pale") == False
def test_check_anagrams():
assert check_anagrams(2, [
("listen", 3, ["enlist", "s... | [
{
"docstring": "Helper function to check if two words are anagrams.",
"function_declaration": "def are_anagrams(word1, word2):",
"function_name": "are_anagrams",
"parameter_list": "(word1, word2)"
},
{
"docstring": null,
"function_declaration": "def check_anagrams(T, test_cases):",
"... | [
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_anagram(word1, word2):\n \"\"\"\n Check if word1 is an anagram of word2.\n \"\"\"\n return sorted(word1) == sorted(word2)\n\ndef check_a... | trial_gpt4o_1 | {
"original_instruction": "Anna is a fan of word games and loves rearranging letters of words to form meaningful anagrams. She has a collection of words and she wants to determine if one particular word can be rearranged to form another word in her collection.\n\nYour task is to write a program that checks if one wor... | 0.627392 | Code_Contests_15254 | C | [
"are_anagrams",
"check_anagrams"
] | 2 | [
[
"check_anagrams",
"are_anagrams"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b2782f861318abfc2209b2d7951eaa4b51f5858b | d3568905a965fd9fc5d6646303901d6987d84ebd | |||
v1.0 | complete | Code_Contests | Code_Contests_20845_C | def minimum_travel_cost(n: int, m: int, happiness: List[int], roads: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum travel cost for the traveler to visit all the cities exactly once.
Args:
n (int): Number of cities.
m (int): Number of roads.
happiness (List[int]): A list of happi... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return 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_x] = root_y
elif rank[roo... | def test_minimum_travel_cost_given_example1():
n, m = 3, 3
happiness = [5, 10, 15]
roads = [
(1, 2, 3),
(2, 3, 4),
(1, 3, 2)
]
assert minimum_travel_cost(n, m, happiness, roads) == 5
def test_minimum_travel_cost_given_example2():
n, m = 4, 4
happiness = [8, 2, 3, 5]
... | [
{
"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,
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 heapq\n\ndef minimum_travel_cost(n, m, happiness, roads):\n # Initialize graph as adjacency list\n graph = [[] for _ in range(n)]\n for u, ... | trial_gpt4o_3 | {
"original_instruction": "In a magical kingdom, there are n cities connected by m bidirectional roads such that there is a unique path between any two cities. A traveler wants to visit all the cities starting from city 1. Each city i has a certain level of happiness h_i that the traveler gains when visiting it for t... | 0.722128 | Code_Contests_20845 | C | [
"find",
"union",
"kruskal",
"minimum_travel_cost"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_travel_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | c3fb1c5f1a711ea172f4ba204c856499744a0e5b | 5a5953cb99a4c5214784112332eb0bf81140d315 | |||
v1.0 | complete | Code_Contests | Code_Contests_15299_C | def is_prime(n: int) -> bool:
"""
Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(5) True
"""
pass
def longest_prime_subsequence_sum(sequence: List[int]) -> int:
"""
Returns the sum of the longest contiguous subsequence co... | import math
def is_prime(n):
"""
Check if a number 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 % (i + 2) == 0:
return False
i += 6
... | import pytest
from solution import longest_prime_subsequence_sum
def test_longest_prime_subsequence_sum():
assert longest_prime_subsequence_sum([6, 2, 3, 4, 5, 7, 11, 13]) == 36
assert longest_prime_subsequence_sum([1, 4, 6, 8, 10, 12]) == 0
assert longest_prime_subsequence_sum([2, 3, 5, 6, 7, 11, 13, 17, ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the longest contiguous subsequence consisting solely of prime numbers.",
"function_declaration": "def longe... | [
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 if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n retu... | trial_gpt4o_1 | {
"original_instruction": "A: Prime Subsequence Sum\n\nproblem\n\nDr. Prime, an esteemed mathematician, is exploring interesting properties of prime numbers within sequences. One of his recent studies involves identifying and analyzing subsequences of prime numbers within a given sequence of integers. Specifically, h... | 0.676275 | Code_Contests_15299 | C | [
"is_prime",
"longest_prime_subsequence_sum",
"main"
] | 3 | [
[
"longest_prime_subsequence_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 929f6977fb66a4732da1959dbc0d213f89210b93 | fbb5c6ffb1cddc0c029edd0db45b5596350ea959 | |||
v1.0 | complete | Code_Contests | Code_Contests_15741_C | from typing import List
def rank_poker_hand(hand: List[str]) -> str:
""" Evaluates a poker hand and returns its rank.
>>> rank_poker_hand('A♠ K♠ Q♠ J♠ T♠'.split()) == 'Straight Flush'
>>> rank_poker_hand('9♦ 9♣ 9♥ 9♠ 3♦'.split()) == 'Four of a Kind'
>>> rank_poker_hand('3♣ 3♦ 3♠ 6♣ 6♦'.split()) == 'Ful... | from collections import Counter
def rank_poker_hand(hand):
ranks_dict = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'T': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14}
def is_flush(hand):
suits = [card[-1] for card in hand]
return len(set(suits)) == 1
def i... | def test_rank_poker_hand():
assert rank_poker_hand('A♠ K♠ Q♠ J♠ T♠'.split()) == 'Straight Flush'
assert rank_poker_hand('9♦ 9♣ 9♥ 9♠ 3♦'.split()) == 'Four of a Kind'
assert rank_poker_hand('3♣ 3♦ 3♠ 6♣ 6♦'.split()) == 'Full House'
assert rank_poker_hand('2♥ 4♥ 6♥ 8♥ T♥'.split()) == 'Flush'
assert ra... | [
{
"docstring": null,
"function_declaration": "def rank_poker_hand(hand):",
"function_name": "rank_poker_hand",
"parameter_list": "(hand)"
},
{
"docstring": null,
"function_declaration": "def rank_all_hands(hands):",
"function_name": "rank_all_hands",
"parameter_list": "(hands)"
... | [
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": "import itertools\n\n# Helper function to determine rank and suit of a card\ndef get_rank(card):\n return card[0]\n\ndef get_suit(card):\n return card... | trial_gpt4o_2 | {
"original_instruction": "Create a poker hand evaluator that determines the type of poker hand value from given card hands. In poker, certain hand values are ranked higher than others. Here, you need to classify the poker hands into categorized rank.\n\nCards are represented in the following format:\nA♠, A♥, K♦, etc... | 0.744093 | Code_Contests_15741 | C | [
"rank_poker_hand",
"rank_all_hands"
] | 2 | [
[
"rank_all_hands",
"rank_poker_hand"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | edf41a225153d75a3865039dfddf79cde9820f94 | 4ca5b6c4d2633ab33bc2685a117d02476de7fe71 | |||
v1.0 | complete | Code_Contests | Code_Contests_15108_C | def min_circles_to_cover(N: int, points: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of circular roads required to cover all cities in the kingdom.
Each city is represented as a point in a 2D plane given by its coordinates (x_i, y_i).
Args:
N (int): The number of cities.
poi... | import math
def distance(p1, p2):
return math.hypot(p2[0] - p1[0], p2[1] - p1[1])
def is_collinear(points):
if len(points) < 3:
return True
(x1, y1), (x2, y2), (x3, y3) = points[:3]
return (y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1)
def min_circles_to_cover(N, points):
# If there are o... | from solution import min_circles_to_cover
def test_single_point():
assert min_circles_to_cover(1, [(1, 1)]) == 1
def test_two_points():
assert min_circles_to_cover(2, [(1, 1), (2, 2)]) == 1
def test_collinear_points():
assert min_circles_to_cover(3, [(1, 1), (2, 2), (3, 3)]) == 1
def test_non_collinear_... | [
{
"docstring": null,
"function_declaration": "def distance(p1, p2):",
"function_name": "distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def is_collinear(points):",
"function_name": "is_collinear",
"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": "import math\n\ndef distance(p1, p2):\n return math.hypot(p2[0] - p1[0], p2[1] - p1[1])\n\ndef is_collinear(points):\n if len(points) < 3:\n re... | trial_gpt4o_0 | {
"original_instruction": "In a faraway land, there is a kingdom where they love circles. The kingdom has exactly N cities, each uniquely represented as a point in a 2D plane. The King of this land decides to connect his cities using the minimum number of circular roads. Each circular road can cover any set of cities... | 0.586953 | Code_Contests_15108 | C | [
"distance",
"is_collinear",
"min_circles_to_cover"
] | 3 | [
[
"min_circles_to_cover",
"is_collinear"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 670c741a381ac938abe1a33f4e9948875335db2e | c3d6ae38a3a6aa6e67b3de69097978b11b6b0fb3 | |||
v1.0 | complete | Code_Contests | Code_Contests_20813_C | [Completion Task in Python]
def is_subsequence(s: str, t: str) -> bool:
"""
Determines if s is a subsequence of t.
>>> is_subsequence("abc", "ahbgdc")
True
>>> is_subsequence("axc", "ahbgdc")
False
"""
def check_subsequences(test_cases: List[Tuple[str, str]]) -> List[str]:
"""
For ... | def is_subsequence(s, t):
"""
Determines if s is a subsequence of t.
"""
it = iter(t)
return all(char in it for char in s)
def check_subsequences(test_cases):
"""
For each test case, determines if the first string is a subsequence of the second.
"""
results = []
for s, t in test... | from solution import is_subsequence, check_subsequences, main, read_test_cases
def test_is_subsequence():
assert is_subsequence("abc", "ahbgdc") == True
assert is_subsequence("axc", "ahbgdc") == False
assert is_subsequence("ace", "abcde") == True
assert is_subsequence("aec", "abcde") == False
def test... | [
{
"docstring": "Determines if s is a subsequence of t.",
"function_declaration": "def is_subsequence(s, t):",
"function_name": "is_subsequence",
"parameter_list": "(s, t)"
},
{
"docstring": "For each test case, determines if the first string is a subsequence of the second.",
"function_de... | [
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_subsequence(s, t):\n \"\"\"\n Check if string s is a subsequence of string t.\n \"\"\"\n it = iter(t)\n return all(char in it for cha... | trial_gpt4o_2 | {
"original_instruction": "In a distant galaxy, there is a species of creatures known as Terbongers, who communicate using sequences of colors. Each creature has a communication device that can emit sequences of colors represented by strings of lowercase letters where each letter corresponds to a specific color. The ... | 0.645804 | Code_Contests_20813 | C | [
"is_subsequence",
"check_subsequences",
"read_test_cases",
"main"
] | 4 | [
[
"check_subsequences",
"is_subsequence"
]
] | 1 | [
"read_test_cases"
] | false | [] | false | pytest | true | [] | true | ff6a76e97aed641af36de0179450ac331166e542 | 7f9cdc09c8e2e3d2bdba79c5bbd590a4f0dd0bbb | |||
v1.0 | complete | Code_Contests | Code_Contests_16111_C | def find_ancestors(tree, individual):
"""
Given a tree (dictionary) where keys are children and values are parents,
this function returns a set of ancestors for the given individual.
"""
ancestors = set()
while individual in tree:
individual = tree[individual]
ancestors.add(indiv... | def find_ancestors(tree, individual):
ancestors = set()
while individual in tree:
individual = tree[individual]
ancestors.add(individual)
return ancestors
def find_cca(tree, individual1, individual2):
ancestors1 = find_ancestors(tree, individual1)
ancestors2 = find_ancestors(tree, i... | def test_find_ancestors():
tree = {'Bob': 'Adam', 'Charlie': 'Adam', 'David': 'Bob', 'Ellen': 'Bob',
'Frank': 'Charlie', 'Grace': 'Charlie', 'Henry': 'Ellen', 'Isaac': 'Ellen'}
assert find_ancestors(tree, 'David') == {'Bob', 'Adam'}
assert find_ancestors(tree, 'Henry') == {'Ellen', 'Bob', 'Adam... | [
{
"docstring": null,
"function_declaration": "def find_ancestors(tree, individual):",
"function_name": "find_ancestors",
"parameter_list": "(tree, individual)"
},
{
"docstring": null,
"function_declaration": "def find_cca(tree, individual1, individual2):",
"function_name": "find_cca"... | [
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 find_closest_common_ancestor(n, relationships, person1, person2):\n from collections import defaultdict, deque\n\n # Build the parent dictionary\... | trial_gpt4o_6 | {
"original_instruction": "A genealogist is tracing the lineage of a famous dynasty. As part of their research, they need to analyze the family tree to determine the closest common ancestor (CCA) of two given members. The family tree is represented as a series of parent-child relationships.\n\nYou are given the famil... | 0.519464 | Code_Contests_16111 | C | [
"find_ancestors",
"find_cca",
"closest_common_ancestor"
] | 3 | [
[
"closest_common_ancestor",
"find_cca"
],
[
"find_cca",
"find_ancestors"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 57617f06914f08334ed4be64e118e514f71960f3 | e17840c317957bf7f7d353be3c72cc3a0bfedda5 | |||
v1.0 | complete | Code_Contests | Code_Contests_21285_C | def min_prime_numbers_sum(N: int) -> int:
""" Find the minimum number of prime numbers whose sum equals a given number N.
>>> min_prime_numbers_sum(10)
2
>>> min_prime_numbers_sum(28)
2
>>> min_prime_numbers_sum(3)
1
"""
# Implement the function here
def test_min_prime_numbers_sum_1... | def is_prime(n):
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
i += 6
return True
def min_prime_numbers_sum(N):
if is_prime(... | def test_min_prime_numbers_sum_10():
assert min_prime_numbers_sum(10) == 2
def test_min_prime_numbers_sum_28():
assert min_prime_numbers_sum(28) == 2
def test_min_prime_numbers_sum_3():
assert min_prime_numbers_sum(3) == 1
def test_min_prime_numbers_sum_prime():
assert min_prime_numbers_sum(17) == 1
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def min_prime_numbers_sum(N):",
"function_name": "min_prime_numbers_sum",
"parameter_list": "(N)"
}
] | [
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 min_prime_sum(N):\n \"\"\"\n This function returns the minimum number of prime numbers whose sum equals N.\n \"\"\"\n if N == 2:\n r... | trial_gpt4o_1 | {
"original_instruction": "Jenny has recently started learning algorithms, and she is fascinated by prime numbers. As a challenge, she decides to write a program that finds the minimum number of prime numbers whose sum equals a given number N.\n\nA prime number is a natural number greater than 1 that has no positive ... | 0.655635 | Code_Contests_21285 | C | [
"is_prime",
"min_prime_numbers_sum"
] | 2 | [
[
"min_prime_numbers_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c993989cf36fa58c1064c7284e4df39f6b20c4cd | 7e7ed4b60d12c8c4bd32982fc1dd2993a4c8a80a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.