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_22248_C
from typing import List, Tuple, Union def is_prime(n: int) -> bool: """ Checks if `n` is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True >>> is_prime(18) False >>> is_prime(19) True >>> is_prime(1) False """ def find_twin_pr...
def is_prime(n): """ Checks if n is a prime number. """ if n <= 1: return False if n == 2: return True # as 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return...
from solution import is_prime, find_twin_primes, format_twin_primes 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 assert is_prime(1) == False def te...
[ { "docstring": "Checks if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds and returns all twin primes within the range [L, R].", "function_declaration": "def find_twin_primes(L, R):", "fu...
[ 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(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ...
trial_gpt4o_2
{ "original_instruction": "Arjun loves to play with numbers and is particularly fascinated by prime numbers. He recently learned about twin primes (pairs of prime numbers that differ by 2). He now wants to identify all the twin primes within a given range and needs your help.\n\nInput:\nThe first line contains two in...
0.665148
Code_Contests_22248
C
[ "is_prime", "find_twin_primes", "format_twin_primes" ]
3
[ [ "find_twin_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7fa66d376b68a4581b054454e175de209d2cf996
ae010c6cf3b2e71184dc5864546e6dcc71fcd39a
v1.0
complete
Code_Contests
Code_Contests_21346_C
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree_from_level_order(values): """ Build a binary tree from level-order traversal values. >>> build_tree_from_level_order([1, 2, 3, 4, 5]) TreeNod...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree_from_level_order(values): if not values: return None root = TreeNode(values[0]) queue = [root] index = 1 while index < len(va...
from solution import build_tree_from_level_order, deepest_leaves_sum, solve, main import pytest def test_single_node_tree(): tree = build_tree_from_level_order([10]) assert deepest_leaves_sum(tree) == 10 def test_tree_with_multiple_levels(): tree = build_tree_from_level_order([1, 2, 3, 4, 5]) assert d...
[]
[ 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\n...
trial_gpt4o_5
{ "original_instruction": "Liam is fascinated by binary trees and has embarked on a quest to find the \"deepest leaves.\" A leaf is a node with no children, and the deepest leaves are the ones farthest from the root. Liam wants to determine the sum of the values of these deepest leaves for a given binary tree. Can yo...
0.553694
Code_Contests_21346
C
[ "build_tree_from_level_order", "deepest_leaves_sum", "solve", "main" ]
4
[ [ "solve", "build_tree_from_level_order" ], [ "solve", "deepest_leaves_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
27944085bdf02d0a2642e768508aeed5619f21e5
710acb6a599e86bc00739761bb0797e068722bc9
v1.0
complete
Code_Contests
Code_Contests_22224_C
def process_logs_and_queries(log_entries, queries): """ Process log entries and queries to find the number of unique IP addresses within specified time intervals. >>> process_logs_and_queries( ... [ ... "10 192.168.1.1", ... "20 192.168.1.2", ... "30 192.168.1.3", ... "40 192...
def process_logs_and_queries(log_entries, queries): from collections import defaultdict import bisect # Parse log entries into a list of (timestamp, IP_address) tuples logs = [] for entry in log_entries: timestamp, ip = entry.split() logs.append((int(timestamp), ip)) # Dictiona...
def test_process_logs_and_queries_simple_case(): log_entries = [ "10 192.168.1.1", "20 192.168.1.2", "30 192.168.1.3", "40 192.168.1.1", "50 192.168.1.4" ] queries = [ "10 30", "20 50", "0 60" ] expected = [3, 3, 4] result = p...
[ { "docstring": null, "function_declaration": "def process_logs_and_queries(log_entries, queries):", "function_name": "process_logs_and_queries", "parameter_list": "(log_entries, queries)" }, { "docstring": null, "function_declaration": "def collect_input_and_process():", "function_na...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_unique_ips(logs, queries):\n \"\"\"\n Returns a list of the number of unique IP addresses for each query interval.\n \"\"\"\n from co...
trial_gpt4o_7
{ "original_instruction": "In a network security company, analyst Emily is in charge of monitoring the network for any unusual behavior. She needs to identify and report on the number of unique IP addresses accessing the network over a certain period.\n\nYou're tasked to create a program that helps Emily with her job...
0.640251
Code_Contests_22224
C
[ "process_logs_and_queries", "collect_input_and_process" ]
2
[ [ "collect_input_and_process", "process_logs_and_queries" ] ]
1
[]
false
[]
false
pytest
false
[]
true
67cb4aa907755a645c83b33d6e4d762bb348769f
994cf8b8809754383febf94efd18e49a35e75d3d
v1.0
complete
Code_Contests
Code_Contests_22763_C
from typing import List, Tuple def max_distance(N: int, edges: List[Tuple[int, int]], values: List[int]) -> int: """ Find the maximum distance between any two nodes in the tree. Args: N: int - the number of nodes in the tree edges: List[Tuple[int, int]] - the edges between nodes in the tree ...
from collections import deque, defaultdict def max_distance(N, edges, values): if N == 1: return 0 # Construct the tree as an adjacency list tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) # Function to perform BFS and return the far...
def test_max_distance_simple(): edges = [(1, 2), (1, 3)] values = [3, 1, 2] assert max_distance(3, edges, values) == 2 def test_max_distance_complex(): edges = [(1, 2), (1, 3), (2, 4), (2, 5)] values = [5, 1, 4, 2, 3] assert max_distance(5, edges, values) == 3 def test_max_distance_single_node...
[ { "docstring": null, "function_declaration": "def max_distance(N, edges, values):", "function_name": "max_distance", "parameter_list": "(N, edges, values)" }, { "docstring": null, "function_declaration": "def parse_and_solve():", "function_name": "parse_and_solve", "parameter_lis...
[ 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 deque, defaultdict\n\ndef max_distance(N, edges, values):\n if N == 1:\n return 0\n \n # Construct the tree as an a...
trial_gpt4o_0
{ "original_instruction": "You are given a binary tree with `N` nodes, each with a value. The value of each node is unique and ranges from 1 to N. Your task is to find the maximum distance between any two nodes in the tree.\n\nThe distance between two nodes is defined as the number of edges on the shortest path betwe...
0.623677
Code_Contests_22763
C
[ "max_distance", "parse_and_solve" ]
2
[ [ "parse_and_solve", "max_distance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c9a8f3ca35056b20302b9e3822acd4c141a059e9
dc6b8d3a46db1558f8486045dc3ff81b2e97ed76
v1.0
complete
Code_Contests
Code_Contests_22260_C
def treasure_hunt(s: str, queries: List[Tuple[int, int]]) -> List[int]: """ During a treasure hunt, you discover an ancient map that leads to a treasure. The map contains a secret code which can be deciphered using a simple algorithm based on characters' positions in the English alphabet. The map is ...
def alphabet_position(char): return ord(char) - ord('a') + 1 def preprocess_sum(s): sums = [0] * (len(s) + 1) for i in range(1, len(s) + 1): sums[i] = sums[i - 1] + alphabet_position(s[i - 1]) return sums def query_sum(sums, l, r): return sums[r] - sums[l - 1] def treasure_hunt(s, queries...
from solution import treasure_hunt def test_example_1(): s = "abc" queries = [(1, 1), (1, 2), (1, 3)] result = treasure_hunt(s, queries) assert result == [1, 3, 6] def test_example_2(): s = "xyz" queries = [(1, 2), (2, 3)] result = treasure_hunt(s, queries) assert result == [49, 51] d...
[ { "docstring": null, "function_declaration": "def alphabet_position(char):", "function_name": "alphabet_position", "parameter_list": "(char)" }, { "docstring": null, "function_declaration": "def preprocess_sum(s):", "function_name": "preprocess_sum", "parameter_list": "(s)" }, ...
[ 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 alphabetic_value_sum(s, queries):\n \"\"\"\n This function calculates the sum of numeric values for queried segments of the string.\n \n Pa...
trial_gpt4o_2
{ "original_instruction": "During a treasure hunt, you discover an ancient map that leads to a treasure. The map contains a secret code which can be deciphered using a simple algorithm based on characters' positions in the English alphabet.\n\nThe map is represented as a string containing only lowercase English alpha...
0.54026
Code_Contests_22260
C
[ "alphabet_position", "preprocess_sum", "query_sum", "treasure_hunt" ]
4
[ [ "preprocess_sum", "alphabet_position" ], [ "treasure_hunt", "preprocess_sum" ], [ "treasure_hunt", "query_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5b7cde2c6ac89ae965a29a13b1648760bab9bfcd
95ca1f79b319d0013b47687331493ebf23bf6747
v1.0
complete
Code_Contests
Code_Contests_22569_C
import math from functools import reduce from typing import List, Tuple def gcd(a: int, b: int) -> int: """ Calculate the greatest common divisor (GCD) of two numbers. >>> gcd(10, 15) 5 >>> gcd(14, 21) 7 """ pass def compute_max_gcd_in_subarray(arr: List[int], l: int, r: int) -> int: ...
import math from functools import reduce def gcd(a, b): while b: a, b = b, a % b return a def compute_max_gcd_in_subarray(arr, l, r): """ Function to compute the max GCD of any subarray that includes all elements from index l to r in the given list. """ subarray = arr[l-1:r] return...
def test_gcd(): assert gcd(10, 15) == 5 assert gcd(14, 21) == 7 assert gcd(13, 17) == 1 assert gcd(0, 5) == 5 assert gcd(5, 0) == 5 def test_compute_max_gcd_in_subarray(): assert compute_max_gcd_in_subarray([5, 10, 15, 20, 25, 30], 1, 3) == 5 assert compute_max_gcd_in_subarray([5, 10, 15, 2...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Function to compute the max GCD of any subarray that includes all elements from index l to r in the given list.", "function_declaration": "def compute_max_...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef gcd(a, b):\n \"\"\"\n Function to return the greatest common divisor (GCD) of two numbers.\n \"\"...
trial_gpt4o_7
{ "original_instruction": "You are given a list of n integers. Your task is to answer q queries. Each query will contain two integers l and r (1 ≤ l ≤ r ≤ n), and you need to determine the maximum GCD (Greatest Common Divisor) of any subarray that includes all elements from the l-th to the r-th element in the list.\n...
0.69418
Code_Contests_22569
C
[ "gcd", "compute_max_gcd_in_subarray", "solve" ]
3
[ [ "compute_max_gcd_in_subarray", "gcd" ], [ "solve", "compute_max_gcd_in_subarray" ] ]
2
[]
false
[]
false
pytest
false
[]
true
2aa0a827434f99c573d065d726c7285e4d6a6d93
ac1ad12771a0efa671569debe8dc49b20e87b21f
v1.0
complete
Code_Contests
Code_Contests_23283_C
from typing import List, Tuple def find_shortest_path(n: int, m: int, edges: List[Tuple[int, int, int]], s: int, d: int) -> int: """ Given a directed, weighted graph G, determine the shortest path from a starting city s to a destination city d. Returns the minimum travel cost if there is a valid path, or -1 i...
import heapq def dijkstra(n, graph, start, end): """ Uses Dijkstra's algorithm to find the shortest path in a directed, weighted graph. """ # Initialize distances and priority queue dist = [float('inf')] * (n + 1) dist[start] = 0 pq = [(0, start)] # (cost, node) while pq: ...
import pytest from solution import find_shortest_path def test_example_case(): n = 5 m = 6 edges = [ (1, 2, 2), (1, 3, 4), (2, 3, 1), (3, 4, 7), (2, 4, 5), (4, 5, 1) ] s = 1 d = 5 assert find_shortest_path(n, m, edges, s, d) == 8 def test_no_...
[ { "docstring": "Uses Dijkstra's algorithm to find the shortest path in a directed, weighted graph.", "function_declaration": "def dijkstra(n, graph, start, end):", "function_name": "dijkstra", "parameter_list": "(n, graph, start, end)" }, { "docstring": "Constructs the graph and finds the sh...
[ 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 heapq\n\ndef dijkstra(n, edges, s, d):\n # Creating the adjacency list for the graph\n graph = {i: [] for i in range(1, n+1)}\n for u, v, w...
trial_gpt4o_2
{ "original_instruction": "Given a directed, weighted graph G. Each node represents a city, and each edge represents a direct road connecting two cities with a certain travel cost. Your task is to determine the shortest path from a starting city s to a destination city d. You need to return the minimum travel cost if...
0.716406
Code_Contests_23283
C
[ "dijkstra", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a428510a9d4076a9e723158495fa7b2ecb2a9653
c7d1d0cf77af96ef372036b573981561fdf74867
v1.0
complete
Code_Contests
Code_Contests_22560_C
from typing import List, Tuple from collections import defaultdict def min_new_links_to_strongly_connect(n: int, m: int, links: List[Tuple[int, int]]) -> int: """ Determine the minimum number of new direct links that need to be added to make the network strongly connected. Parameters: n (int): Num...
from collections import defaultdict def find_scc(graph, n): """Find Strongly Connected Components (SCC) using Kosaraju's Algorithm.""" def dfs(v, graph, visited, stack): visited[v] = True for u in graph[v]: if not visited[u]: dfs(u, graph, visited, stack) ...
from solution import min_new_links_to_strongly_connect def test_example_case(): assert min_new_links_to_strongly_connect(4, 2, [(0, 1), (2, 3)]) == 2 def test_single_server(): assert min_new_links_to_strongly_connect(1, 0, []) == 0 def test_already_strongly_connected(): assert min_new_links_to_strongly_c...
[ { "docstring": "Find Strongly Connected Components (SCC) using Kosaraju's Algorithm.", "function_declaration": "def find_scc(graph, n):", "function_name": "find_scc", "parameter_list": "(graph, n)" }, { "docstring": null, "function_declaration": "def min_new_links_to_strongly_connect(n, ...
[ 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": "def min_new_links(n, m, edges):\n from collections import defaultdict, deque\n \n def strongly_connected_components(n, adjacency_list):\n i...
trial_gpt4o_3
{ "original_instruction": "Alex works as a network administrator at a company that maintains a dedicated network of servers. Each server connects to a certain number of other servers through direct one-way communication links. The network is represented as a directed graph where each node corresponds to a server and ...
0.57428
Code_Contests_22560
C
[ "find_scc", "min_new_links_to_strongly_connect", "reverse_graph" ]
3
[ [ "min_new_links_to_strongly_connect", "find_scc" ], [ "min_new_links_to_strongly_connect", "reverse_graph" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0926417fb10a4a591f0bd04d155c432ab0b6b1be
af6e500e0151e3d1c1c3d818eddfe6991cf35f51
v1.0
complete
Code_Contests
Code_Contests_23091_C
def calculate_max_revenue(initial_price: float, elasticity: float) -> float: """ Calculate the maximum possible revenue for a product given its initial price and price elasticity of demand. """ # Implement the function to calculate the maximum possible revenue pass def maximize_revenues(n: int...
def calculate_max_revenue(initial_price, elasticity): """ Calculate the maximum possible revenue for a product given its initial price and price elasticity of demand. """ if elasticity > 0: # Elastic demand return round(max(2 * initial_price, initial_price), 2) else: # Inelastic deman...
from solution import maximize_revenues def test_maximize_revenues_case_1(): n = 2 product_info = [(100, 1.5), (200, -0.5)] result = maximize_revenues(n, product_info) assert result == [200.0, 400.0] def test_maximize_revenues_case_2(): n = 3 product_info = [(50, 0.8), (150, 1.2), (300, -0....
[ { "docstring": "Calculate the maximum possible revenue for a product given its \ninitial price and price elasticity of demand.", "function_declaration": "def calculate_max_revenue(initial_price, elasticity):", "function_name": "calculate_max_revenue", "parameter_list": "(initial_price, elasticity)" ...
[ 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": "def calculate_max_revenue(prices, elasticities):\n \"\"\"\n Calculate the maximum possible revenue for each product\n\n :param prices: List of ini...
trial_gpt4o_3
{ "original_instruction": "Imagine you are writing an algorithm for an online marketplace to manage the pricing of products over time to maximize revenue. The marketplace has a set of products, each with a specific price elasticity of demand. The price elasticity of demand (e) is a measure of how the quantity demande...
0.665658
Code_Contests_23091
C
[ "calculate_max_revenue", "maximize_revenues" ]
2
[ [ "maximize_revenues", "calculate_max_revenue" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b149e1ef77f7e44fad0efe246f636c444bb3c0e
860785f4ee3c26bbadc9a96aeb5e8db2309662f0
v1.0
complete
Code_Contests
Code_Contests_22953_C
def solve(t: int, experiments: List[List[str]]) -> List[str]: """ Determine the core string for each experimental cycle or indicate if it does not exist. Args: t (int): The number of experiment cycles. experiments (List[List[str]]): A list containing t lists of strings representing bacteria...
def find_core_string(cycle): n = len(cycle) m = len(cycle[0]) for i in range(n): candidate = list(cycle[i]) valid = True for j in range(m): original_char = candidate[j] mismatch_count = 0 for k in range(n): ...
from solution import solve def test_single_experiment_positive(): t = 1 experiments = [ ["ABCD", "ABCE", "ABCF"] ] assert solve(t, experiments) == ["ABCD"] def test_single_experiment_negative(): t = 1 experiments = [ ["ABCD", "ABDC"] ] assert solve(t, experiments) == [-...
[ { "docstring": null, "function_declaration": "def find_core_string(cycle):", "function_name": "find_core_string", "parameter_list": "(cycle)" }, { "docstring": null, "function_declaration": "def solve(t, experiments):", "function_name": "solve", "parameter_list": "(t, experiments...
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_core_string(t, cycles):\n results = []\n for cycle in cycles:\n n, strings = cycle\n \n m = len(strings[0])\n \n...
trial_gpt4o_7
{ "original_instruction": "A scientist is conducting an experiment using bacteria cultures in a laboratory. Each culture is represented as a string consisting of characters 'A', 'B', 'C', and 'D'. The scientist has a hypothesis that the cultures follow a specific pattern to mutate over time. Specifically, she suspect...
0.528412
Code_Contests_22953
C
[ "find_core_string", "solve" ]
2
[ [ "solve", "find_core_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b1c2d359ae3418b0ef4edfdb3e5d9cb25487766a
f04f66fa671fb87571316578a6d7144fc155aeb9
v1.0
complete
Code_Contests
Code_Contests_22791_C
def can_form_palindrome(s): """ Determine if a string can be rearranged to form a palindrome. """ def check_beautiful_strings(strings): """ For each string in the input list, return 'YES' if it is beautiful (can be rearranged to form a palindrome), and 'NO' otherwise. """ import pytest de...
def can_form_palindrome(s): """ Determine if a string can be rearranged to form a palindrome. """ from collections import Counter char_count = Counter(s) odd_count = sum(1 for count in char_count.values() if count % 2 == 1) return odd_count <= 1 def check_beautiful_strings(strings): """...
import pytest from solution import can_form_palindrome, check_beautiful_strings def test_can_form_palindrome(): assert can_form_palindrome("civic") == True assert can_form_palindrome("ivicc") == True assert can_form_palindrome("random") == False assert can_form_palindrome("madam") == True assert ca...
[ { "docstring": "Determine if a string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "For each string in the input list, return 'YES' if it is beautiful (can be...
[ 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_beautiful(s):\n \"\"\"\n Checks if a string s can be rearranged to form a palindrome.\n \n Args:\n s (str): The input string.\n \n...
trial_gpt4o_2
{ "original_instruction": "Liam is fascinated with symmetric properties of strings. He finds a string beautiful if it can be rearranged to form a palindrome. Recall that a palindrome is a string that reads the same forward and backward.\n\nLiam wonders how many of the strings in a given list are beautiful.\n\nInput\n...
0.716464
Code_Contests_22791
C
[ "can_form_palindrome", "check_beautiful_strings" ]
2
[ [ "check_beautiful_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
879db3018c18085d8c931c2964ef1faf873a17d9
3c672f406639f9a3cd5318d502c1466c30c5af7c
v1.0
complete
Code_Contests
Code_Contests_23343_C
def largest_subrectangle_area(n: int, m: int, matrix: List[List[int]]) -> int: """ Find the area of the largest subrectangle in the matrix containing only 1s. >>> largest_subrectangle_area(4, 5, [ ... [1, 0, 1, 0, 0], ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 0, 0, 1, 0] ... ]) 6 ...
def max_rectangle_area(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) heights = [0] * (m + 1) max_area = 0 for row in matrix: for i in range(m): if row[i] == 1: heights[i] += 1 else: heights[i...
from solution import largest_subrectangle_area def test_example_1(): n, m = 4, 5 matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert largest_subrectangle_area(n, m, matrix) == 6 def test_example_2(): n, m = 3, 3 matrix = [ ...
[ { "docstring": null, "function_declaration": "def max_rectangle_area(matrix):", "function_name": "max_rectangle_area", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_subrectangle_area(n, m, matrix):", "function_name": "largest_subrectangle_a...
[ 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 maximalRectangle(matrix):\n \"\"\"\n Given a 2D binary matrix filled with 0's and 1's, find the area of the largest rectangle containing only 1's...
trial_gpt4o_2
{ "original_instruction": "You are given a matrix with n rows and m columns containing only 0s and 1s. A subrectangle of this matrix is any contiguous subgrid with all values being 1. The task is to find the area of the largest subrectangle in the matrix containing only 1s.\n\nInput\n\nThe first line contains two int...
0.620637
Code_Contests_23343
C
[ "max_rectangle_area", "largest_subrectangle_area" ]
2
[ [ "largest_subrectangle_area", "max_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c470e3cab2eae1c21ccaadb02419b235a426c18c
ac7695550d1c50458dccd2408e0c2dd25292e687
v1.0
complete
Code_Contests
Code_Contests_23392_C
def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int: """ Compute the diameter of a tree. >>> tree_diameter(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) 3 >>> tree_diameter(3, [(1, 2), (2, 3)]) 2 >>> tree_diameter(1, []) 0 >>> tree_diameter(6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]) ...
def find_farthest_node(adj_list, start): from collections import deque n = len(adj_list) visited = [False] * n distance = [0] * n queue = deque([start]) visited[start] = True farthest_node = start while queue: node = queue.popleft() for neighbor in adj_list[node]: ...
def test_tree_diameter(): assert tree_diameter(5, [(1, 2), (1, 3), (2, 4), (2, 5)]) == 3 assert tree_diameter(3, [(1, 2), (2, 3)]) == 2 assert tree_diameter(1, []) == 0 assert tree_diameter(2, [(1, 2)]) == 1 def test_tree_diameter_large(): assert tree_diameter(6, [(1, 2), (2, 3), (3, 4), (4, 5), (5...
[ { "docstring": null, "function_declaration": "def find_farthest_node(adj_list, start):", "function_name": "find_farthest_node", "parameter_list": "(adj_list, start)" }, { "docstring": null, "function_declaration": "def tree_diameter(n, edges):", "function_name": "tree_diameter", ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef find_furthest_node(start_node, graph):\n visited = set()\n queue = deque([(start_node, 0)])\n fu...
trial_gpt4o_2
{ "original_instruction": "Emily is learning about tree structures and their properties. She came across the concept of node distances and wants to write a program to calculate the longest distance between any two nodes in a tree.\n\nA tree is an undirected, connected, acyclic graph with n nodes and n-1 edges. The di...
0.667783
Code_Contests_23392
C
[ "find_farthest_node", "tree_diameter" ]
2
[ [ "tree_diameter", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c75aa3ee41d826e187fd122c11fb265c3e6377e3
d1b30f683251d89455ed53e96fb3c9a76b33b042
v1.0
complete
Code_Contests
Code_Contests_23194_C
from typing import List, Tuple def lazy_bartender(n: int, m: int, preferences: List[Tuple[int, int]]) -> int: """ Determine the minimal number of different types of drinks the bartender needs to keep in stock to satisfy all regulars. >>> lazy_bartender(4, 3, [(1, 2), (2, 3), (3, 4)]) 2 >>> lazy_ba...
from itertools import combinations def minimize_drinks(n, preferences): all_drinks = set() for pref in preferences: all_drinks.update(pref) # Check each combination of drink sets starting from size 1 to size n for size in range(1, n + 1): for combo in combinations(all_drinks, size): ...
from solution import lazy_bartender def test_example_1(): n = 4 m = 3 preferences = [(1, 2), (2, 3), (3, 4)] assert lazy_bartender(n, m, preferences) == 2 def test_example_2(): n = 5 m = 5 preferences = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)] assert lazy_bartender(n, m, preferences) =...
[ { "docstring": null, "function_declaration": "def minimize_drinks(n, preferences):", "function_name": "minimize_drinks", "parameter_list": "(n, preferences)" }, { "docstring": null, "function_declaration": "def lazy_bartender(n, m, preferences):", "function_name": "lazy_bartender", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef minimize_drinks(n, preferences):\n all_drinks = set()\n for pref in preferences:\n all_drinks.update...
trial_gpt4o_0
{ "original_instruction": "**Lazy Bartender's Challenge**\n\nBartender, a fan of efficient serving, has an interesting dilemma. There exist `n` different drinks at his bar and `m` regulars at his bar, each having a distinct drink preference. Each regular requests only a single drink, but the bartender sometimes must ...
0.559992
Code_Contests_23194
C
[ "minimize_drinks", "lazy_bartender" ]
2
[ [ "lazy_bartender", "minimize_drinks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f39c8cced25ee476ade3d2cb53cabcdec57faf7
f04d02ecb2267ac609982efca5d0fc2445117ad6
v1.0
complete
Code_Contests
Code_Contests_23623_C
def is_prime(num: int) -> bool: """ Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(29) True >>> is_prime(1) False """ def sum_of_m_largest_primes(sequence: List[int], m: int) -> int: """ Compute the s...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def sum_of_m_largest_primes(se...
from solution import is_prime, sum_of_m_largest_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(18...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sum_of_m_largest_primes(sequence, m):", "function_name": "sum_of_m_largest_primes", "parameter_list": "(s...
[ 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(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i...
trial_gpt4o_2
{ "original_instruction": "Emma is a renowned mathematician who is fascinated by sequences and prime numbers. She stumbled upon a sequence problem and needs your help to solve it. You need to develop an algorithm that finds a special sum of a sequence based on a specific condition.\n\nGiven a sequence of integers and...
0.735945
Code_Contests_23623
C
[ "is_prime", "sum_of_m_largest_primes" ]
2
[ [ "sum_of_m_largest_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13dacc2b9bc3a3a84e37777ec4eeeac2b7010316
77a55e8715206d15daca961351e45b1a304f7b8f
v1.0
complete
Code_Contests
Code_Contests_23852_C
def min_digits_to_palindrome(n: int) -> str: """ Check if the number n is a palindrome. If not, find the minimum number of digits required to be added to the end of n to make it a palindrome. Returns "YES" if n is already a palindrome, or the smallest number of digits needed to add to the end of ...
def is_palindrome(s): """ Returns True if the given string s is a palindrome, False otherwise. """ return s == s[::-1] def min_digits_to_palindrome(n): """ Check if the number n is a palindrome. If not, find the minimum number of digits required to be added to the end of n to make it a ...
from solution import min_digits_to_palindrome def test_min_digits_to_palindrome_positive_palindrome(): assert min_digits_to_palindrome(121) == "YES" def test_min_digits_to_palindrome_non_palindrome(): assert min_digits_to_palindrome(123) == 2 def test_min_digits_to_palindrome_single_digit(): assert min_d...
[ { "docstring": "Returns True if the given string s is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if the number n is a palindrome.\nIf not, find the minimum number of digi...
[ 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(n):\n \"\"\"\n Check if the number n is a palindrome.\n \"\"\"\n str_n = str(n)\n return str_n == str_n[::-1]\n\ndef min_a...
trial_gpt4o_2
{ "original_instruction": "Anna is interested in palindrome numbers. A palindrome number is a number that reads the same backward as forward, like 121 or 1331. One day, she was given a task to check if a number is a palindrome and, if not, find the minimum number of digits she needs to add to the end of the number to...
0.774574
Code_Contests_23852
C
[ "is_palindrome", "min_digits_to_palindrome" ]
2
[ [ "min_digits_to_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a410e08ed50e9b62ee0269016506ebb33158ce53
ad7091c33f6aac7af210d0e7e0d4e5ca8624cc78
v1.0
complete
Code_Contests
Code_Contests_22938_C
def min_total_difficulty(n: int, m: int, trails: List[Tuple[int, int, int]]) -> int: """ Compute the minimum total difficulty level required to ensure that all intersections are accessible from each other in a large forest represented by an undirected graph. Args: n : int : number of intersections ...
# Kruskal's algorithm to find the Minimum Spanning Tree (MST) 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[ro...
def test_min_total_difficulty(): # Test case 1 n, m = 4, 5 trails = [(1, 2, 1), (1, 3, 4), (1, 4, 3), (2, 3, 2), (3, 4, 5)] assert min_total_difficulty(n, m, trails) == 6 # Test case 2 n, m = 5, 4 trails = [(1, 2, 0), (2, 3, 1), (3, 4, 2), (4, 5, 3)] assert min_total_difficulty(n, m...
[ { "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": "# Kruskal's algorithm to find the Minimum Spanning Tree (MST)\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n return fi...
trial_gpt4o_0
{ "original_instruction": "A forest ranger is responsible for maintaining the hiking trails in a large forest. The forest is represented by an undirected graph, where nodes represent trail intersections and edges represent the trails between them. Each trail has a difficulty level that can be positive or zero.\n\nThe...
0.603044
Code_Contests_22938
C
[ "find", "union", "min_total_difficulty" ]
3
[ [ "min_total_difficulty", "find" ], [ "min_total_difficulty", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
87724a1246f8fbd1a221fa41702bd2b69b5b19c1
dc437ed1c058c56f9a7181016b8255f43f5ae99d
v1.0
complete
Code_Contests
Code_Contests_23495_C
from typing import List def is_prime(num: int) -> bool: """Check if a number is a prime. >>> is_prime(1) == False >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True """ pass def find_primes_up_to_n(N: int) -> List[int]: """Returns a lis...
def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while (i * i) <= num: if num % i == 0 or num % (i + 2) == 0: return False i ...
from solution import is_prime, find_primes_up_to_n def test_is_prime(): assert is_prime(1) == False assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True def test_find_primes_up_to_10(): assert find_primes_up_to_n(10) == [2, 3, 5, 7] def ...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers from 1 to N (inclusive).", "function_declaration": "def find_primes_up_to_n(N):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i...
trial_gpt4o_2
{ "original_instruction": "Write a program that reads a single integer N (1 ≤ N ≤ 10000) and prints all the prime numbers from 1 to N (inclusive). \n\nConstraints\n\n* 1 ≤ N ≤ 10000\n\nInput\n\nThe input consists of a single integer N.\n\nOutput\n\nFor each prime number from 1 to N, print the prime number on a new li...
0.818655
Code_Contests_23495
C
[ "is_prime", "find_primes_up_to_n" ]
2
[ [ "find_primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
64bc6bc833ae371f11be3daefddefe9ca3159e10
fc5aa4989e8d55fb1a3ce4f9b12a31a5e5c35144
v1.0
complete
Code_Contests
Code_Contests_22035_C
def preprocess_max_values(sequence): """ Preprocesses the sequence to provide a data structure enabling efficient range maximum queries. Args: - sequence (list of int): The list of integers representing the sequence. Returns: - list of list of int: Sparse table prepared for range maxim...
def preprocess_max_values(sequence): """ Preprocesses the sequence to provide a data structure enabling efficient range maximum queries. Args: - sequence (list of int): The list of integers representing the sequence. Returns: - list of list of int: Sparse table prepared for range maxim...
from solution import handle_queries def test_handle_queries_example(): sequence = [1, 3, 5, 7, 9] queries = [(1, 3), (2, 4), (1, 5)] expected = [5, 7, 9] assert handle_queries(sequence, queries) == expected def test_handle_queries_single_element_subarray(): sequence = [1, 3, 5, 7, 9] queries =...
[ { "docstring": "Preprocesses the sequence to provide a data structure enabling efficient range maximum queries.\n\nArgs:\n- sequence (list of int): The list of integers representing the sequence.\n\nReturns:\n- list of list of int: Sparse table prepared for range maximum queries.", "function_declaration": "...
[ 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_max_in_subarray(sequence, queries):\n \"\"\"\n For each query, find the maximum value in the subarray specified by indices l and r.\n \n ...
trial_gpt4o_2
{ "original_instruction": "You are given a sequence of `n` integers. You have to perform a specific type of query on the sequence multiple times. Each query is defined by two integers `l` and `r` and requires you to find the maximum value in the subarray starting at index `l` and ending at index `r`. The task is to e...
0.630355
Code_Contests_22035
C
[ "preprocess_max_values", "query_max_in_subarray", "handle_queries" ]
3
[ [ "handle_queries", "preprocess_max_values" ], [ "handle_queries", "query_max_in_subarray" ] ]
2
[ "handle_queries" ]
false
[]
false
pytest
true
[]
true
fe82644736e6673980bcab0f5ed2a6ce2a1ff559
d51b2a53420d3e80fceb329aada67f37cceec6e9
v1.0
complete
Code_Contests
Code_Contests_24076_C
def max_increase_and_decrease(prices: List[int]) -> Tuple[int, int]: """ Returns the maximum increase and maximum decrease in stock prices within a contiguous subarray. >>> max_increase_and_decrease([1, -2, 3, -4, 5]) (5, -4) >>> max_increase_and_decrease([-1, -1, -1, -1]) (-1, -4) >>> m...
def max_increase_and_decrease(prices): """ Returns the maximum increase and maximum decrease in stock prices within a contiguous subarray. """ max_increase = max_subarray_sum(prices) max_decrease = min_subarray_sum(prices) return max_increase, max_decrease def max_subarray_sum(arr): max...
from solution import max_increase_and_decrease, solve def test_case_1(): prices = [1, -2, 3, -4, 5] assert max_increase_and_decrease(prices) == (5, -4) def test_case_2(): prices = [-1, -1, -1, -1] assert max_increase_and_decrease(prices) == (-1, -4) def test_case_3(): prices = [2, -1, 2, 3, -1, 2...
[ { "docstring": "Returns the maximum increase and maximum decrease in stock prices\nwithin a contiguous subarray.", "function_declaration": "def max_increase_and_decrease(prices):", "function_name": "max_increase_and_decrease", "parameter_list": "(prices)" }, { "docstring": null, "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_increase_and_decrease(arr):\n def max_subarray_sum(nums):\n max_ending_here, max_so_far = float('-inf'), float('-inf')\n for x in ...
trial_gpt4o_2
{ "original_instruction": "**Question: Price Fluctuation Analysis**\n\nAlice is an analyst working for a stock trading company. Her task is to monitor the daily price changes of a particular stock for the past N days. Alice records a positive integer each day, representing the price change. A positive change indicate...
0.581301
Code_Contests_24076
C
[ "max_increase_and_decrease", "max_subarray_sum", "min_subarray_sum", "solve" ]
4
[ [ "max_increase_and_decrease", "max_subarray_sum" ], [ "max_increase_and_decrease", "min_subarray_sum" ], [ "solve", "max_increase_and_decrease" ] ]
3
[]
false
[]
false
pytest
true
[]
true
04954e66a1abb8f555524c022eeb37ae1b06be25
3a6a1b03f00c3499cd27d2a226b9d4bcc2d474ad
v1.0
complete
Code_Contests
Code_Contests_24080_C
def garden_setup(m: int, n: int, garden: List[str]) -> str: """ Check if planting flowers in the garden to match preferred cells is possible. Args: m (int): number of rows in the garden. n (int): number of columns in the garden. garden (List[str]): list of strings representing the garden...
def can_plant_flowers(m, n, garden): row_counts = [0] * m col_counts = [0] * n for i in range(m): for j in range(n): if garden[i][j] == '#': row_counts[i] += 1 col_counts[j] += 1 return sorted(row_counts) == sorted(col_counts) def garden_setup(m, n,...
from solution import garden_setup def test_example1(): m = 3 n = 3 garden = [ "#.#", ".#.", "#.#" ] assert garden_setup(m, n, garden) == "YES" def test_example2(): m = 4 n = 4 garden = [ "####", ".#..", "###.", "####" ] as...
[ { "docstring": null, "function_declaration": "def can_plant_flowers(m, n, garden):", "function_name": "can_plant_flowers", "parameter_list": "(m, n, garden)" }, { "docstring": null, "function_declaration": "def garden_setup(m, n, garden):", "function_name": "garden_setup", "param...
[ 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 can_plant_flowers(m, n, garden):\n row_counts = [0] * m\n col_counts = [0] * n\n\n for i in range(m):\n for j in range(n):\n ...
trial_gpt4o_0
{ "original_instruction": "Alice is an avid gardener and is particularly fond of growing flowerbeds. However, maintaining the flowerbeds in certain patterns is quite a task! Alice decides to automate the process using some programming magic.\n\nYou are assigned to help Alice in the following problem:\n\nAlice has a r...
0.576246
Code_Contests_24080
C
[ "can_plant_flowers", "garden_setup" ]
2
[ [ "garden_setup", "can_plant_flowers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
222ee57d7949f3fa89bdae569350bdf13855ef9a
ccd2ea0f6e2b27457140591788223357452400d4
v1.0
complete
Code_Contests
Code_Contests_23878_C
def find_maximum_subarray_sum(arr): """ Find the maximum subarray sum for a given array using the divide and conquer approach. >>> find_maximum_subarray_sum([1]) 1 >>> find_maximum_subarray_sum([-1]) -1 >>> find_maximum_subarray_sum([-2, -3, 4, -1, -2, 1, 5, -3]) 7 >>> find_maximum_subar...
def max_crossing_sum(arr, low, mid, high): """ Find the maximum sum of the subarray that crosses the midpoint. """ left_sum = float('-inf') total = 0 for i in range(mid, low-1, -1): total += arr[i] if total > left_sum: left_sum = total right_sum = float('-inf') ...
from solution import find_maximum_subarray_sum def test_single_element(): assert find_maximum_subarray_sum([1]) == 1 assert find_maximum_subarray_sum([-1]) == -1 def test_all_negative(): assert find_maximum_subarray_sum([-2, -3, -1, -4]) == -1 def test_mixed_elements(): assert find_maximum_subarray_s...
[ { "docstring": "Find the maximum sum of the subarray that crosses the midpoint.", "function_declaration": "def max_crossing_sum(arr, low, mid, high):", "function_name": "max_crossing_sum", "parameter_list": "(arr, low, mid, high)" }, { "docstring": "Find the maximum sum of a contiguous subar...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crossing_sum(arr, left, mid, right):\n \"\"\"\n Find the maximum possible sum in `arr` such that the sum includes\n elements on either sid...
trial_gpt4o_2
{ "original_instruction": "Write a function to find the maximum subarray sum for a given array using the divide and conquer approach.\n\nThe problem is to find the maximum sum of a contiguous subarray in an unbounded array (i.e., an array that can have both positive and negative integers). You need to implement the s...
0.775325
Code_Contests_23878
C
[ "max_crossing_sum", "max_subarray_sum", "find_maximum_subarray_sum" ]
3
[ [ "find_maximum_subarray_sum", "max_subarray_sum" ], [ "max_subarray_sum", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
603dbb5f0e7b2ce99eb3658fe0399ebf577b2322
1126a3f435e69c573b25e59f0386647bea718ec1
v1.0
complete
Code_Contests
Code_Contests_24050_C
def maximum_spanning_tree(n: int, edges: List[Tuple[int, int, int]]) -> int: """ Determine the maximum possible total length of roads selected, such that there are no cycles in the road network. Args: n: int - The number of cities. edges: List[Tuple[int, int, int]] - The list of roads describe...
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 rank[root_x] > rank[root_y]: p...
def test_maximum_spanning_tree(): assert maximum_spanning_tree(4, [(0, 1, 3), (1, 2, 5), (2, 3, 6), (3, 0, 7), (1, 3, 4)]) == 18 assert maximum_spanning_tree(4, [(0, 1, 1), (1, 2, 1), (2, 3, 1)]) == 3 assert maximum_spanning_tree(2, [(0, 1, 10)]) == 10 assert maximum_spanning_tree(3, [(0, 1, 10), (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, 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, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro...
trial_gpt4o_0
{ "original_instruction": "You are part of a team responsible for designing road networks. You need to select certain roads in such a way that the road network does not contain any cycles and has the maximum possible total length. \n\nYou are given a list of roads, where each road connects two cities and has a certai...
0.657426
Code_Contests_24050
C
[ "find", "union", "maximum_spanning_tree", "process_input" ]
4
[ [ "maximum_spanning_tree", "find" ], [ "maximum_spanning_tree", "union" ], [ "process_input", "maximum_spanning_tree" ], [ "union", "find" ] ]
4
[ "process_input" ]
false
[]
false
pytest
false
[]
true
26a7f330c3fcb15bacfeb5e82ca5f9d131ff2eb0
ed505874bdb082a00e4065ca35dac7a42cf51e8b
v1.0
complete
Code_Contests
Code_Contests_23632_C
def who_wins_game(n: int) -> str: """ Determine the winner of the card game with n cards. Charlie wins if n % 3 != 0. Dana wins if n % 3 == 0. >>> who_wins_game(1) 'Charlie' >>> who_wins_game(2) 'Charlie' >>> who_wins_game(3) 'Dana' >>> who_wins_game(4) 'Charlie...
def who_wins_game(n): """ Determine the winner of the card game with n cards. Charlie wins if n % 3 != 0. Dana wins if n % 3 == 0. """ if n % 3 == 0: return "Dana" else: return "Charlie" def determine_winners(test_cases): results = [] for n in test_cases: ...
from solution import who_wins_game, determine_winners, process_input_output def test_who_wins_game(): assert who_wins_game(1) == "Charlie" assert who_wins_game(2) == "Charlie" assert who_wins_game(3) == "Dana" assert who_wins_game(4) == "Charlie" assert who_wins_game(5) == "Charlie" assert who_...
[ { "docstring": "Determine the winner of the card game with n cards.\n\nCharlie wins if n % 3 != 0.\nDana wins if n % 3 == 0.", "function_declaration": "def who_wins_game(n):", "function_name": "who_wins_game", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def d...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_winner(n):\n \"\"\"\n Determines the winner of the game given N cards.\n Charlie wins if N % 3 != 0, otherwise Dana wins.\n \"\"\"\n ...
trial_gpt4o_9
{ "original_instruction": "Two friends, Charlie and Dana, are playing a card game using a deck of N cards numbered from 1 to N.\n\nThey take turns drawing cards from the top of the deck. Charlie always goes first, and after that, they alternate turns.\n\nOn their turn, a player can draw either one card or two consecu...
0.657345
Code_Contests_23632
C
[ "who_wins_game", "determine_winners", "process_input_output" ]
3
[ [ "determine_winners", "who_wins_game" ], [ "process_input_output", "determine_winners" ] ]
2
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
cfd7cb1e4b7e20adec44036b6f376085aa964fa9
8c9744f8ca5d19898468c81842a934d6606fab1f
v1.0
complete
Code_Contests
Code_Contests_24022_C
def max_water_flow(num_junctions: int, pipes: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ Determine the maximum water flow from source to target junctions in a water supply system represented as a weighted directed graph. Args: num_junctions (int): Number of junctions....
import collections def bfs(C, F, source, sink, parent): visited = [False] * len(C) queue = collections.deque([source]) visited[source] = True while queue: u = queue.popleft() for v in range(len(C)): if not visited[v] and C[u][v] - F[u][v] > 0: queue.append(v)...
from solution import max_water_flow def test_example_case1(): num_junctions = 4 pipes = [ (1, 2, 10), (1, 3, 5), (2, 3, 15), (2, 4, 10), (3, 4, 10) ] queries = [ (1, 4), (2, 3), (3, 1) ] result = max_water_flow(num_junctions, pipes...
[ { "docstring": null, "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(C, source, sink):", "function_name": "edmonds_karp", "pa...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef bfs(C, F, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(sourc...
trial_gpt4o_4
{ "original_instruction": "Arkady wants to monitor the water supply system in his garden. The water supply system can be represented as a weighted directed graph with n junctions (numbered from 1 to n) and m pipes connecting them. Each pipe from junction u to junction v has a capacity w, which is the maximum amount o...
0.634894
Code_Contests_24022
C
[ "bfs", "edmonds_karp", "max_water_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_water_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
18039ec469fec803d0e4c2260a7c156efed6fbe0
75745f254632847a6814ac4ee29f7c9c126d3047
v1.0
complete
Code_Contests
Code_Contests_23608_C
def garden_arrangement(m, n, constraints): """ Determine if it's possible to arrange plants in a garden according to specific rules and constraints. Args: m (int): Number of rows in the garden. n (int): Number of columns in the garden. constraints (List[Tuple[int, int, int]]): A list of tuples r...
def garden_arrangement(m, n, constraints): garden = [[-1 for _ in range(n)] for _ in range(m)] # Fill in the constraints for (i, j, t) in constraints: garden[i-1][j-1] = t # Check if the constraints lead to a contradiction for i in range(m): for j in range(n): i...
from solution import garden_arrangement, solve, parse_input, format_output def test_garden_arrangement_no(): assert garden_arrangement(3, 3, [(1, 1, 0), (1, 2, 0)]) == "NO" def test_garden_arrangement_yes(): assert garden_arrangement(3, 3, [(1, 1, 0), (3, 3, 1)])[0] == "YES" assert garden_arrangement(4, 4...
[ { "docstring": null, "function_declaration": "def garden_arrangement(m, n, constraints):", "function_name": "garden_arrangement", "parameter_list": "(m, n, constraints)" }, { "docstring": null, "function_declaration": "def solve(k, cases):", "function_name": "solve", "parameter_l...
[ 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 garden_arrangement(m, n, requirements):\n # Create an initial garden with -1 (undecided)\n garden = [[-1 for _ in range(n)] for _ in range(m)]\n ...
trial_gpt4o_4
{ "original_instruction": "In a rectangular garden, there are m rows and n columns of plants. Each plant can either grow flowers or vegetables. The gardener wants to arrange the garden such that each row contains only one type of plant (all flowers or all vegetables) and each column contains only one type of plant. A...
0.609551
Code_Contests_23608
C
[ "garden_arrangement", "solve", "parse_input", "format_output" ]
4
[ [ "solve", "garden_arrangement" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
e52ee2dd8c7038c8fdeec019f5eba762ae9808b0
b530e59e869ae72cbfdd4cbc75154c64714d4b0b
v1.0
complete
Code_Contests
Code_Contests_24205_C
def subset_sum_exists(input_str: str) -> str: """ Given an array of integers, determine if there exists a subset of the array whose sum is exactly equal to a given integer S. >>> subset_sum_exists("5 9\n3 34 4 12 5 2") "YES" >>> subset_sum_exists("5 30\n3 34 4 12 5 2") "NO" """
def is_subset_sum_exists(n, S, array): """ Determines if there exists a subset of the array whose sum is exactly equal to S using dynamic programming. :param n: int, number of elements in the array :param S: int, target sum :param array: list of integers, elements of the array :return: str,...
def test_subset_sum_exists(): assert subset_sum_exists("5 9\n3 34 4 12 5 2") == "YES" assert subset_sum_exists("5 30\n3 34 4 12 5 2") == "NO" assert subset_sum_exists("6 10\n1 2 3 4 5 6") == "YES" assert subset_sum_exists("4 10\n10 10 10 10") == "YES" assert subset_sum_exists("4 25\n1 3 5 7") == "NO...
[ { "docstring": "Determines if there exists a subset of the array whose sum is exactly equal to S using dynamic programming.\n\n:param n: int, number of elements in the array\n:param S: int, target sum\n:param array: list of integers, elements of the array\n:return: str, \"YES\" if such a subset exists, \"NO\" o...
[ 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 subset_sum_exists(arr, target):\n \"\"\"\n Determine if there is a subset of 'arr' such that the sum of its elements is equal to 'target'.\n \...
trial_gpt4o_2
{ "original_instruction": "Given an array of integers, determine if there exists a subset of the array whose sum is exactly equal to a given integer $S$.\n\nConstraints\n\n* $ 1 \\leq n \\leq 1000$\n* $ 1 \\leq a_i \\leq 1000$\n\nInput\n\nThe input is given in the following format:\n\n$n$ $S$\n$a_1$ $a_2$ $a_3$ $...$...
0.715285
Code_Contests_24205
C
[ "is_subset_sum_exists", "subset_sum_exists" ]
2
[ [ "subset_sum_exists", "is_subset_sum_exists" ] ]
1
[]
false
[]
false
pytest
false
[]
true
258fbccdeefec4d39d20a019de3c25123127ac7c
e41f838d29d3a28d9aa44ba323896813fa7b430d
v1.0
complete
Code_Contests
Code_Contests_24129_C
def preprocess_tree_heights(heights): """ Preprocess the tree heights to allow for efficient range maximum queries. >>> preprocess_tree_heights([2, 8, 3, 7, 4]) [[2, 8, 8], [8, 8, 8], [3, 7], [7], [4]] """ def query_max_in_range(dp, L, R): """ Answer the range maximum query using the preprocessed d...
def preprocess_tree_heights(heights): """ Preprocess the tree heights to allow for efficient range maximum queries. """ n = len(heights) log_n = n.bit_length() dp = [[0] * log_n for _ in range(n)] for i in range(n): dp[i][0] = heights[i] j = 1 while (1 << j) <= n: ...
from solution import preprocess_tree_heights, query_max_in_range, solve def test_single_query(): heights = [2, 8, 3, 7, 4] dp = preprocess_tree_heights(heights) assert query_max_in_range(dp, 1, 3) == 8 assert query_max_in_range(dp, 2, 4) == 8 assert query_max_in_range(dp, 1, 5) == 8 def test_multi...
[ { "docstring": "Preprocess the tree heights to allow for efficient range maximum queries.", "function_declaration": "def preprocess_tree_heights(heights):", "function_name": "preprocess_tree_heights", "parameter_list": "(heights)" }, { "docstring": "Answer the range maximum query using the p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class SegmentTree:\n def __init__(self, data):\n n = len(data)\n self.n = n\n self.tree = [0] * (2 * n)\n self.build(data)\n...
trial_gpt4o_2
{ "original_instruction": "In a forest there are n different types of trees, labeled from 1 to n. Each tree type has a fixed height, and exactly one tree of each type exists in the forest. You want to trim the forest such that only trees of certain heights remain in a contiguous segment from any given range [L, R] (1...
0.59944
Code_Contests_24129
C
[ "preprocess_tree_heights", "query_max_in_range", "solve" ]
3
[ [ "solve", "preprocess_tree_heights" ], [ "solve", "query_max_in_range" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d7ec14a430068b6f87deced7698de15b06f6d264
4935eb25b72ca34b54c00272c66e42d62ae15558
v1.0
complete
Code_Contests
Code_Contests_22776_C
import math from typing import List, Tuple def is_prime(num: int) -> bool: """Check if a number is prime.""" pass def special_sort(n: int, arr: List[int]) -> List[int]: """Return the array sorted in special order. >>> special_sort(7, [3, 15, 2, 1, 9, 4, 7]) [2, 3, 7, 15, 9, 4, 1] >>> special_s...
def is_prime(num): """Check if a number is prime.""" if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 retur...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(7) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(1) == False def test_special_sort(): assert special_sort(7, [3, 15, 2, 1, 9, 4, 7]) ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Return the array sorted in special order.", "function_declaration": "def special_sort(n, arr):", "function_name": "spe...
[ 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 \"\"\" Helper function to determine if a number is prime \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "Given a list of n distinct integers in any random order, you need to sort them into a special order. The special order is defined as follows:\n- All the prime numbers in the list should appear first and they should be sorted in ascending order.\n- All the composite numbers in the list shoul...
0.672771
Code_Contests_22776
C
[ "is_prime", "special_sort", "process_test_cases" ]
3
[ [ "process_test_cases", "special_sort" ], [ "special_sort", "is_prime" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
false
[]
true
659a0ed24f6157facba16d301c3a57d6a0b83267
b2979204f7bcf42e72736cdb1de33d344f5da593
v1.0
complete
Code_Contests
Code_Contests_23465_C
import heapq from typing import List, Tuple def dijkstra(graph, start, end): pq = [(0, start)] distances = {start: 0} while pq: current_distance, current_vertex = heapq.heappop(pq) if current_vertex == end: return current_distance for neighbor, weig...
import heapq def dijkstra(graph, start, end): """ Finds the shortest path in a weighted directed graph using Dijkstra's algorithm. """ pq = [(0, start)] distances = {start: 0} while pq: current_distance, current_vertex = heapq.heappop(pq) if current_vertex == end: ...
def test_no_mandatory_stops(): n, m, k = 5, 5, 0 edges = [ (1, 2, 2), (2, 3, 2), (3, 4, 2), (4, 5, 2), (1, 5, 10) ] mandatory_stops = [] s, t = 1, 5 assert shortest_path(n, m, k, edges, mandatory_stops, s, t) == 8 def test_with_mandatory_stops(): n, m...
[ { "docstring": "Finds the shortest path in a weighted directed graph using Dijkstra's algorithm.", "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": "Builds a graph from a list of edges.", "f...
[ 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 heapq\nfrom collections import defaultdict\n\ndef dijkstra(graph, start):\n distances = {vertex: float('infinity') for vertex in graph}\n dist...
trial_gpt4o_9
{ "original_instruction": "You are given a directed weighted graph with n vertices and m edges. The weights of the edges can be any positive integer. You are also given two integers s and t representing the starting and ending vertices respectively. Your task is to find the shortest path from vertex s to vertex t.\n\...
0.628176
Code_Contests_23465
C
[ "dijkstra", "build_graph", "shortest_path" ]
3
[ [ "shortest_path", "build_graph" ], [ "shortest_path", "dijkstra" ] ]
2
[]
false
[]
false
pytest
false
[]
true
8bb6cebf70bbdbb918a474b835a029d8c21f806d
ed6d1eaac91ae8c60e2c29b98dff78aab0fec13f
v1.0
complete
Code_Contests
Code_Contests_23659_C
def update_add(array, x, y): """ Add y to the element at index x-1 of the array. """ pass def update_multiply(array, x, y): """ Multiply the element at index x-1 of the array by y. """ pass def find_kth_smallest(array, l, r, k): """ Find the k-th smallest element in the subarra...
def update_add(array, x, y): """ Add y to the element at index x-1 of the array. """ array[x-1] += y def update_multiply(array, x, y): """ Multiply the element at index x-1 of the array by y. """ array[x-1] *= y def find_kth_smallest(array, l, r, k): """ Find the k-th smallest ...
import pytest from solution import update_add, update_multiply, find_kth_smallest, process_operations def test_update_add(): arr = [5, 3, 8, 6, 2, 1] update_add(arr, 2, 2) assert arr == [5, 5, 8, 6, 2, 1] def test_update_multiply(): arr = [5, 3, 8, 6, 2, 1] update_add(arr, 2, 2) update_multipl...
[ { "docstring": "Add y to the element at index x-1 of the array.", "function_declaration": "def update_add(array, x, y):", "function_name": "update_add", "parameter_list": "(array, x, y)" }, { "docstring": "Multiply the element at index x-1 of the array by y.", "function_declaration": "de...
[ 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 update_add(array, x, y):\n \"\"\"\n Add y to the element at index x-1 of the array.\n \"\"\"\n array[x-1] += y\n\ndef update_multiply(array...
trial_gpt4o_0
{ "original_instruction": "Alice loves playing with arrays. She has an array of integers and she likes to modify it using multiple operations. The operations can be of three types:\n\n1. \"1 x y\" — add y to the element at index x of the array.\n2. \"2 x y\" — multiply the element at index x of the array by y.\n3. \"...
0.666337
Code_Contests_23659
C
[ "update_add", "update_multiply", "find_kth_smallest", "process_operations" ]
4
[ [ "process_operations", "find_kth_smallest" ], [ "process_operations", "update_add" ], [ "process_operations", "update_multiply" ] ]
3
[]
false
[]
false
pytest
true
[]
true
175ea3278894d3b1aade51e826a57a32dd7b294a
0e062649187c08afa008e0b7f27d9687aa64baf0
v1.0
complete
Code_Contests
Code_Contests_24307_C
def is_there_a_bridge(n: int, m: int, roads: List[Tuple[int, int]]) -> str: """ Determine if there is any bridge in the city's road network. Args: n (int): The number of intersections. m (int): The number of roads. roads (List[Tuple[int, int]]): List of roads where each road is repr...
import sys sys.setrecursionlimit(200000) def find_bridges(n, m, edges): from collections import defaultdict def dfs(node, parent, discovery, low, graph, visited, disc_time, bridges): visited[node] = True discovery[node] = low[node] = disc_time[0] disc_time[0] += 1 for neighbor...
def test_example_1(): n, m = 4, 5 roads = [ (1, 2), (2, 3), (2, 4), (3, 4), (4, 1) ] assert is_there_a_bridge(n, m, roads) == "NO" def test_example_2(): n, m = 4, 3 roads = [ (1, 2), (2, 3), (3, 4) ] assert is_there_a_bridg...
[ { "docstring": null, "function_declaration": "def find_bridges(n, m, edges):", "function_name": "find_bridges", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def is_there_a_bridge(n, m, roads):", "function_name": "is_there_a_bridge", "paramete...
[ 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 find_bridges(n, m, edges):\n from collections import defaultdict\n \n graph = defaultdict(list)\n for u, v in edges:\n graph[u].appe...
trial_gpt4o_2
{ "original_instruction": "There is a city with n intersections and m bi-directional roads connecting these intersections. The city planning committee needs to ensure that it's still possible to travel between any two intersections even if one road needs to be closed for maintenance. To help them, you need to find ou...
0.646318
Code_Contests_24307
C
[ "find_bridges", "is_there_a_bridge" ]
2
[ [ "is_there_a_bridge", "find_bridges" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1beb54bc647c5b7ef1fa496bafea58e5699c2e02
5d395e2fb640d66c3d431e9b19f0c7af945ba895
v1.0
complete
Code_Contests
Code_Contests_22580_C
from typing import List, Tuple def solve(n: int, values: List[int], edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ You are given a rooted tree with n nodes. The tree is rooted at node 1. Each node has a value assigned to it, and the value of node i is denoted by a_i. Your task is t...
from collections import defaultdict, deque def build_tree(n, edges): tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) return tree def preprocess_ancestors(n, tree): parent = [-1] * (n + 1) depth = [0] * (n + 1) log = 1 while (1 << log) <= n: ...
def test_find_ancestors(): n = 7 q = 6 values = [1, 2, 3, 4, 5, 6, 7] edges = [ (1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), ] queries = [ (4, 1), (4, 2), (4, 3), (7, 2), (6, 1), (1, 0), ] ...
[ { "docstring": null, "function_declaration": "def build_tree(n, edges):", "function_name": "build_tree", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def preprocess_ancestors(n, tree):", "function_name": "preprocess_ancestors", "parameter_list":...
[ 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 collections import deque, defaultdict\nimport sys\n\nsys.setrecursionlimit(200000)\n\ndef find_kth_ancestor(tree, values, u, k, parent, depth):\n i...
trial_gpt4o_2
{ "original_instruction": "You are given a rooted tree with n nodes. The tree is rooted at node 1. Each node has a value assigned to it, and the value of node i is denoted by a_i. Your task is to answer q queries of the following type:\n\nFor each query, given a node u and an integer k, find the k-th ancestor of node...
0.68855
Code_Contests_22580
C
[ "build_tree", "preprocess_ancestors", "find_kth_ancestor", "solve" ]
4
[ [ "solve", "build_tree" ], [ "solve", "find_kth_ancestor" ], [ "solve", "preprocess_ancestors" ] ]
3
[]
false
[]
false
pytest
false
[]
true
ecb813ea696690159707f1ca4b10e8f5872ec09a
e16b49718f07c4377b19f59d9ddba857e2abd48d
v1.0
complete
Code_Contests
Code_Contests_24424_C
from typing import List def count_primes(test_cases: List[int]) -> List[int]: """ For each test case, count the number of prime numbers less than or equal to X. >>> count_primes([10, 14, 18]) [4, 6, 7] >>> count_primes([1]) [0] >>> count_primes([2, 3, 5, 7]) [1, 2, 3, 4] >>> count_...
def sieve(n): """ Uses the Sieve of Eratosthenes to find all prime numbers less than or equal to n """ 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_count = [...
from solution import count_primes def test_with_small_numbers(): assert count_primes([10, 14, 18]) == [4, 6, 7] def test_with_edge_case_1(): assert count_primes([1]) == [0] def test_with_prime_edge_cases(): assert count_primes([2, 3, 5, 7]) == [1, 2, 3, 4] def test_with_large_numbers(): assert count...
[ { "docstring": "Uses the Sieve of Eratosthenes to find all prime numbers less than or equal to n ", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "For each test case, count the number of prime numbers less than or equal to X", ...
[ 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 sieve_of_eratosthenes(max_num):\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is_prime[1] = False\n p = 2\n while (p * p <= max_num):...
trial_gpt4o_1
{ "original_instruction": "Mihai loves prime numbers and recently came across an interesting problem. He wishes to find out the number of prime numbers that are less than or equal to a given number X. Being a Computer Science student, Mihai decided to write a program to solve this.\n\nThe problem is defined as follow...
0.794429
Code_Contests_24424
C
[ "sieve", "count_primes" ]
2
[ [ "count_primes", "sieve" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b50e6061652a2853597c19a16706fa5f199ff11
03972fa36027700406fd70c78be672e294a909d2
v1.0
complete
Code_Contests
Code_Contests_24297_C
from typing import List def sieve_of_eratosthenes(limit: int) -> List[int]: """Generate a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.""" is_prime = [True] * (limit + 1) p = 2 while p * p <= limit: if is_prime[p]: for i in range(p * p, limit...
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if is_prime[p]: for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 prime_numbers = [] for p in range(2, limit + 1): if is_prime[p]: ...
from solution import find_longest_sequence def test_find_longest_sequence_case1(): result = find_longest_sequence(100, 2) assert set(result) == set([2, 3, 5, 7]) def test_find_longest_sequence_case2(): result = find_longest_sequence(500, 3) # Either [2, 3, 5] or [2, 11] are acceptable answers asse...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def find_longest_sequence(n, k):", "function_name": "find_longest_sequence", "p...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Implements the Sieve of Eratosthenes to find all prime numbers up to max_num.\n \"\"\"\n sieve =...
trial_gpt4o_8
{ "original_instruction": "Professor Quantum is building a new encryption system based on a sequence of prime numbers. He defines an encoded message as the sum of the k-th powers of distinct prime numbers, where k is a given integer.\n\nGiven an integer n, find the longest possible sequence of distinct prime numbers ...
0.603502
Code_Contests_24297
C
[ "sieve_of_eratosthenes", "find_longest_sequence" ]
2
[ [ "find_longest_sequence", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ca4cb680b4fcdb23acb44215234b0e058fcc747
4633557a35fc076aa0a6209df411129b1bfff2d3
v1.0
complete
Code_Contests
Code_Contests_24188_C
def sort_books(test_cases): result = [] for books in test_cases: sorted_books = sorted(books, key=lambda x: (x[2], x[1], x[0])) result.append(sorted_books) return result def process_input(input_data): lines = input_data.strip().split("\n") index = 0 T = int(lines[index]) ind...
def sort_books(test_cases): result = [] for books in test_cases: sorted_books = sorted(books, key=lambda x: (x[2], x[1], x[0])) result.append(sorted_books) return result def process_input(input_data): lines = input_data.strip().split("\n") index = 0 T = int(lines[index]) ind...
from solution import librarian_program def test_case_1(): input_data = "2\n3\nWarAndPeace Tolstoy 1869\nPrideAndPrejudice Austen 1813\nAnnaKarenina Tolstoy 1877\n4\nTheGreatGatsby Fitzgerald 1925\nMobyDick Melville 1851\nTheCatchInTheRye Salinger 1951\nToKillAMockingbird Lee 1960" expected_output = "PrideAndPr...
[ { "docstring": null, "function_declaration": "def sort_books(test_cases):", "function_name": "sort_books", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", "parameter_list": "(inpu...
[ 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 sort_books(T, cases):\n \"\"\"\n Sort the books according to the specified rules and return the sorted list for each test case.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "Write a program that assists a librarian in sorting a collection of books. Each book in the collection has a title, an author, and a year of publication.\n\nYou are required to sort the books primarily by the year of publication in ascending order. If two or more books are published in the ...
0.551422
Code_Contests_24188
C
[ "sort_books", "process_input", "format_output", "librarian_program" ]
4
[ [ "librarian_program", "format_output" ], [ "librarian_program", "process_input" ], [ "librarian_program", "sort_books" ] ]
3
[ "process_input", "format_output" ]
false
[]
false
pytest
true
[]
true
397bfc8a35a5e3bdd4f9651003820db50afe601e
c0ca2dfb1a30269c93efdf933bc33daae32858e5
v1.0
complete
Code_Contests
Code_Contests_23340_C
def shift_char(c: str, shift: int) -> str: """ Shift a single character by the given shift value, wrapping around the alphabet if necessary. Non-alphabetic characters remain unchanged. """ ... def process_message(directive: str, shift_value: int, message: str) -> str: """ Encode or decode a message...
def shift_char(c, shift): if c.isalpha(): base = ord('a') if c.islower() else ord('A') return chr((ord(c) - base + shift) % 26 + base) return c def process_message(directive, shift_value, message): if directive == "DECODE": shift_value = -shift_value return ''.join(shift_char(c,...
from solution import process_input, process_message def test_process_message(): assert process_message("ENCODE", 2, "Hello, World!") == "Jgnnq, Yqtnf!" assert process_message("DECODE", 2, "Jgnnq, Yqtnf!") == "Hello, World!" assert process_message("ENCODE", -2, "Jgnnq, Yqtnf!") == "Hello, World!" assert...
[ { "docstring": null, "function_declaration": "def shift_char(c, shift):", "function_name": "shift_char", "parameter_list": "(c, shift)" }, { "docstring": null, "function_declaration": "def process_message(directive, shift_value, message):", "function_name": "process_message", "pa...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shift_character(c, shift):\n if 'a' <= c <= 'z':\n return chr((ord(c) - ord('a') + shift) % 26 + ord('a'))\n elif 'A' <= c <= 'Z':\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a string of characters that represent an encoded message. The encoding mechanism works by shifting each character in the message a certain number of places down the Unicode table. We call this the \"shift value.\" For example, if the shift value is 2, 'a' becomes 'c', 'b' beco...
0.759482
Code_Contests_23340
C
[ "shift_char", "process_message", "process_input" ]
3
[ [ "process_input", "process_message" ], [ "process_message", "shift_char" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
e15d4f972582fc0ab458e65053dd113c9fa22fc3
155edc0e1bf35d8c16fdddc5c410021697c8d6f2
v1.0
complete
Code_Contests
Code_Contests_24641_C
import re from typing import List def validate_email(email: str) -> bool: """ Validates a single email address based on the criteria provided. >>> validate_email("john.doe@example.com") True >>> validate_email("user@domain") False """ pass def validate_emails(emails: List[str]) ->...
import re def validate_email(email): """ Validates a single email address based on the criteria provided. """ email_regex = re.compile( r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$" ) return bool(email_regex.match(email)) def validate_emails(emails): """ Takes a list of ...
import pytest from solution import validate_email, validate_emails def test_validate_email(): assert validate_email("john.doe@example.com") == True assert validate_email("jane_doe@sub.domain.co.uk") == True assert validate_email("user@domain") == False assert validate_email("user@domain.toolongtld") ==...
[ { "docstring": "Validates a single email address based on the criteria provided.", "function_declaration": "def validate_email(email):", "function_name": "validate_email", "parameter_list": "(email)" }, { "docstring": "Takes a list of email addresses and returns a list of 'Valid' or 'Invalid...
[ 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 re\n\ndef is_valid_email(email):\n \"\"\"\n Validates an email address based on specific criteria.\n \"\"\"\n # Define the regular expre...
trial_gpt4o_2
{ "original_instruction": "A valid email address is composed of a local part, an \"@\" symbol, and a domain part:\n\n- The local part may contain uppercase and lowercase letters, digits, and the characters: `.`, `-`, `_`.\n- The domain part is a sequence of characters divided into two or more segments by dots (`.`). ...
0.638339
Code_Contests_24641
C
[ "validate_email", "validate_emails" ]
2
[ [ "validate_emails", "validate_email" ] ]
1
[]
false
[]
false
pytest
true
[]
true
34e1176c82e6020414894309a74ce202cf1cd9b2
120bb66c6add41f2c236b95d81eaf271c6821540
v1.0
complete
Code_Contests
Code_Contests_24658_C
def digit_shadow(n): """ Calculate the shadow of a number. >>> digit_shadow(123) == 1**1 + 2**2 + 3**3 == 1 + 4 + 27 == 32 >>> digit_shadow(89) == 8**1 + 9**2 == 8 + 81 == 89 >>> digit_shadow(1) == 1**1 == 1 >>> digit_shadow(10) == 1**1 + 0**2 == 1 """ pass def count_shadow_perfect(L, R...
def digit_shadow(n): """ Calculate the shadow of a number. """ return sum(int(digit)**(pos+1) for pos, digit in enumerate(str(n))) def count_shadow_perfect(L, R): """ Count the number of shadow-perfect numbers in the range [L, R]. """ count = 0 for number in range(L, R+1): i...
from solution import digit_shadow, count_shadow_perfect def test_digit_shadow(): assert digit_shadow(123) == 1**1 + 2**2 + 3**3 == 1 + 4 + 27 == 32 assert digit_shadow(89) == 8**1 + 9**2 == 8 + 81 == 89 assert digit_shadow(1) == 1**1 == 1 assert digit_shadow(10) == 1**1 + 0**2 == 1 def test_count_...
[ { "docstring": "Calculate the shadow of a number.", "function_declaration": "def digit_shadow(n):", "function_name": "digit_shadow", "parameter_list": "(n)" }, { "docstring": "Count the number of shadow-perfect numbers in the range [L, R].", "function_declaration": "def count_shadow_perf...
[ 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 digit_power_sum(n):\n \"\"\"\n Calculate the sum of digits powered by their respective positions for n.\n \"\"\"\n return sum(int(digit) **...
trial_gpt4o_2
{ "original_instruction": "Sophia is a budding mathematician and she enjoys playing with numbers. One day, she came up with an interesting problem involving numbers and their digits. She defines the \"shadow\" of a number as the sum of all the digits of the number raised to the power of their respective positions (1-...
0.581871
Code_Contests_24658
C
[ "digit_shadow", "count_shadow_perfect" ]
2
[ [ "count_shadow_perfect", "digit_shadow" ] ]
1
[]
false
[]
false
pytest
true
[]
true
690ff76140e4067e46086e971572059da53d9289
291e6b7d8d54d050cec0270a7f130fe55bd237fe
v1.0
complete
Code_Contests
Code_Contests_24415_C
def largest_rectangle_area(rectangles): """ Calculate the area of the largest rectangle that can be formed using one or multiple overlapping or touching plots. :param rectangles: List of tuples (x1, y1, x2, y2) :return: The area of the largest rectangle Examples: >>> largest_rectangle_area(...
def largest_rectangle_area(rectangles): """ Calculate the area of the largest rectangle that can be formed using one or multiple overlapping or touching plots. :param rectangles: List of tuples (x1, y1, x2, y2) :return: The area of the largest rectangle """ if not rectangles: return ...
from solution import largest_rectangle_area def test_single_small_rectangle(): assert largest_rectangle_area([(0, 0, 2, 2)]) == 4 def test_multiple_overlapping_rectangles(): assert largest_rectangle_area([(0, 0, 3, 2), (2, 1, 4, 3)]) == 6 def test_multiple_adjacent_rectangles_horizontal(): assert largest...
[ { "docstring": "Calculate the area of the largest rectangle that can be formed\nusing one or multiple overlapping or touching plots.\n:param rectangles: List of tuples (x1, y1, x2, y2)\n:return: The area of the largest rectangle", "function_declaration": "def largest_rectangle_area(rectangles):", "funct...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_rectangle_area(N, plots):\n # Create an empty grid of size 1001x1001\n grid = [[0] * 1001 for _ in range(1001)]\n \n # Fill the gri...
trial_gpt4o_2
{ "original_instruction": "Given a set of $N$ axis-aligned rectangular plots, find the area of the largest rectangle that can be formed using one or multiple overlapping or touching plots.\n\nConstraints\n\n* $ 1 \\leq N \\leq 100000 $\n* $ 0 \\leq x1_i < x2_i \\leq 1000 $\n* $ 0 \\leq y1_i < y2_i \\leq 1000 $\n* $ x...
0.728598
Code_Contests_24415
C
[ "largest_rectangle_area", "largest_rectangle_in_histogram" ]
2
[ [ "largest_rectangle_area", "largest_rectangle_in_histogram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8c00549d713743471b60d736111bb12b8f926918
6046a267e705e90b80c84e7d6d0a0fb8d34fe6d5
v1.0
complete
Code_Contests
Code_Contests_24926_C
def reverse_and_check_prime(n: int) -> bool: """ Reverses the digits of an integer and determines if the result is a prime number. >>> reverse_and_check_prime(13) True >>> reverse_and_check_prime(37) True >>> reverse_and_check_prime(123) False >>> reverse_and_check_prime(2) True ...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for i in range(3, max_divisor, 2): if n % i == 0: return False ...
def test_reverse_and_check_prime(): # Test case 1: Reversing 13 gives 31, which is prime assert reverse_and_check_prime(13) == True # Test case 2: Reversing 37 gives 73, which is prime assert reverse_and_check_prime(37) == True # Test case 3: Reversing 123 gives 321, which is not prime ass...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Reverses the digits of an integer and checks if the result is a prime number.", "function_declaration": "de...
[ 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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True...
trial_gpt4o_2
{ "original_instruction": "Write a function that will reverse the digits of an integer and determine if the result is a prime number or not. The function should take as input the integer and return True if the reversed integer is a prime, and False otherwise. \n\nA prime number is a natural number greater than 1 that...
0.803806
Code_Contests_24926
C
[ "is_prime", "reverse_and_check_prime" ]
2
[ [ "reverse_and_check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
483b62dc37a349ca0bb2977d7f60471d26ff87b9
b486490552b577c9ad716d9a6ec10070bfe46131
v1.0
complete
Code_Contests
Code_Contests_24225_C
def rotate_90_deg(matrix): """ Rotate the given NxN matrix by 90 degrees clockwise. """ def are_matrices_equivalent(n, A, B): """ Check if matrix B is equivalent to matrix A by rotating it 0, 90, 180, or 270 degrees. Parameters: - n: integer, size of the matrices (1 ≤ n ≤ 50) - A: list...
def rotate_90_deg(matrix): """ Rotate the given NxN matrix by 90 degrees clockwise. """ n = len(matrix) return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)] def are_matrices_equivalent(n, A, B): """ Check if matrix B is equivalent to matrix A by rotating it 0, 90, 180, or 270...
from solution import are_matrices_equivalent def test_matrices_equivalent_example_1(): n = 2 A = [[1, 2], [3, 4]] B = [[4, 3], [2, 1]] assert are_matrices_equivalent(n, A, B) == "YES" def test_matrices_equivalent_example_2(): n = 3 A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[1, 2, 3], [6, ...
[ { "docstring": "Rotate the given NxN matrix by 90 degrees clockwise.", "function_declaration": "def rotate_90_deg(matrix):", "function_name": "rotate_90_deg", "parameter_list": "(matrix)" }, { "docstring": "Check if matrix B is equivalent to matrix A by rotating it 0, 90, 180, or 270 degrees...
[ 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 rotate_90(matrix):\n \"\"\"\n Rotates the given square matrix by 90 degrees clockwise.\n \"\"\"\n n = len(matrix)\n return [[matrix[n - ...
trial_gpt4o_1
{ "original_instruction": "In a distant galaxy, there is a highly secure vault protected by a series of magical locks. Each lock is controlled by a distinct key matrix. The key matrices are square matrices of integers, and two matrices \\(A\\) and \\(B\\) are deemed equivalent if one can be transformed into the other...
0.517895
Code_Contests_24225
C
[ "rotate_90_deg", "are_matrices_equivalent" ]
2
[ [ "are_matrices_equivalent", "rotate_90_deg" ] ]
1
[]
false
[]
false
pytest
true
[]
true
317d002535a1e1ed5d09ac80441c2f12eb893e63
d98f0e5006e3b64ff33a817204b92c7bdf750fb9
v1.0
complete
Code_Contests
Code_Contests_24967_C
def rotations_from_inorder(n: int, A: List[int], B: List[int]) -> Union[int, Tuple[int, List[str]]]: """ Find the sequence of rotations to transform one BST (in-order traversal A) into another BST (in-order traversal B). >>> rotations_from_inorder(3, [1, 2, 3], [3, 1, 2]) [2, ["Left 1", "Left 2"]] >>> r...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def build_tree_from_inorder(inorder): if not inorder: return None def build_tree(in_index_map, start, end): if start > end: return None root_val = next(it...
from solution import rotations_from_inorder def test_rotations_simple_case(): n, A, B = 3, [1, 2, 3], [3, 1, 2] result = rotations_from_inorder(n, A, B) assert result == -1 def test_rotations_complex_case(): n, A, B = 5, [4, 2, 5, 1, 3], [1, 2, 3, 4, 5] result = rotations_from_inorder(n, A, B) ...
[]
[ 0, 0, 1, 0 ]
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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef ...
trial_gpt4o_3
{ "original_instruction": "Alice has recently learned about binary search trees (BST) and is fascinated by their properties. She decides to test her knowledge by solving a problem where she needs to transform one BST into another by performing rotations.\n\nA single rotation in a BST involves changing the parent-chil...
0.493164
Code_Contests_24967
C
[ "build_tree_from_inorder", "convert_tree_to_inorder", "find_rotation_sequence", "rotations_from_inorder", "calculate_rotations" ]
5
[ [ "calculate_rotations", "rotations_from_inorder" ], [ "find_rotation_sequence", "build_tree_from_inorder" ], [ "find_rotation_sequence", "convert_tree_to_inorder" ], [ "rotations_from_inorder", "find_rotation_sequence" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
a894172cf34bc67e31a2001a46c38a22316636e8
674a07925a1f51d2f95a559816667739f4ff3b18
v1.0
complete
Code_Contests
Code_Contests_25027_C
from typing import List def is_palindrome(num: int) -> bool: """ Check if a number is palindrome. >>> is_palindrome(121) True >>> is_palindrome(123) False """ pass def find_smallest_palindrome_greater_or_equal(N: int) -> int: """ Find the smallest palindrome number greater...
def is_palindrome(num): """ Check if a number is palindrome. """ s = str(num) return s == s[::-1] def find_smallest_palindrome_greater_or_equal(N): """ Find the smallest palindrome number greater than or equal to N. """ current_num = N while True: if is_palindrome(curren...
from solution import is_palindrome, find_smallest_palindrome_greater_or_equal def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(1221) == True def test_find_smallest...
[ { "docstring": "Check if a number is palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Find the smallest palindrome number greater than or equal to N.", "function_declaration": "def find_smalles...
[ 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_palindrome(n):\n \"\"\"\n Utility function to check if a number is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef s...
trial_gpt4o_2
{ "original_instruction": "Iroha loves palindrome numbers. A palindrome number reads the same backward as forward, for example, 121 or 12321.\n\nShe has a number N and would like to find the smallest palindrome number greater than or equal to N. \n\nConstraints\n\n* 1 ≦ N < 100000\n\nInput\n\nThe input is given from ...
0.733897
Code_Contests_25027
C
[ "is_palindrome", "find_smallest_palindrome_greater_or_equal" ]
2
[ [ "find_smallest_palindrome_greater_or_equal", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4a1bd259ab91f81259ae4fcde65c9d12d1be8dec
72572620503c0718dd27b5d9fde18a96980655d6
v1.0
complete
Code_Contests
Code_Contests_24383_C
def can_form_palindrome(s: str) -> bool: """ Check if a string can be rearranged to form a palindrome. """ def process_strings(t: int, strings: List[str]) -> List[str]: """ For multiple strings, determine if each can be rearranged to form a palindrome. """ # Test cases def test_can_form_palind...
def can_form_palindrome(s): """ Check if a string can be rearranged to form a palindrome. """ from collections import Counter char_count = Counter(s) odd_count = sum(1 for count in char_count.values() if count % 2 != 0) return odd_count <= 1 def process_strings(t, strings): """ For ...
from solution import can_form_palindrome, process_strings def test_can_form_palindrome(): assert can_form_palindrome("aabb") == True assert can_form_palindrome("racecar") == True assert can_form_palindrome("abcd") == False assert can_form_palindrome("a") == True assert can_form_palindrome("abcdef")...
[ { "docstring": "Check if a string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "For multiple strings, determine if each can be rearranged to form a palindrome...
[ 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 can_be_rearranged_to_palindrome(s):\n \"\"\"\n Determine if a string can be rearranged to form a palindrome.\n \n A string can be rearrange...
trial_gpt4o_1
{ "original_instruction": "Alice likes to collect and arrange strings of the same length but wants them to look nice. A string looks \"nice\" if it is a palindrome or can be rearranged to form a palindrome. \n\nA palindrome is a string that reads the same forwards and backwards. Alice can swap any two characters in t...
0.724325
Code_Contests_24383
C
[ "can_form_palindrome", "process_strings" ]
2
[ [ "process_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69b56ddc483e9b61ea97d683085f187e87be8000
3769272f42518e5e2a9af4c382afb9145eb474b4
v1.0
complete
Code_Contests
Code_Contests_24617_C
from functools import reduce from math import gcd def lcm(a: int, b: int) -> int: """ Calculate the least common multiple (LCM) of two integers. >>> lcm(3, 5) 15 >>> lcm(4, 6) 12 """ pass def total_lcm(cycles: List[int]) -> int: """ Calculate the LCM of a list of integers. >>> tota...
from math import gcd from functools import reduce def lcm(a, b): return a * b // gcd(a, b) def total_lcm(cycles): return reduce(lcm, cycles) def main(): import sys input = sys.stdin.read data = input().strip().split('\n') N = int(data[0]) cycles = [] for i in range(1, N+1): ...
from solution import lcm, total_lcm def test_lcm(): assert lcm(3, 5) == 15 assert lcm(4, 6) == 12 assert lcm(2, 3) == 6 assert lcm(7, 3) == 21 assert lcm(1, 1) == 1 def test_total_lcm(): assert total_lcm([3, 4, 2, 5, 6]) == 60 assert total_lcm([2, 3, 5]) == 30 assert total_lcm([4, 6]) ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def total_lcm(cycles):", "function_name": "total_lcm", "parameter_list": "(cycles)" }, { "docstring": null, ...
[ 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": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef traffic_lights_sync(n, cycles):\n # Calculate...
trial_gpt4o_5
{ "original_instruction": "You have been assigned the role of a developer in a company responsible for traffic management systems. Your task involves monitoring and managing traffic flows at various intersections.\n\nAt a particular intersection, there are N traffic lights. Each traffic light operates on a fixed cycl...
0.576506
Code_Contests_24617
C
[ "lcm", "total_lcm", "main" ]
3
[ [ "total_lcm", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
794020a9f74ac8f4dd644f8e9be8368f819436d5
3e739292defc5aa1570829b5b92dd0c139925ba5
v1.0
complete
Code_Contests
Code_Contests_24889_C
def minimum_spanning_tree(towns: int, road_data: List[List[int]]) -> int: """ Find the total length of the minimum spanning tree in the given road network. >>> minimum_spanning_tree(5, [[1, 2, 4], [1, 3, 2], [2, 3, 1], [2, 4, 7], [3, 4, 3], [3, 5, 5], [4, 5, 6]]) == 11 >>> minimum_spanning_tree(4, [[1, 2, 1...
import heapq def find(parent, i): """ A function to find the set of an element i (uses path compression technique) """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ A function that does ...
from solution import minimum_spanning_tree def test_mst_example_1(): towns = 5 roads = [ [1, 2, 4], [1, 3, 2], [2, 3, 1], [2, 4, 7], [3, 4, 3], [3, 5, 5], [4, 5, 6] ] assert minimum_spanning_tree(towns, roads) == 11 def test_mst_example_2(): ...
[ { "docstring": "A function to find the set of an element i\n(uses path compression technique)", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "A function that does union of two sets of x and y\n(uses union by rank)"...
[ 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 heapq\n\ndef find(parent, i):\n \"\"\"\n A function to find the set of an element i\n (uses path compression technique)\n \"\"\"\n if...
trial_gpt4o_0
{ "original_instruction": "In the Kingdom of Alpha, there are several towns connected by bidirectional roads that create a network. Each road has a weight representing its length. The King's advisor wants to ensure that the towns are connected in the most efficient way possible, specifically building the minimum span...
0.660329
Code_Contests_24889
C
[ "find", "union", "kruskal_mst", "minimum_spanning_tree" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_spanning_tree", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
2f882f45e3446ae6f33b61660a1b7debc4839f6e
2f7fc49b7e62340ec164ab6b5a1a6a79918720b9
v1.0
complete
Code_Contests
Code_Contests_24567_C
from typing import List import math from functools import reduce def gcd(a: int, b: int) -> int: return math.gcd(a, b) def gcd_of_list(lst: List[int]) -> int: return reduce(gcd, lst) def gcd_of_subarray(arr: List[int], l: int, r: int) -> int: """ Given a list of integers, find the GCD of the subarray spe...
import math from functools import reduce def gcd(a, b): return math.gcd(a, b) def gcd_of_list(lst): return reduce(gcd, lst) def gcd_of_subarray(arr, l, r): subarray = arr[l-1:r] return gcd_of_list(subarray)
from solution import gcd_of_subarray def test_gcd_of_subarray_case1(): arr = [2, 3, 6, 9, 5] assert gcd_of_subarray(arr, 1, 3) == 1 def test_gcd_of_subarray_case2(): arr = [2, 3, 6, 9, 5] assert gcd_of_subarray(arr, 2, 5) == 1 def test_gcd_of_subarray_case3(): arr = [2, 3, 6, 9, 5] assert gcd...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def gcd_of_list(lst):", "function_name": "gcd_of_list", "parameter_list": "(lst)" }, { "docstring": null, ...
[ 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 typing import List, Tuple\n\ndef find_gcd_subarray(n: int, arr: List[int], queries: List[Tuple[int, int]]) -> List[int]:\n def gcd(a, ...
trial_gpt4o_2
{ "original_instruction": "Xenny now wants to explore factors and multiples. His latest homework assignment involves working with a list of integers. Given a list, he needs to find the Greatest Common Divisor (GCD) of all elements in a particular range specified by two indices in the list. This time, Xenny is busy wi...
0.615679
Code_Contests_24567
C
[ "gcd", "gcd_of_list", "gcd_of_subarray" ]
3
[ [ "gcd_of_list", "gcd" ], [ "gcd_of_subarray", "gcd_of_list" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8a0ca850e1e973d68f2bb3745a75ee57317048ef
d90c2e33ec3b6e16443a8971648204d6b7d6895f
v1.0
complete
Code_Contests
Code_Contests_24913_C
from typing import List, Tuple def sieve_primes_upto(limit: int) -> set: """Returns a set of all primes up to the specified limit.""" is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime...
def sieve_primes_upto(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 is_prime[0], is_prime[1] = False, False # 0 and 1 are not prime numbers p...
from solution import sum_of_unique_primes def test_case_1(): arr = [2, 3, 4, 5, 6] queries = [(1, 3), (2, 4), (1, 5)] result = sum_of_unique_primes(arr, queries) assert result == [5, 8, 10] def test_case_2(): arr = [10, 15, 21, 25, 30] queries = [(1, 3), (3, 5), (1, 5)] result = sum_of_uni...
[ { "docstring": null, "function_declaration": "def sieve_primes_upto(limit):", "function_name": "sieve_primes_upto", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def sum_of_unique_primes(arr, queries):", "function_name": "sum_of_unique_primes", "par...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\" Returns a list of all primes <= max_num \"\"\"\n is_prime = [True] * (max_num + 1)\n is_prime[0] = is...
trial_gpt4o_2
{ "original_instruction": "You are given an array of N integers and Q queries. Each query consists of two indices L and R. For each query, you need to return the sum of all the unique prime numbers in the subarray from L to R (inclusive). Implement a function to handle the queries efficiently.\n\nInput:\n- The first ...
0.681805
Code_Contests_24913
C
[ "sieve_primes_upto", "sum_of_unique_primes" ]
2
[ [ "sum_of_unique_primes", "sieve_primes_upto" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f867fef54898887cb356dcc88ae76a6b0730aa5d
ef47ff2d4a734b6f73b8ad7fc5a2a40f15a98bf8
v1.0
complete
Code_Contests
Code_Contests_25149_C
def most_frequent_digit(sequences: List[str]) -> List[str]: """ For each sequence in the list, returns the most frequently occurring digit. If there is a tie, returns the smallest digit among them. >>> most_frequent_digit(["122333444455555"]) == ["5"] >>> most_frequent_digit(["9876543210 122333"]) ...
def most_frequent_digit(sequences): """ For each sequence in the list, returns the most frequently occurring digit. If there is a tie, returns the smallest digit among them. """ results = [] for sequence in sequences: digit_counts = [0] * 10 for char in sequence: if c...
from solution import most_frequent_digit def test_most_frequent_digit(): sequences = [ "122333444455555", "9876543210 122333", "000111222 333444 555666" ] expected_output = ["5", "3", "0"] assert most_frequent_digit(sequences) == expected_output def test_tied_frequencies(): ...
[ { "docstring": "For each sequence in the list, returns the most frequently occurring digit.\nIf there is a tie, returns the smallest digit among them.", "function_declaration": "def most_frequent_digit(sequences):", "function_name": "most_frequent_digit", "parameter_list": "(sequences)" }, { ...
[ 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": "def most_frequent_digit(sequences):\n \"\"\"\n Given a list of numeric code sequences, return the most frequently occurring digit in each sequence.\n...
trial_gpt4o_3
{ "original_instruction": "You are reading an ancient manuscript which contains numeric code sequences. The codes are represented as strings of digits, separated by spaces. You suspect that each sequence contains an embedded message, based on the frequency of digits in the sequence.\n\nYour task is to determine the m...
0.621009
Code_Contests_25149
C
[ "most_frequent_digit", "process_input_and_find_most_frequent" ]
2
[ [ "process_input_and_find_most_frequent", "most_frequent_digit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3ee6b92d4a160a04cb8df52276d85f4156fba268
d9d9b582604e226bb1d9b151c123f05ca68ed7f4
v1.0
complete
Code_Contests
Code_Contests_24895_C
def find_scc_count(n: int, m: int, edges: List[Tuple[int, int]]) -> int: """ Find the number of strongly connected components (SCCs) in a directed graph with N nodes and M edges. Parameters ---------- n : int Number of nodes in the graph m : int Number of edges in the graph ...
from collections import defaultdict, deque def kosaraju_scc_count(n, edges): def dfs(v, graph, visited, stack=None, component=None): visited[v] = True if component is not None: component.append(v) for neighbour in graph[v]: if not visited[neighbour]: ...
def test_find_scc_count_example(): n = 5 m = 5 edges = [ (1, 2), (2, 3), (3, 1), (4, 5), (5, 4) ] assert find_scc_count(n, m, edges) == 2 def test_find_scc_count_no_edges(): n = 5 m = 0 edges = [] assert find_scc_count(n, m, edges) == 5 # Ea...
[ { "docstring": null, "function_declaration": "def kosaraju_scc_count(n, edges):", "function_name": "kosaraju_scc_count", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def find_scc_count(n, m, edges):", "function_name": "find_scc_count", "paramete...
[ 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\n\ndef kosaraju_scc_count(n, edges):\n def dfs(v, graph, visited, stack=None, component=None):\n visit...
trial_gpt4o_0
{ "original_instruction": "You are given a directed graph with $N$ nodes and $M$ edges. Find the number of strongly connected components (SCCs) in the graph.\n\n### Constraints\n* $1 \\leq N \\leq 10^5$\n* $1 \\leq M \\leq 10^5$\n\n### Input\nThe input is given in the following format:\n\n$N$ $M$\n\nNext $M$ lines, e...
0.577271
Code_Contests_24895
C
[ "kosaraju_scc_count", "find_scc_count" ]
2
[ [ "find_scc_count", "kosaraju_scc_count" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2e816a1a5ad3a6dd8e52ae95e64921ebb188a8d1
665759191d1a5341d8f9e875d94a8c3c261196ba
v1.0
complete
Code_Contests
Code_Contests_25035_C
from typing import Tuple def final_position(commands: str) -> Tuple[int, int]: """ Takes a string of commands and returns the final position of the robotic arm. >>> final_position("UURDDLLR") (0, 0) >>> final_position("UUDDLRLR") (0, 0) >>> final_position("LLLL") (-4, 0) >>> final_posit...
def final_position(commands): """ Takes a string of commands and returns the final position of the robotic arm. Parameters: commands (str): A string containing the commands executed by the robotic arm Returns: tuple: A tuple of two integers representing the final coordinates """ ...
from solution import final_position def test_final_position_uurrddllr(): assert final_position("UURDDLLR") == (0, 0) def test_final_position_uuddlrlr(): assert final_position("UUDDLRLR") == (0, 0) def test_final_position_llll(): assert final_position("LLLL") == (-4, 0) def test_final_position_uuuuu(): ...
[ { "docstring": "Takes a string of commands and returns the final position of the robotic arm.\n\nParameters:\ncommands (str): A string containing the commands executed by the robotic arm\n\nReturns:\ntuple: A tuple of two integers representing the final coordinates", "function_declaration": "def final_posit...
[ 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 final_position(commands):\n \"\"\"\n Takes a string of commands and returns the final position of the robotic arm.\n \n Parameters:\n co...
trial_gpt4o_0
{ "original_instruction": "A robotics company is designing a new robotic arm that can move in a 2D grid. The robotic arm starts at the origin point (0,0) and can move in four directions: up, down, left, and right. Each move is represented by a command in a string, where 'U' means up, 'D' means down, 'L' means left, a...
0.510197
Code_Contests_25035
C
[ "final_position", "print_final_position" ]
2
[ [ "print_final_position", "final_position" ] ]
1
[]
false
[]
false
pytest
true
[]
true
02d3053bddd4028c7948be677de2127fceb58516
6a77a55efe8d1259795a51cc8ebe5785ccc5d49f
v1.0
complete
Code_Contests
Code_Contests_24407_C
def gcd(x, y): """Compute the greatest common divisor of x and y.""" while y: x, y = y, x % y return x def simplify_fraction(numerator, denominator): """Simplify a fraction given the numerator and denominator. Args: numerator (int): The numerator of the fraction. denomi...
def gcd(x, y): while y: x, y = y, x % y return x def simplify_fraction(numerator, denominator): gcd_value = gcd(numerator, denominator) return f"{numerator // gcd_value}/{denominator // gcd_value}" def process_fractions(input_data): results = [] for data in input_data.strip().split("\n...
import pytest from solution import simplify_fraction, process_fractions def test_gcd(): assert gcd(48, 18) == 6 assert gcd(8, 24) == 8 assert gcd(25, 100) == 25 def test_simplify_fraction(): assert simplify_fraction(8, 24) == "1/3" assert simplify_fraction(25, 100) == "1/4" assert simplify_fra...
[ { "docstring": null, "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def simplify_fraction(numerator, denominator):", "function_name": "simplify_fraction", "parameter_list": "(numerator,...
[ 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 sys\nfrom math import gcd\n\ndef simplify_fraction(numerator, denominator):\n \"\"\"\n Returns the simplified form of a fraction given the num...
trial_gpt4o_2
{ "original_instruction": "A simplified fraction is a fraction that is reduced to its simplest form. Given two positive integers, a numerator and a denominator of a fraction, return the simplified fraction. You can assume that the initial numerator and denominator are positive integers that do not exceed 1000.\n\nInp...
0.72816
Code_Contests_24407
C
[ "gcd", "simplify_fraction", "process_fractions" ]
3
[ [ "process_fractions", "simplify_fraction" ], [ "simplify_fraction", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
be53097bb944bed7ecbbeaff901bc7383bb127a3
ec65de5fcf244388711b7df1d1f08e2c78a15c93
v1.0
complete
Code_Contests
Code_Contests_25012_C
from typing import List, Tuple def max_flow(n: int, m: int, waterways: List[Tuple[int, int, int]]) -> int: """ Calculates the maximum water flow from the source dam to the sink dam using the capacities of the waterways. >>> max_flow(4, 5, [(1, 2, 100), (1, 3, 100), (2, 4, 50), (3, 4, 50), (2, 3, 50)]) 100 ...
from collections import deque def bfs_capacity(graph, source, sink, parent): """ A BFS for finding the augmenting path in the residual graph. """ visited = [False] * len(graph) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v, capacity i...
def test_simple_case(): n = 4 m = 5 waterways = [ (1, 2, 100), (1, 3, 100), (2, 4, 50), (3, 4, 50), (2, 3, 50) ] assert max_flow(n, m, waterways) == 100 def test_disconnected_case(): n = 4 m = 3 waterways = [ (1, 2, 10), (2, 3, 5) ...
[ { "docstring": "A BFS for finding the augmenting path in the residual graph.", "function_declaration": "def bfs_capacity(graph, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, source, sink, parent)" }, { "docstring": "Calculates the maximum flow from sour...
[ 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 collections import deque\n\ndef bfs_capacity(graph, source, sink, parent):\n \"\"\"\n A BFS for finding the augmenting path in the residual grap...
trial_gpt4o_0
{ "original_instruction": "There is a complex system of waterways and dams called the Vethian River Network (VRN) on planet Vetha. VRN is represented as a directed graph where nodes represent dams, and edges represent waterways with given capacities. The water flows along these waterways from one dam to another. The ...
0.684076
Code_Contests_25012
C
[ "bfs_capacity", "max_flow" ]
2
[ [ "max_flow", "bfs_capacity" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c53aa059a073a1f063506145abba79bf723dc517
4e161376572be197fa9555d7129095266c308e1a
v1.0
complete
Code_Contests
Code_Contests_24924_C
def minimum_modifications(n: int, m: int, grid: List[List[int]]) -> int: """ Given a 2D grid representing a maze, find the minimum number of blocked cells that need to be made open to ensure there is a path from the top-left corner to the bottom-right corner. Args: n (int): number of rows in the grid. ...
from collections import deque import heapq def minCellsToOpenForPath(grid): n = len(grid) m = len(grid[0]) if n == 0 or m == 0: return -1 def is_valid(x, y): return 0 <= x < n and 0 <= y < m directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] # Early exit if initial or final ...
from solution import minimum_modifications def test_example_case(): grid = [ [0, 1, 0], [1, 1, 0], [0, 0, 0] ] assert minimum_modifications(3, 3, grid) == 1 def test_no_modifications_needed(): grid = [ [0, 0, 0], [0, 1, 0], [0, 0, 0] ] assert min...
[ { "docstring": null, "function_declaration": "def minCellsToOpenForPath(grid):", "function_name": "minCellsToOpenForPath", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def minimum_modifications(n, m, grid):", "function_name": "minimum_modifications", ...
[ 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 deque\nimport heapq\n\ndef minCellsToOpenForPath(grid):\n n = len(grid)\n m = len(grid[0])\n if n == 0 or m == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "You are given a 2D grid representing a maze, where each cell can either be open or blocked. The objective is to modify the maze to make it solvable if it's not already. Specifically, you can transform some blocked cells into open cells. Your task is to find the minimum number of blocked cel...
0.664581
Code_Contests_24924
C
[ "minCellsToOpenForPath", "minimum_modifications" ]
2
[ [ "minimum_modifications", "minCellsToOpenForPath" ] ]
1
[]
false
[]
false
pytest
true
[]
true
443225f74bcb83411627d572ba7853bdea7c1159
a69ece5e00501a8a04b721051f256e60014a3d89
v1.0
complete
Code_Contests
Code_Contests_25055_C
import string from typing import List def word_weight(word: str) -> int: """ Calculate the weight of a word based on the sum of the positions of its characters in the alphabet. >>> word_weight('a') 1 >>> word_weight('z') 26 >>> word_weight('abc') 6 >>> word_weight('test') 64 """ def sort_words...
def word_weight(word): """ Calculate the weight of a word based on the sum of the positions of its characters in the alphabet. """ return sum(ord(char) - ord('a') + 1 for char in word) def sort_words_by_weight(phrase): """ Sort the words in the phrase based on their weight in ascending order. ...
from solution import word_weight, sort_words_by_weight, process_phrases def test_word_weight(): assert word_weight('a') == 1 assert word_weight('z') == 26 assert word_weight('abc') == 6 assert word_weight('test') == 64 def test_sort_words_by_weight(): assert sort_words_by_weight('this is a test') ...
[ { "docstring": "Calculate the weight of a word based on the sum of the positions of its characters in the alphabet.", "function_declaration": "def word_weight(word):", "function_name": "word_weight", "parameter_list": "(word)" }, { "docstring": "Sort the words in the phrase based on their we...
[ 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 word_weight(word):\n \"\"\"\n Given a word, return its weight, which is the sum of its characters' positions \n in the alphabet.\n \"\"\"\n...
trial_gpt4o_1
{ "original_instruction": "Title: Weight of the Words\n\nIn a universe where words have weights, each word's weight is calculated as the sum of the weights of its characters. The weight of a character is defined by its position in the alphabet (i.e., 'a' = 1, 'b' = 2, ..., 'z' = 26). Given a phrase, you need to deter...
0.639562
Code_Contests_25055
C
[ "word_weight", "sort_words_by_weight", "process_phrases" ]
3
[ [ "process_phrases", "sort_words_by_weight" ], [ "sort_words_by_weight", "word_weight" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f3ed20f38f118c401c2fb0816f3f18126bbf6a44
b05da0edad9d3bb7d65ef79a14f25ba9d8df1e54
v1.0
complete
Code_Contests
Code_Contests_25082_C
def sieve_of_eratosthenes(max_num: int) -> List[int]: """ Helper function that uses the Sieve of Eratosthenes to find all primes <= max_num """ def multiply_digits(num: int) -> int: """ Helper function that multiplies all digits of a number until a single digit is obtained """ def single_digit_prime_p...
def sieve_of_eratosthenes(max_num): """ Helper function that uses the Sieve of Eratosthenes to find all primes <= max_num """ is_prime = [True] * (max_num + 1) p = 2 while (p * p <= max_num): if (is_prime[p] == True): for i in range(p * p, max_num + 1, p): is_prime[i]...
from solution import single_digit_prime_product, sieve_of_eratosthenes, multiply_digits, process_input def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(15) == [2, 3, 5, 7, 11, 13] assert sieve_of_eratosthenes(7) == [2, 3, 5, 7] def test_multip...
[ { "docstring": "Helper function that uses the Sieve of Eratosthenes to find all primes <= max_num ", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Helper function that multiplies all d...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\" Returns a list of prime numbers up to n using the Sieve of Eratosthenes. \"\"\"\n is_prime = [True] * (n + 1)\...
trial_gpt4o_8
{ "original_instruction": "Grace loves playing with numbers. One day, she came across a sequence of operations involving the properties of prime numbers. She defined a transformation on an integer N, which involves the following steps: \n1. Find all the prime numbers less than or equal to N.\n2. Multiply these prime ...
0.655335
Code_Contests_25082
C
[ "sieve_of_eratosthenes", "multiply_digits", "single_digit_prime_product", "process_input" ]
4
[ [ "process_input", "single_digit_prime_product" ], [ "single_digit_prime_product", "multiply_digits" ], [ "single_digit_prime_product", "sieve_of_eratosthenes" ] ]
3
[ "process_input" ]
false
[]
false
pytest
true
[]
true
719dfa73fe81eee3ca8ea8d0dddd27eb8c3bdf6c
5495fa5346632e4e79a340fd781bf4c2cfe234d2
v1.0
complete
Code_Contests
Code_Contests_24790_C
from typing import List, Tuple def process_tree_cost(n: int, k: int, values: List[int], edges: List[Tuple[int, int]]) -> int: """Calculate the minimum cost required to make the leaf nodes have at least value k. Args: n (int): Number of nodes in the tree. k (int): Minimum required value for lea...
def min_cost_to_leaf_values(n, k, values, edges): from collections import defaultdict, deque tree = defaultdict(list) for u, v in edges: tree[u].append(v) tree[v].append(u) degrees = {i: len(adj) for i, adj in tree.items()} leaf_nodes = [i for i, d in degrees.items() if...
from solution import process_tree_cost def test_example_case(): n, k = 5, 5 values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert process_tree_cost(n, k, values, edges) == 5 def test_all_leaves_have_enough_value(): n, k = 4, 2 values = [2, 2, 2, 2] edges = [(1, 2), (1, 3...
[ { "docstring": null, "function_declaration": "def min_cost_to_leaf_values(n, k, values, edges):", "function_name": "min_cost_to_leaf_values", "parameter_list": "(n, k, values, edges)" }, { "docstring": null, "function_declaration": "def process_tree_cost(n, k, values, edges):", "func...
[ 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": "def min_cost_to_reach_k(n, k, values, edges):\n from collections import defaultdict, deque\n \n # Create adjacency list\n tree = defaultdict(li...
trial_gpt4o_3
{ "original_instruction": "You are given a tree with n nodes and n-1 edges. Each node has an initial value assigned to it.\n\nIn one operation, you can choose any node and increase its value by 1. The cost of this operation is equal to the sum of the current values of its direct children. If the node has no children,...
0.658711
Code_Contests_24790
C
[ "min_cost_to_leaf_values", "process_tree_cost" ]
2
[ [ "process_tree_cost", "min_cost_to_leaf_values" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c4efac63f31752866055573f003b1c735d1e79b
ddb8e252fdeb925036b180b3f3c5a21c2b6ee487
v1.0
complete
Code_Contests
Code_Contests_25037_C
def calculate_max_scores(t: int, test_cases: List[Tuple[Tuple[int, int], List[Tuple[int, int]]]]) -> List[int]: """ Calculate the maximum total score a participant can achieve given a list of problems and their difficulty levels, scores, and the participant's skill level. :param t: Number of test cases...
def max_total_score(test_cases): results = [] for test_case in test_cases: n, l = test_case[0] problems = test_case[1] total_score = 0 for (d, s) in problems: if l >= d: total_score += s results.append(total_score) return results # Functio...
def test_max_total_score(): test_cases = [ [(3, 10), [(5, 80), (10, 100), (3, 50)]], [(4, 5), [(10, 100), (5, 50), (20, 30)]] ] expected_output = [230, 50] assert calculate_max_scores(2, test_cases) == expected_output def test_max_total_score_with_zero_problems(): test_cases = [ ...
[ { "docstring": null, "function_declaration": "def max_total_score(test_cases):", "function_name": "max_total_score", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def calculate_max_scores(t, test_cases):", "function_name": "calculate_max_scores", ...
[ 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_total_score(t, test_cases):\n \"\"\"\n Calculates the maximum total score a participant can achieve.\n \n Parameters:\n t (int): num...
trial_gpt4o_1
{ "original_instruction": "Bob is organizing a programming contest where each participant can solve multiple problems.\n\nEach problem has a difficulty level d and an associated score s. A participant can solve a problem if their skill level, l, is greater than or equal to the difficulty level d of the problem. The p...
0.670089
Code_Contests_25037
C
[ "max_total_score", "calculate_max_scores" ]
2
[ [ "calculate_max_scores", "max_total_score" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5590258a5c2d71b47e305b4f213d38afd36f00b1
9e8e5838cce111b6702d041276b665e2e529626a
v1.0
complete
Code_Contests
Code_Contests_24804_C
import heapq import sys from typing import List, Tuple def dijkstra(N: int, flights: List[Tuple[int, int, int]], starting_city: int) -> List[int]: """ Determines the minimum travel time from the starting city to all other cities in the network. Args: N (int) - The number of cities. flights (List[Tuple[...
import heapq import sys def dijkstra(N, flights, starting_city): adj = {i: [] for i in range(N)} for src, dst, time in flights: adj[src].append((dst, time)) min_time = [sys.maxsize] * N min_time[starting_city] = 0 pq = [(0, starting_city)] while pq: current_time, city...
from solution import find_min_travel_times def test_case_1(): data = [ "5 7", "0", "0 1 10", "0 2 3", "1 2 1", "2 1 4", "1 3 2", "2 3 8", "3 4 7" ] assert find_min_travel_times(data) == [0, 7, 3, 9, 16] def test_case_2(): data = [...
[ { "docstring": null, "function_declaration": "def dijkstra(N, flights, starting_city):", "function_name": "dijkstra", "parameter_list": "(N, flights, starting_city)" }, { "docstring": null, "function_declaration": "def find_min_travel_times(data):", "function_name": "find_min_travel_...
[ 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 heapq\nimport sys\n\ndef dijkstra(N, flights, starting_city):\n adj = {i: [] for i in range(N)}\n for src, dst, time in flights:\n adj[...
trial_gpt4o_0
{ "original_instruction": "You are given a list of M intercity flights, where each flight is represented by a triplet (source city, destination city, travel time in hours). You want to develop a program to determine the minimum travel time required to go from a specific starting city to all other cities in the networ...
0.739807
Code_Contests_24804
C
[ "dijkstra", "find_min_travel_times" ]
2
[ [ "find_min_travel_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c0943ad401c5301bf2c14d89403f777aaf081dc
fb9d3371fd9230addf567f4d1e76bbc33f0927f8
v1.0
complete
Code_Contests
Code_Contests_24876_C
MOD = 1000000007 def solve_fibonacci(test_cases: List[int]) -> List[int]: """ Compute the n-th Fibonacci number modulo 1000000007 for each test case. >>> solve_fibonacci([1]) [1] >>> solve_fibonacci([2]) [1] >>> solve_fibonacci([10]) [55] >>> solve_fibonacci([50]) [12586269025 % 100...
MOD = 1000000007 def matrix_mult(A, B, mod=MOD): return [ [(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod, (A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod], [(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod, (A[1][0] * B[0][1] + A[1][1] * B[1][1]) % mod] ] def matrix_pow(mat, exp, ...
def test_fibonacci_cases(): assert solve_fibonacci([1]) == [1] assert solve_fibonacci([2]) == [1] assert solve_fibonacci([10]) == [55] assert solve_fibonacci([50]) == [12586269025 % 1000000007] assert solve_fibonacci([100]) == [354224848179261915075 % 1000000007] def test_multiple_fibonacci_cases()...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B, mod=MOD):", "function_name": "matrix_mult", "parameter_list": "(A, B, mod=MOD)" }, { "docstring": null, "function_declaration": "def matrix_pow(mat, exp, mod=MOD):", "function_name": "matrix_pow", "parameter_list...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "MODULO = 1000000007\n\ndef fibonacci_modulo(n):\n \"\"\"\n Returns the n-th Fibonacci number modulo 1000000007.\n \"\"\"\n if n == 1 or n == 2:...
trial_gpt4o_2
{ "original_instruction": "Matt loves the Fibonacci sequence and he is trying to create a game based on the Fibonacci numbers. He needs your help to compute the n-th Fibonacci number, but there's a twist: since the numbers can get very large, he wants to know the n-th Fibonacci number modulo 1000000007.\n\nInput\nThe...
0.678414
Code_Contests_24876
C
[ "matrix_mult", "matrix_pow", "fibonacci_mod", "solve_fibonacci" ]
4
[ [ "fibonacci_mod", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ], [ "solve_fibonacci", "fibonacci_mod" ] ]
3
[]
false
[]
false
pytest
false
[]
true
fa8bb53d5a992689b1e0ef9d14f073be63332e85
cac255301bea06182b9e614698a4e910360b95db
v1.0
complete
Code_Contests
Code_Contests_25253_C
def maximal_rectangle(matrix: List[List[int]]) -> int: """ Find the maximum area of a rectangle composed entirely of 1s in the matrix. >>> maximal_rectangle([ ... [1, 0, 1, 0, 0], ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 0, 0, 1, 0] ... ]) 6 >>> maximal_rectangle...
def maximal_rectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 heights = [0] * m for i in range(n): for j in range(m): heights[j] = heights[j] + 1 if matrix[i][j] == 1 else 0 max_area = max(max_area, largest_r...
from solution import maximal_rectangle def test_maximal_rectangle_example(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximal_rectangle(matrix) == 6 def test_maximal_rectangle_single_column(): matrix = [ [1], ...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 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 maximal_rectangle(matrix):\n if not matrix:\n return 0\n\n n = len(matrix)\n m = len(matrix[0])\n max_area = 0\n heights = [0] * ...
trial_gpt4o_0
{ "original_instruction": "**Problem Description:**\nYou are given a matrix with `n` rows and `m` columns, containing only 0s and 1s. Your task is to find the maximum area of a rectangle composed entirely of 1s in the matrix.\n\n### Input:\n- First line contains two integers `n` and `m`, the number of rows and column...
0.752177
Code_Contests_25253
C
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
789d669c747fca77e1e1ba45eb461ef19cd73c58
31c07d6c0a5991ebc72d0e5e14799c301694f090
v1.0
complete
Code_Contests
Code_Contests_25010_C
from typing import List def is_layout_valid(N: int, M: int, D: int, grid: List[str]) -> str: """ Determine if the city layout meets the requirements. Args: - N (int): Number of rows in the grid. - M (int): Number of columns in the grid. - D (int): Maximum allowed distance from a house to a hospital...
from collections import deque def bfs(grid, start, N, M): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] visited = [[False for _ in range(M)] for _ in range(N)] queue = deque([start]) visited[start[0]][start[1]] = True distances = [[float('inf') for _ in range(M)] for _ in range(N)] distances[...
from solution import is_layout_valid def test_case_1(): grid = [ "F....", ".#H#.", "H..R.", "R...." ] assert is_layout_valid(4, 5, 2, grid) == "YES" def test_case_2(): grid = [ "F.#..", "##H#.", "H..R.", "R...." ] assert is_layout...
[ { "docstring": null, "function_declaration": "def bfs(grid, start, N, M):", "function_name": "bfs", "parameter_list": "(grid, start, N, M)" }, { "docstring": null, "function_declaration": "def is_layout_valid(N, M, D, grid):", "function_name": "is_layout_valid", "parameter_list":...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(start, grid, n, m):\n \"\"\"\n Perform BFS from the start position to find shortest distance to all reachabl...
trial_gpt4o_2
{ "original_instruction": "A city is represented as a grid of size N x M. Some cells are blocked and cannot be walked on. The city has exactly one fire station and some number of hospitals and residential houses. A person can move up, down, left, or right, but cannot move into or through a blocked cell.\n\nThe mayor ...
0.651972
Code_Contests_25010
C
[ "bfs", "is_layout_valid" ]
2
[ [ "is_layout_valid", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de55c222975eac64c5f7374587d1afc2adb09aea
6b82221b5f9c937694a5cd345cfd2b78a464c15a
v1.0
complete
Code_Contests
Code_Contests_25378_C
def chemical_formula(formula: str) -> List[str]: """ Calculate the total number of each type of atoms in the formula and return them in lexicographical order of element names. Examples: >>> chemical_formula("H2O") ['H 2', 'O 1'] >>> chemical_formula("K4(ON(SO3)2)2") ['K 4', 'N 2', 'O 14', 'S...
import re from collections import defaultdict def parse_formula(formula): def parse(): stack = [defaultdict(int)] i = 0 while i < len(formula): if formula[i] == '(': stack.append(defaultdict(int)) i += 1 elif formula[i] == ')': ...
from solution import chemical_formula def test_simple_formula(): result = chemical_formula("H2O") assert result == ["H 2", "O 1"] def test_complex_formula(): result = chemical_formula("K4(ON(SO3)2)2") assert result == ["K 4", "N 2", "O 14", "S 4"] def test_single_element(): result = chemical_form...
[ { "docstring": null, "function_declaration": "def parse_formula(formula):", "function_name": "parse_formula", "parameter_list": "(formula)" }, { "docstring": null, "function_declaration": "def chemical_formula(formula):", "function_name": "chemical_formula", "parameter_list": "(f...
[ 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 re\nfrom collections import defaultdict\n\ndef parse_formula(formula):\n def parse():\n stack = [defaultdict(int)]\n i = 0\n ...
trial_gpt4o_0
{ "original_instruction": "You are given a string that represents a chemical formula containing various elements, where the occurrence of each element is denoted by an integer immediately following the element's symbol (if the integer is omitted, the count is assumed to be 1). The elements inside parentheses indicate...
0.498743
Code_Contests_25378
C
[ "parse_formula", "chemical_formula" ]
2
[ [ "chemical_formula", "parse_formula" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6f69eeab76b8e9b53828fe83965d91fd71969a2e
3722450e079a985ea6049ba25c0b5e50016d58cd
v1.0
complete
Code_Contests
Code_Contests_25070_C
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root, value): """Insert a value into the Binary Search Tree (BST)""" if root is None: return TreeNode(value) if value < root.value: root.left = in...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root, value): if root is None: return TreeNode(value) if value < root.value: root.left = insert_into_bst(root.left, value) else: root.righ...
def test_solve_example(): assert solve(5, [10, 5, 15, 3, 7], 7) == 32 def test_all_elements_greater_or_equal(): assert solve(3, [5, 10, 15], 5) == 30 def test_all_elements_less_than_k(): assert solve(3, [1, 2, 3], 10) == 0 def test_mixed_elements(): assert solve(6, [20, 15, 25, 10, 30, 5], 17) == 75 ...
[]
[ 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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(node, key):\n i...
trial_gpt4o_1
{ "original_instruction": "**Archie loves trees and math. One day he found an interesting problem involving binary search trees (BST). He decided to solve it and needs your help to succeed.**\n\nGiven an array of integer values, you need to construct the BST from the given array elements and find the sum of all nodes...
0.59456
Code_Contests_25070
C
[ "insert_into_bst", "build_bst", "sum_of_nodes_greater_or_equal_to_k", "solve" ]
4
[ [ "build_bst", "insert_into_bst" ], [ "solve", "build_bst" ], [ "solve", "sum_of_nodes_greater_or_equal_to_k" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
f2147f2a2e3ba2c59e86f02b6c7444953179df04
5f24d71974b3efb937b8bcf2c0a503268f8904f8
v1.0
complete
Code_Contests
Code_Contests_24675_C
def minimum_distance(n: int, m: int, lanes: List[List[int]]) -> int: """ Determine the minimum distance required to connect all warehouses into a single connected network. :param n: Number of warehouses :param m: Number of direct lanes :param lanes: List of lanes with each lane represented as [...
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): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > ...
def test_minimum_distance_case_1(): N = 4 M = 5 lanes = [ [0, 1, 1], [1, 2, 2], [2, 3, 1], [0, 3, 4], [0, 2, 3] ] assert minimum_distance(N, M, lanes) == 4 def test_minimum_distance_case_2(): N = 3 M = 1 lanes = [ [0, 1, 2] ] asser...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 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, 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_1
{ "original_instruction": "A transport company wants to optimize the travel route between its warehouses. Given a map with N warehouses and M direct lanes between them, determine the minimum distance required to connect all warehouses into a single connected network (spanning tree), ensuring that the company minimize...
0.671117
Code_Contests_24675
C
[ "find", "union", "kruskal", "minimum_distance" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_distance", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
485ff9887357455f1db21f1d26282836a843d179
66246d09241f9dfa6098d4a9a61964847b2de059
v1.0
complete
Code_Contests
Code_Contests_25065_C
import sys import heapq from typing import List def dijkstra(grid: List[List[int]], n: int, m: int) -> int: """Calculate the minimum time to traverse from the upper-left to the bottom-right corner of the grid using Dijkstra's algorithm.""" pass def min_travel_time(test_cases: List[List[List[int]]]) -> Lis...
import sys import heapq def dijkstra(grid, n, m): # Initialize time array with infinity time = [[sys.maxsize] * m for _ in range(n)] time[0][0] = max(1, 1 - grid[0][0]) # Priority queue for dijkstra's algorithm pq = [(time[0][0], 0, 0)] # Dijkstra's algorithm while pq: cur...
def test_parse_input(): input_str = "2\n3 3\n0 1 2\n-1 0 1\n2 -1 0\n2 2\n0 1\n-1 0\n" expected_output = [ [[0, 1, 2], [-1, 0, 1], [2, -1, 0]], [[0, 1], [-1, 0]] ] assert parse_input(input_str) == expected_output def test_dijkstra(): grid1 = [[0, 1, 2], [-1, 0, 1], [2, -1, 0]] as...
[ { "docstring": null, "function_declaration": "def dijkstra(grid, n, m):", "function_name": "dijkstra", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def min_travel_time(test_cases):", "function_name": "min_travel_time", "parameter_list": "(test...
[ 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 sys\nimport heapq\n\ndef dijkstra(grid, n, m):\n # Initialize time array with infinity\n time = [[sys.maxsize] * m for _ in range(n)]\n tim...
trial_gpt4o_0
{ "original_instruction": "Admiral Grace Hopper Naval Academy is planning a midterm programming assessment for its cadets. The task is to determine the efficiency of their navigation algorithms by assessing their ability to calculate the shortest path in a grid that's partially subject to current flows that either ac...
0.611135
Code_Contests_25065
C
[ "dijkstra", "min_travel_time", "parse_input", "main" ]
4
[ [ "min_travel_time", "dijkstra" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
c785978ce8b250b1ab0ac891a6bb87aa8d02b48a
1b529651a8477eea4a802c431b721e459bc302a9
v1.0
complete
Code_Contests
Code_Contests_25133_C
def minimum_latency_to_connect_servers(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int: """ Calculate the minimum total latency required to connect all servers. Args: N (int): Number of servers M (int): Number of links connections (List[Tuple[int, int, int]]): List of tuples whe...
def find(parent, node): if parent[node] == node: return node parent[node] = find(parent, parent[node]) return parent[node] def union(parent, rank, node1, node2): root1 = find(parent, node1) root2 = find(parent, node2) if root1 != root2: if rank[root1] > rank[root2]: ...
def test_minimum_latency_to_connect_servers_minimum_spanning_tree(): assert minimum_latency_to_connect_servers(4, 5, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 4, 10), (1, 3, 6)]) == 12 def test_minimum_latency_to_connect_servers_disconnected(): assert minimum_latency_to_connect_servers(4, 2, [(1, 2, 3), (3, 4, 5)]...
[ { "docstring": null, "function_declaration": "def find(parent, node):", "function_name": "find", "parameter_list": "(parent, node)" }, { "docstring": null, "function_declaration": "def union(parent, rank, node1, node2):", "function_name": "union", "parameter_list": "(parent, rank...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n\n def find(self, u):\n ...
trial_gpt4o_2
{ "original_instruction": "A company has a network of N servers connected by M bidirectional links. Each link has an associated latency which represents the time taken to travel between two servers. The company's goal is to ensure that data can be transferred between any pair of servers in the minimum possible time. ...
0.557845
Code_Contests_25133
C
[ "find", "union", "minimum_latency_to_connect_servers", "solve" ]
4
[ [ "minimum_latency_to_connect_servers", "find" ], [ "minimum_latency_to_connect_servers", "union" ], [ "solve", "minimum_latency_to_connect_servers" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
54448bb77148ca976e1f159fc6ffb14ae3870c9e
4709b9b16bcb15f1b0fc7f8c08610685d16f4fb0
v1.0
complete
Code_Contests
Code_Contests_25533_C
from typing import List, Tuple def bipartite_subgraph(V: int, edges: List[Tuple[int, int]]) -> int: """ Given an undirected graph representing a network of computers and connections between them, find the size (number of edges) of the largest Bipartite Subgraph. A Bipartite Graph is a graph whose vertices ...
from collections import defaultdict, deque def is_bipartite(graph, src, color): """ Helper function to check if the graph is bipartite starting from the source vertex. """ q = deque([src]) color[src] = 1 # Start coloring with 1 while q: node = q.popleft() for neig...
def test_bipartite_subgraph(): vertices = 4 edges_list = [ (0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 0) ] assert bipartite_subgraph(vertices, edges_list) == 5 vertices = 5 edges_list = [ (0, 1), (0, 2), (0, 3), ...
[ { "docstring": "Helper function to check if the graph is bipartite starting from the source vertex.", "function_declaration": "def is_bipartite(graph, src, color):", "function_name": "is_bipartite", "parameter_list": "(graph, src, color)" }, { "docstring": "Function to find the largest bipar...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 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 largest_bipartite_subgraph(V, E, edges):\n from collections import defaultdict, deque\n\n def bfs_check(start):\n color = {}\n queu...
trial_gpt4o_8
{ "original_instruction": "Given an undirected graph G = (V, E) representing a network of computers and connections between them, find the largest Bipartite Subgraph. A Bipartite Graph is a graph whose vertices can be divided into two disjoint sets U and V such that no two vertices within the same set are adjacent.\n...
0.524085
Code_Contests_25533
C
[ "is_bipartite", "bipartite_subgraph" ]
2
[ [ "bipartite_subgraph", "is_bipartite" ] ]
1
[]
false
[]
false
pytest
false
[]
true
593305d212117e6eb15272652bf85b868c2f99be
147479b36ea50016d329de64342ba98b2f1ca4e8
v1.0
complete
Code_Contests
Code_Contests_25619_C
def sequence_transformation(N: int, A: List[int]) -> int: """ Determines the number of distinct arrays B that can be generated following the rules. B[i] = A[i] + max(0, B[i-1] - (i-1)) for 1 <= i <= N where B[0] is considered 0. The function returns the number of distinct arrays B modulo 10^9+7. >>> se...
MOD = 10**9 + 7 def count_distinct_arrays(N, A): """ Determines the number of distinct arrays B that can be generated following the rules. B[i] = A[i] + max(0, B[i-1] - (i-1)) for 1 <= i <= N where B[0] is considered 0. """ B = [] prev_B = 0 for i in range(1, N+1): current_B = A[i-...
from solution import sequence_transformation def test_sample1(): assert sequence_transformation(3, [1, 2, 3]) == 1 def test_sample2(): assert sequence_transformation(2, [1000000000, 1000000000]) == 1 def test_sample3(): assert sequence_transformation(4, [1, 2, 2, 3]) == 0 def test_sample4(): assert ...
[ { "docstring": "Determines the number of distinct arrays B that can be generated following the rules.\nB[i] = A[i] + max(0, B[i-1] - (i-1)) for 1 <= i <= N where B[0] is considered 0.", "function_declaration": "def count_distinct_arrays(N, A):", "function_name": "count_distinct_arrays", "parameter_l...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_distinct_arrays(N, A):\n MOD = 10**9 + 7\n \n # Initialize set for calculated B. We start with one empty state\n dp = set([0])\n \...
trial_gpt4o_1
{ "original_instruction": "F: Sequence Transformation\n\nProblem Statement\n\nYou are given an array A of N integers. Your task is to transform this array into another array B of length N such that the following conditions are satisfied:\n\n1. For every 1 <= i <= N, B[i] = A[i] + max(0, B[i-1] - (i-1)), where B[0] is...
0.691071
Code_Contests_25619
C
[ "count_distinct_arrays", "sequence_transformation" ]
2
[ [ "sequence_transformation", "count_distinct_arrays" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5cfebf9e3112e64353b8960ea7afc9c604e4354d
e1293f4a5340c0f40443e29b4e7502bb2e098fe3
v1.0
complete
Code_Contests
Code_Contests_25397_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def isSubtree(T1: TreeNode, T2: TreeNode) -> bool: """ You are given two binary trees, T1 and T2. Write a function to check if T2 is a subtree of T1. A subtree of T1 is a...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def isSubtree(T1, T2): if not T2: return True # An empty tree is always a subtree if not T1: return False # Non-empty T2 can't be a subtree of an em...
from solution import TreeNode, isSubtree def test_isSubtree_T2_is_subtree(): T1 = TreeNode(3) T1.left = TreeNode(4) T1.right = TreeNode(5) T1.left.left = TreeNode(1) T1.left.right = TreeNode(2) T2 = TreeNode(4) T2.left = TreeNode(1) T2.right = TreeNode(2) assert isSubtree(...
[]
[ 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 two binary trees, T1 and T2. Write a function to check if T2 is a subtree of T1. A subtree of T1 is a tree consisting of a node in T1 and all of this node's descendants. The tree T1 could also be considered as a subtree of itself.\n\nInput\n- `T1` and `T2` are binary trees, re...
0.601085
Code_Contests_25397
C
[ "isSubtree", "isSameTree" ]
2
[ [ "isSubtree", "isSameTree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
bc5c49c3b8c2d566cfed17843d7044a59a115403
dc4213b2e2a57a56dbb00303af7a27074540c129
v1.0
complete
Code_Contests
Code_Contests_25402_C
def is_path_possible(grid, N, M): """ Determine if it is possible to navigate from the top-left corner to the bottom-right corner of the grid. >>> navigate_river("5 5\nL..R.\nRL..R\nR.RLL\nLL.RL\n....L") "YES" >>> navigate_river("4 4\nL.R.\n.RL.\nRLR.\n.LRR") "NO" """ def navigate_river(gri...
def is_path_possible(grid, N, M): from collections import deque directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] queue = deque([(0, 0)]) visited = set((0, 0)) while queue: r, c = queue.popleft() if (r, c) == (N-1, M-1): return "YES" for dr, dc in dir...
def test_is_path_possible(): input1 = "5 5\nL..R.\nRL..R\nR.RLL\nLL.RL\n....L" input2 = "4 4\nL.R.\n.RL.\nRLR.\n.LRR" input3 = "1 1\nL" input4 = "2 2\nLR\nRR" assert navigate_river(input1) == "YES" assert navigate_river(input2) == "NO" assert navigate_river(input3) == "YES" assert naviga...
[ { "docstring": null, "function_declaration": "def is_path_possible(grid, N, M):", "function_name": "is_path_possible", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def navigate_river(grid_input):", "function_name": "navigate_river", "parameter...
[ 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_path_possible(grid, N, M):\n from collections import deque\n\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queue = deque([(0, 0)])\n ...
trial_gpt4o_0
{ "original_instruction": "A famous online puzzle game consists of a grid of characters representing a river with logs, rocks, and empty spaces. The grid is made up of `N` rows and `M` columns. Each cell on the grid can be one of the following:\n\n- `L`: Represents a log.\n- `R`: Represents a rock.\n- `.`: Represents...
0.594319
Code_Contests_25402
C
[ "is_path_possible", "navigate_river" ]
2
[ [ "navigate_river", "is_path_possible" ] ]
1
[]
false
[]
false
pytest
false
[]
true
bd53dbbc83e3138675bd1835555c1ff754e42a03
d3cf097e834be5d61e93e1347b851af30f151d84
v1.0
complete
Code_Contests
Code_Contests_25655_C
def encrypt(plaintext: str, shift: int) -> str: """Encrypt the given plaintext using the Circular Caesar Cipher method. Args: plaintext (str): The text to encrypt, consisting of lowercase letters and spaces. shift (int): The number of positions to shift each letter. Returns: st...
def encrypt(plaintext, shift): encrypted_text = [] for char in plaintext: if char == ' ': encrypted_text.append(' ') else: new_pos = (ord(char) - ord('a') + shift) % 26 new_char = chr(new_pos + ord('a')) encrypted_text.append(new_char) return '...
import pytest from solution import encrypt, decrypt, process_test_cases def test_encrypt(): assert encrypt("hello world", 3) == "khoor zruog" assert encrypt("abc xyz", 5) == "fgh cde" assert encrypt("a", 1) == "b" assert encrypt("z", 1) == "a" assert encrypt(" ", 1) == " " assert encrypt("abcde...
[ { "docstring": null, "function_declaration": "def encrypt(plaintext, shift):", "function_name": "encrypt", "parameter_list": "(plaintext, shift)" }, { "docstring": null, "function_declaration": "def decrypt(encrypted_text, shift):", "function_name": "decrypt", "parameter_list": "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def circular_caesar_cipher_encrypt(shift, plaintext):\n encrypted_text = []\n for char in plaintext:\n if char == ' ':\n encrypted_...
trial_gpt4o_2
{ "original_instruction": "A well-known software company has developed a new encryption algorithm known as the Circular Caesar Cipher (CCC). This encryption method shifts the characters in the plaintext by a fixed number of positions down the alphabet while wrapping around to the beginning. For instance, with a shift...
0.706319
Code_Contests_25655
C
[ "encrypt", "decrypt", "process_test_cases" ]
3
[ [ "process_test_cases", "decrypt" ], [ "process_test_cases", "encrypt" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
6ac644bcc6e5581487e190e51b6b947ee63900a9
bba91955528f3bad036427fc9996759b027e5b60
v1.0
complete
Code_Contests
Code_Contests_26342_C
def generate_sequence(n: int, a0: int) -> List[int]: """ Generate a sequence of length n starting with a given number a0 using specific rules for even and odd indices. >>> generate_sequence(5, 97) [97, 2, 2, 2, 2] >>> generate_sequence(1, 15) [15] """
def sum_of_digits(num): return sum(int(digit) for digit in str(num)) def smallest_prime_factor(n): if n <= 1: return n for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return i return n def greatest_prime_factor(n): i = 2 max_prime = -1 while i * i <= n:...
from solution import generate_sequence def test_example_case(): assert generate_sequence(5, 97) == [97, 2, 2, 2, 2] def test_single_element(): assert generate_sequence(1, 15) == [15] def test_two_elements(): assert generate_sequence(2, 14) == [14, 5] def test_three_elements(): assert generate_sequen...
[ { "docstring": null, "function_declaration": "def sum_of_digits(num):", "function_name": "sum_of_digits", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def smallest_prime_factor(n):", "function_name": "smallest_prime_factor", "parameter_list": "(n)" ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 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 sum_of_digits(num):\n \"\"\"\n Returns the sum of the digits of a number.\n \"\"\"\n return sum(int(digit) for digit in str(num))\n\ndef sm...
trial_gpt4o_8
{ "original_instruction": "In a galaxy far, far away, there exists a programming droid named C3PO who loves solving problems. He is currently trying to understand a sequence of numbers generated by Tato, a young aspiring programmer. Tato generates a sequence a of length n using the following rule:\n\n- If i is even, ...
0.710559
Code_Contests_26342
C
[ "sum_of_digits", "smallest_prime_factor", "greatest_prime_factor", "generate_sequence" ]
4
[ [ "generate_sequence", "greatest_prime_factor" ], [ "generate_sequence", "smallest_prime_factor" ], [ "generate_sequence", "sum_of_digits" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3cc51279785a9872a7a42063a221739b2f8c22dd
a837ea8e0a16d3e917096565f1b967ccfe2668d1
v1.0
complete
Code_Contests
Code_Contests_25527_C
def count_paths(n: int, m: int, grid: List[str]) -> int: """ Returns the number of unique paths from the top-left to the bottom-right corner of the grid, avoiding obstacles. >>> count_paths(3, 3, ["000", "010", "000"]) 2 >>> count_paths(2, 2, ["01", "00"]) 1 >>> count_paths(3, 3, ["0...
def unique_paths_with_obstacles(grid): """ Returns the number of unique paths from the top-left to the bottom-right corner of the grid, avoiding obstacles. """ n = len(grid) m = len(grid[0]) # Special case for a 1x1 grid with no obstacle. if n == 1 and m == 1: return 1 if grid[...
from solution import count_paths def test_simple_case(): assert count_paths(3, 3, [ "000", "010", "000" ]) == 2 def test_no_paths_due_to_obstacles(): assert count_paths(3, 3, [ "011", "110", "000" ]) == 0 def test_single_path(): assert count_pat...
[ { "docstring": "Returns the number of unique paths from the top-left to the bottom-right corner \nof the grid, avoiding obstacles.", "function_declaration": "def unique_paths_with_obstacles(grid):", "function_name": "unique_paths_with_obstacles", "parameter_list": "(grid)" }, { "docstring": ...
[ 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 unique_paths(n, m, grid):\n # Create a 2D dp array initialized with 0\n dp = [[0]*m for _ in range(n)]\n \n # Starting position\n dp[0][...
trial_gpt4o_7
{ "original_instruction": "Petya and Gena are playing a survival game on a grid. The grid is an n x m matrix, where each cell either contains an obstacle or is empty. Petya starts at the top-left cell of the grid and needs to reach the bottom-right cell. Petya can only move right or down. If Petya moves onto an obsta...
0.79514
Code_Contests_25527
C
[ "unique_paths_with_obstacles", "count_paths" ]
2
[ [ "count_paths", "unique_paths_with_obstacles" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f2dd32be96114dd0f1bcc5f9a831acb94566d5d
38ed162116154238960fb1b28172a8c6b5e35e74
v1.0
complete
Code_Contests
Code_Contests_25933_C
def maximum_enjoyment_from_string(input_str: str) -> int: """ Given a string input describing the number of museums, paths, enjoyment values for each museum, and paths between museums, determine the maximum total enjoyment Alice can achieve. >>> input_str = "4 3\n10 20 30 40\n0 1\n1 2\n2 3" >>> maximum_enjo...
def maximum_enjoyment(n, m, enjoyment_values, paths): from collections import defaultdict from itertools import permutations def dfs(start, graph, visited): stack = [start] total_enjoyment = 0 while stack: node = stack.pop() if node not in visited: ...
import pytest from solution import maximum_enjoyment_from_string def test_example_1(): input_str = """4 3 10 20 30 40 0 1 1 2 2 3""" assert maximum_enjoyment_from_string(input_str) == 100 def test_example_2(): input_str = """5 6 ...
[ { "docstring": null, "function_declaration": "def maximum_enjoyment(n, m, enjoyment_values, paths):", "function_name": "maximum_enjoyment", "parameter_list": "(n, m, enjoyment_values, paths)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_nam...
[ 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_total_enjoyment(n, m, enjoyments, paths):\n from collections import defaultdict, deque\n \n # Build graph representation\n graph = defa...
trial_gpt4o_1
{ "original_instruction": "Problem\n\nAlice is planning a trip to visit different museums in a new city. She has a map of the city that shows the museums and the walking paths connecting them. Alice wants to maximize her total enjoyment by visiting as many distinct museums as possible, without visiting any museum mor...
0.587161
Code_Contests_25933
C
[ "maximum_enjoyment", "parse_input", "maximum_enjoyment_from_string" ]
3
[ [ "maximum_enjoyment_from_string", "maximum_enjoyment" ], [ "maximum_enjoyment_from_string", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
db31a816712a9eaecd61cec8d07ccb0f305afa7b
2a09e056f3863d0c198646723eb516763a0a21fc
v1.0
complete
Code_Contests
Code_Contests_26183_C
from typing import List def filter_primes(numbers: List[int]) -> List[int]: """ Filters and returns a list of prime numbers from the given list of positive integers. >>> filter_primes([2, 3, 4, 5, 10, 13, 17]) [2, 3, 5, 13, 17] >>> filter_primes([1, 4, 6, 8, 9]) [] >>> filter_primes([19, 22, ...
from typing import List def is_prime(n: int) -> bool: """ Checks 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...
from solution import filter_primes def test_filter_primes_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 10, 13, 17]) == [2, 3, 5, 13, 17] def test_filter_primes_no_primes(): assert filter_primes([1, 4, 6, 8, 9]) == [] def test_filter_primes_all_primes(): assert filter_primes([19, 23, 29, 31]) == [19...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters and returns a list of prime numbers from the given list of positive integers.", "function_declaration": "def filter_p...
[ 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 typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_0
{ "original_instruction": "Write a function that takes a list of positive integers and returns a list of only the prime numbers from the original list, in the order they appear.\n\n**Input**\n\n- A list of positive integers \n\n**Output**\n\n- A list of prime numbers in the same order as they appear in the input list...
0.666002
Code_Contests_26183
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9775332507931044962ed067ab74eb733de34de6
268c4af1eaf135f30d51babec3bd5dd9ef1ca029
v1.0
complete
Code_Contests
Code_Contests_25526_C
import heapq from typing import List, Tuple, Union def process_input_and_find_paths(input_data: str) -> List[Union[int, str]]: """ Determine the shortest travel time from the Start Building to the Target Building in the given city graph. Args: - input_data: A string that contains the number of buildings, ...
import heapq def dijkstra(graph, start, end, n): """ Dijkstra's algorithm to find the shortest path from start to end. """ INF = float('inf') dist = [INF] * (n + 1) dist[start] = 0 priority_queue = [(0, start)] while priority_queue: current_dist, current_node = heapq.heappo...
from solution import process_input_and_find_paths def test_case_1(): input_data = "4 4 3\n1 2 4\n1 3 2\n2 3 5\n3 4 1\n1 4\n2 3\n3 2\n0 0 0" expected_output = [3, 5, "NO PATH"] assert process_input_and_find_paths(input_data) == expected_output def test_case_no_path(): input_data = "3 2 1\n1 2 1\n2 3 1\...
[ { "docstring": "Dijkstra's algorithm to find the shortest path from start to end.", "function_declaration": "def dijkstra(graph, start, end, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, end, n)" }, { "docstring": "Returns shortest paths for each query.", "function...
[ 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 shortest_path_delivery(N, M, edges, queries):\n def dijkstra(start, end):\n if start == end:\n return 0\n d...
trial_gpt4o_2
{ "original_instruction": "Graph Shortest Path Delivery\n\nIn a city, there are N buildings connected by M one-way roads. The roads potentially have different lengths, and they form a directed graph. One of these buildings, labeled as the \"Start Building,\" is where delivery starts. The goal is to deliver a package ...
0.747692
Code_Contests_25526
C
[ "dijkstra", "find_shortest_paths", "process_input_and_find_paths" ]
3
[ [ "find_shortest_paths", "dijkstra" ], [ "process_input_and_find_paths", "find_shortest_paths" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2070397770a5edc554f72ab767dbda8a4e6742d3
d92e9b92012971d7368c80d08bf89a4595af05a7
v1.0
complete
Code_Contests
Code_Contests_26499_C
def longest_subsequence(s: str, words: List[str]) -> int: """ Determine the length of the longest string that can be formed by deleting some characters of the given string so that it becomes a subsequence of a word in the dictionary. >>> longest_subsequence("abppplee", ["able", "ale", "apple", "bale", "kan...
def is_subsequence(sub, main): it = iter(main) return all(char in it for char in sub) def longest_subsequence(s, words): longest = 0 for word in words: if is_subsequence(word, s): longest = max(longest, len(word)) return longest
def test_longest_subsequence(): s = "abppplee" words = ["able", "ale", "apple", "bale", "kangaroo", "app"] assert longest_subsequence(s, words) == 5 def test_longest_subsequence_example2(): s = "abcdef" words = ["fed", "abc", "abf", "ace"] assert longest_subsequence(s, words) == 3 def test_no_...
[ { "docstring": null, "function_declaration": "def is_subsequence(sub, main):", "function_name": "is_subsequence", "parameter_list": "(sub, main)" }, { "docstring": null, "function_declaration": "def longest_subsequence(s, words):", "function_name": "longest_subsequence", "paramet...
[ 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_subsequence(sub, main):\n it = iter(main)\n return all(char in it for char in sub)\n\ndef longest_subsequence(s, words):\n longest = 0\n ...
trial_gpt4o_0
{ "original_instruction": "You are given a string of lowercase letters and a dictionary of words. Your task is to determine the length of the longest string that can be formed by deleting some characters of the given string so that it becomes a subsequence of a word in the dictionary. \n\nA subsequence is a sequence ...
0.68013
Code_Contests_26499
C
[ "is_subsequence", "longest_subsequence" ]
2
[ [ "longest_subsequence", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8e39ed244326102ad265ad3228eea58b3df01c0c
044c94209d8f8b13aa95a15812f291f8de26a18a
v1.0
complete
Code_Contests
Code_Contests_26231_C
from typing import List, Tuple def is_strobogrammatic(num_str: str) -> bool: """Check if a given number string is strobogrammatic. >>> is_strobogrammatic("69") True >>> is_strobogrammatic("962") False """ pass def strobogrammatic_count(low: str, high: str) -> int: """Count the number o...
def is_strobogrammatic(num_str): mapping = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'} rotated = [] for char in reversed(num_str): if char not in mapping: return False rotated.append(mapping[char]) return "".join(rotated) == num_str def strobogrammatic_c...
from solution import is_strobogrammatic, strobogrammatic_count, solve def test_is_strobogrammatic(): assert is_strobogrammatic("69") == True assert is_strobogrammatic("88") == True assert is_strobogrammatic("962") == False assert is_strobogrammatic("818") == True def test_strobogrammatic_count(): ...
[ { "docstring": null, "function_declaration": "def is_strobogrammatic(num_str):", "function_name": "is_strobogrammatic", "parameter_list": "(num_str)" }, { "docstring": null, "function_declaration": "def strobogrammatic_count(low, high):", "function_name": "strobogrammatic_count", ...
[ 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 is_strobogrammatic(num):\n \"\"\"\n Checks if a number is strobogrammatic.\n \"\"\"\n strobo_pairs = {'0': '0', '1': '1', '6': '9', '8': '8...
trial_gpt4o_6
{ "original_instruction": "A \"strobogrammatic number\" is a number that looks the same when rotated 180 degrees (looked at upside down). For example, 69, 96, 88, and 818 are all strobogrammatic numbers.\n\nGiven a range of numbers represented by strings low and high where 1 ≤ len(low) ≤ len(high) ≤ 15 and low ≤ high...
0.549526
Code_Contests_26231
C
[ "is_strobogrammatic", "strobogrammatic_count", "solve" ]
3
[ [ "solve", "strobogrammatic_count" ], [ "strobogrammatic_count", "is_strobogrammatic" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e7f8065d88332542f47dcb713840842fd7bbfc75
b008d844ff99f40f359b172b67b1421e6ded0a41
v1.0
complete
Code_Contests
Code_Contests_25867_C
def is_subsequence(s: str, word: str) -> bool: """ Check if word is a subsequence of the string s. """ # Implement this function def count_subsequences(s: str, words: List[str]) -> int: """ Count how many words in the words list are subsequences of s. """ # Implement this function def ...
def is_subsequence(s, word): """ Check if word is a subsequence of string s. """ it = iter(s) return all(char in it for char in word) def count_subsequences(s, words): """ Count how many words in the list are subsequences of s. """ return sum(1 for word in words if is_subsequence(s,...
from solution import is_subsequence, count_subsequences, main def test_is_subsequence(): assert is_subsequence("abpcplea", "ale") == True assert is_subsequence("abpcplea", "apple") == True assert is_subsequence("abpcplea", "monkey") == False assert is_subsequence("abcdef", "a") == True assert is_su...
[ { "docstring": "Check if word is a subsequence of string s.", "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": "Count how many words in the list are subsequences of s.", "function_declaration": "def...
[ 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_subsequence(s, word):\n \"\"\"\n Helper function to check if word is a subsequence of s.\n \"\"\"\n it = iter(s)\n return all(char in...
trial_gpt4o_2
{ "original_instruction": "Given a string `s` of lowercase English letters and a list of words `words`, find the number of words that are subsequences of `s`.\n\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\...
0.726114
Code_Contests_25867
C
[ "is_subsequence", "count_subsequences", "main" ]
3
[ [ "count_subsequences", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b96b59173b5269a099d7ee4525bde982019d29ce
4bd87367d6f2559a88a436534b5bca4d9a05b28d
v1.0
complete
Code_Contests
Code_Contests_26034_C
from typing import List from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 else: return 1 def largest_number(n: int, numbers: List[int]) -> str: """ Form the largest possible integer by concatenating the numbers together. >>> largest_number(3, [10, 2, 9]) ...
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 else: return 1 def largest_number(n, numbers): numbers = [str(number) for number in numbers] numbers.sort(key=cmp_to_key(compare)) return ''.join(numbers) def process_input(n, numbers): return larg...
from solution import process_input def test_single_number(): assert process_input(1, [1]) == "1" def test_two_numbers(): assert process_input(2, [10, 2]) == "210" def test_multiple_numbers(): assert process_input(3, [10, 2, 9]) == "9210" assert process_input(4, [54, 546, 548, 60]) == "6054854654" ...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largest_number(n, numbers):", "function_name": "largest_number", "parameter_list": "(n, numbers)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largest_possible_integer(nums):\n \"\"\"\n Returns the largest possible integer formed by concatenating the g...
trial_gpt4o_9
{ "original_instruction": "You are given a list of positive integers and you need to form the largest possible integer by concatenating the numbers together. \n\nInput\n\n- The first line contains an integer n (1 ≤ n ≤ 100), the number of integers in the list.\n- The second line contains n positive integers each less...
0.645669
Code_Contests_26034
C
[ "compare", "largest_number", "process_input" ]
3
[ [ "largest_number", "compare" ], [ "process_input", "largest_number" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
0f9785e84d6808d4a1c7531a7807bba698a760d5
0fade408266dcdd6aab778198dcea8d9050ac32a
v1.0
complete
Code_Contests
Code_Contests_26555_C
import math from heapq import heappop, heappush from typing import List, Tuple def min_road_length(n: int, intersections: List[Tuple[int, int]]) -> float: """ Compute the minimum total length of roads required to connect all intersections. >>> min_road_length(4, [(0, 0), (0, 1), (1, 0), (1, 1)]) 3.00 >...
import math from heapq import heappop, heappush def euclidean_distance(x1, y1, x2, y2): return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def min_road_length(n, intersections): if n <= 1: return 0 adj = {i: [] for i in range(n)} # adjacency list for i in range(n): for j in range(i + ...
from solution import min_road_length def test_min_road_length_example(): n = 4 intersections = [(0, 0), (0, 1), (1, 0), (1, 1)] assert min_road_length(n, intersections) == 3.00 def test_min_road_length_single_intersection(): n = 1 intersections = [(0, 0)] assert min_road_length(n, intersection...
[ { "docstring": null, "function_declaration": "def euclidean_distance(x1, y1, x2, y2):", "function_name": "euclidean_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def min_road_length(n, intersections):", "function_name": "min_road_len...
[ 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\nfrom heapq import heappop, heappush\n\ndef euclidean_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\ndef m...
trial_gpt4o_0
{ "original_instruction": "Tom loves playing with his toy road-building set, where he builds a city with various roads connecting intersections. Each intersection has unique coordinates in a 2D plane. Tom wonders about the shortest distance required to connect all the intersections with roads while ensuring there's a...
0.609596
Code_Contests_26555
C
[ "euclidean_distance", "min_road_length" ]
2
[ [ "min_road_length", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
450c832c5c7de1d4b33bdfcdbce387a2d302a9d0
e0b409f36131d53e7538abcdf911011b62d60ddc
v1.0
complete
Code_Contests
Code_Contests_26536_C
import math from functools import reduce def lcm(a: int, b: int) -> int: """Function to return the least common multiple of two numbers. >>> lcm(1, 1) 1 >>> lcm(2, 3) 6 >>> lcm(4, 5) 20 >>> lcm(6, 8) 24 >>> lcm(12, 15) 60 """ def smallest_multiple(numbers: List[int]) -> int: """ Re...
import math from functools import reduce def lcm(a, b): """Function to return the least common multiple of two numbers""" return a * b // math.gcd(a, b) def smallest_multiple(numbers): """ Returns the smallest multiple that is evenly divisible by all numbers in the list. """ return reduce(lcm,...
from solution import lcm, smallest_multiple def test_lcm(): assert lcm(1, 1) == 1 assert lcm(2, 3) == 6 assert lcm(4, 5) == 20 assert lcm(6, 8) == 24 assert lcm(12, 15) == 60 def test_smallest_multiple(): assert smallest_multiple([3, 5, 7]) == 105 assert smallest_multiple([1, 2, 3, 4, 5]) ...
[ { "docstring": "Function to return the least common multiple of two numbers", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest multiple that is evenly divisible by all numbers in the list.", "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the Least Common Multiple (LCM) of a and b.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "Write a function that takes a list of n natural numbers and returns the smallest multiple that is evenly divisible by all of the numbers in the list. \n\nClue: You may need to use the relationship between the Least Common Multiple (LCM) and Greatest Common Divisor (GCD).\n\nInput\n\nThe inp...
0.701091
Code_Contests_26536
C
[ "lcm", "smallest_multiple" ]
2
[ [ "smallest_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a6fe63ddd3561ef61a5a5b36d22919683af02a6
004d96fcb38a17b6cc88e216b3bdbc4c1ce2344f
v1.0
complete
Code_Contests
Code_Contests_25327_C
from typing import List, Tuple def find_positions(nums: List[int], target: int) -> Tuple[int, int]: """ Identify the first and last positions of a given target integer in a sorted list of integers. >>> find_positions([5, 7, 7, 8, 8, 10], 8) (3, 4) >>> find_positions([5, 7, 7, 8, 8, 10], 6) (-1, -1)...
from typing import List, Tuple def find_first_position(nums: List[int], target: int) -> int: left, right = 0, len(nums) - 1 first_pos = -1 while left <= right: mid = (left + right) // 2 if nums[mid] < target: left = mid + 1 elif nums[mid] > target: right...
def test_find_positions(): nums = [5, 7, 7, 8, 8, 10] target = 8 assert find_positions(nums, target) == (3, 4) def test_find_positions_not_found(): nums = [5, 7, 7, 8, 8, 10] target = 6 assert find_positions(nums, target) == (-1, -1) def test_find_positions_all_elements_match(): nu...
[ { "docstring": null, "function_declaration": "def find_first_position(nums, target):", "function_name": "find_first_position", "parameter_list": "(nums, target)" }, { "docstring": null, "function_declaration": "def find_last_position(nums, target):", "function_name": "find_last_posit...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef find_positions(nums: List[int], target: int) -> Tuple[int, int]:\n \"\"\"\n Finds the first and last positions ...
trial_gpt4o_2
{ "original_instruction": "You are given a series of integers. Your task is to identify the first and last positions of a given target integers in this series and return them as a tuple. The given series of integers is guaranteed to be sorted in non-decreasing order.\n\nWrite a function `find_positions` that takes in...
0.614366
Code_Contests_25327
C
[ "find_first_position", "find_last_position", "find_positions" ]
3
[ [ "find_positions", "find_first_position" ], [ "find_positions", "find_last_position" ] ]
2
[]
false
[]
false
pytest
false
[]
true
7c04aca0ffd5d56184ab92eac99f0a8774580607
49f5242f2e16fd6993df6ce0158b9bf947b1a497
v1.0
complete
Code_Contests
Code_Contests_26248_C
from typing import List, Tuple def is_prime(number: int) -> bool: """ Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(15) False """ pass def check_magical_sequence(arr: List[int]) -> Tuple[bool, List[int]]: """ Check if the array can be rearranged in...
def is_prime(number): """ Check if a number is a prime number. """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number % (i + 2) == 0: ...
from solution import is_prime, check_magical_sequence, magical_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(17) == True assert is_prime(15) == False def test_check_magical_sequence(): ...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Check if the array can be rearranged into a magical arithmetic sequence.", "function_declaration": "def che...
[ 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 is_prime(n):\n \"\"\" Helper function to determine if a number is a prime number or zero. \"\"\"\n if n <= 1:\n return False\n if n == ...
trial_gpt4o_4
{ "original_instruction": "Problem Description\n\nIn a faraway land, there exists a special sequence known as the \"magical arithmetic sequence.\" A sequence of integers is defined as magical if the difference between any two consecutive elements is always the same and is either a positive prime number or zero.\n\nGi...
0.606914
Code_Contests_26248
C
[ "is_prime", "check_magical_sequence", "magical_sequence" ]
3
[ [ "check_magical_sequence", "is_prime" ], [ "magical_sequence", "check_magical_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4e6842e9740c2dd82e44f6be17926125cdb63ccf
c907c0fff7519ad3f2a31221d50efd536629a7e8
v1.0
complete
Code_Contests
Code_Contests_26517_C
def is_prime(number): """ Returns True if the given number is prime, otherwise False. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False """ def fibonacci_primes(n): """ Returns the first n prime numbers in the Fibonacci sequence. >>> fibonacci_primes(5) ...
def is_prime(number): """ Returns True if the given number is prime, otherwise False. """ if number <= 1: return False if number == 2: return True if number % 2 == 0: return False for i in range(3, int(number**0.5) + 1, 2): if number % i == 0: retu...
def test_is_prime(): # Testing known primes assert is_prime(2) == True assert is_prime(3) == True assert is_prime(7) == True # Testing known non-primes assert is_prime(0) == False assert is_prime(1) == False assert is_prime(8) == False # Testing edge case assert is_prim...
[ { "docstring": "Returns True if the given number is prime, otherwise False.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Returns the first n prime numbers in the Fibonacci sequence.", "function_declaration...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\...
trial_gpt4o_8
{ "original_instruction": "Write a program that takes an integer n and returns the first n numbers in the Fibonacci sequence that are prime. The Fibonacci sequence is defined as: \n\n F(1) = 1\n F(2) = 1\n F(n) = F(n-1) + F(n-2) for n > 2\n\nA prime number is a natural number greater than 1 that has no divis...
0.846878
Code_Contests_26517
C
[ "is_prime", "fibonacci_primes" ]
2
[ [ "fibonacci_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
11352a2344caf6f179cbe9d4c0d95dbe78dc0ec8
23c3de3c521e60eac14696b56de4be038058a5bb
v1.0
complete
Code_Contests
Code_Contests_25159_C
def max_minerals(matrix): """ Given a 2D list representing the mineral quantities in a grid, computes the maximum quantity of minerals the robot can collect from the top-left to the bottom-right corner. """ def process_input(input_data): """ Processes the input data and returns a list of ma...
def max_minerals(matrix): """ Given a 2D list representing the mineral quantities in a grid, computes the maximum quantity of minerals the robot can collect from the top-left to the bottom-right corner. """ if not matrix: return 0 n = len(matrix) m = len(matrix[0]) # Create...
def test_max_minerals(): matrix1 = [ [1, 3, 1, 2], [1, 5, 1, 3], [4, 2, 1, 4], ] matrix2 = [ [2, 4], [0, 3], ] assert max_minerals(matrix1) == 17 assert max_minerals(matrix2) == 9 def test_process_input(): input_data = "3 4\n1 3 1 2\n1 5 1 3\n4 2 1 4\...
[ { "docstring": "Given a 2D list representing the mineral quantities in a grid,\ncomputes the maximum quantity of minerals the robot can collect\nfrom the top-left to the bottom-right corner.", "function_declaration": "def max_minerals(matrix):", "function_name": "max_minerals", "parameter_list": "(m...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_minerals(matrix):\n \"\"\"\n Given a 2D list representing the mineral quantities in a grid,\n computes the maximum quantity of minerals th...
trial_gpt4o_0
{ "original_instruction": "Space Mining Robotics\n\nA space mining company has developed advanced mining robots to autonomously extract valuable minerals from asteroids. Each mining robot operates by moving through a grid-like path on the surface of an asteroid. The grid is represented by a 2D matrix where each cell ...
0.536396
Code_Contests_25159
C
[ "max_minerals", "process_input", "space_mining_robots" ]
3
[ [ "space_mining_robots", "max_minerals" ], [ "space_mining_robots", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
e9397d6a2241918cc6c59a160579f31149f5dcab
d654c4a281835933cfc560544474ff64d5d02470
v1.0
complete
Code_Contests
Code_Contests_25966_C
def calculate_complexities(input_string: str) -> List[str]: """ Write a program that calculates the complexity of a nested loop structure in terms of Big-O notation. >>> calculate_complexities("1\n1 n 1 1 m 2\n") ['O((n-1)/1(m-1)/2)'] >>> calculate_complexities("2\n1 n 1 1 m 2\n0 n 2 0 m 2\n") ...
def big_o_complexity(loop_structures): complexities = [] for loops in loop_structures: complexity = "O(" terms = [] for loop in loops: s, e, u = loop start_diff = f'({e} - {s})' term = f'{start_diff}/{u}' terms.append(term) ...
def test_complexity_single_structure(): input_string = "1\n1 n 1 1 m 2\n" expected_output = ["O((n - 1)/1(m - 1)/2)"] assert calculate_complexities(input_string) == expected_output def test_complexity_multiple_structures(): input_string = "2\n1 n 1 1 m 2\n0 n 2 0 m 2\n" expected_output = ["O((n - 1...
[ { "docstring": null, "function_declaration": "def big_o_complexity(loop_structures):", "function_name": "big_o_complexity", "parameter_list": "(loop_structures)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "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 big_o_complexity(loop_structures):\n complexities = []\n \n for loops in loop_structures:\n complexity = \"O(\"\n terms = []\n ...
trial_gpt4o_0
{ "original_instruction": "Write a program that calculates the complexity of a nested loop structure in terms of Big-O notation.\n\nIn a given nested loop structure, represent each loop with triplet (s, e, u) where:\n- s: loop starts at s\n- e: loop ends at e\n- u: loop updates variable by u\n\nThe loops are nested i...
0.487884
Code_Contests_25966
C
[ "big_o_complexity", "parse_input", "calculate_complexities" ]
3
[ [ "calculate_complexities", "big_o_complexity" ], [ "calculate_complexities", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
d45d8ecca5a23c15ae882162987c281cd434653e
6d159beeb1aeb0a14351a13de612915dd12d9fcb
v1.0
complete
Code_Contests
Code_Contests_25084_C
def minimum_total_road_length(N, M, roads): """ Determine the minimum total length of roads required to keep the campus connected. Parameters: N (int): The number of buildings. M (int): The number of possible roads. roads (List[Tuple[int, int, int]]): The list of roads where each road is re...
def minimum_total_road_length(N, M, roads): """ This function takes the number of buildings N, number of roads M, and a list of roads. Each road is represented by a tuple (u, v, w) where u and v are the buildings connected by the road and w is the length of the road. The function returns the minimum tot...
def test_minimum_total_road_length(): input_data = "4 5\n1 2 10\n1 3 6\n1 4 5\n2 3 15\n3 4 4" assert parse_and_solve(input_data) == 19 def test_single_road(): input_data = "2 1\n1 2 5" assert parse_and_solve(input_data) == 5 def test_no_road(): input_data = "1 0" assert parse_and_solve(input_d...
[ { "docstring": "This function takes the number of buildings N, number of roads M, and a list of roads.\nEach road is represented by a tuple (u, v, w) where u and v are the buildings connected\nby the road and w is the length of the road. The function returns the minimum total length\nof roads required to keep t...
[ 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_spanning_tree(N, M, edges):\n \"\"\"\n Returns the minimum total length of roads required to keep the campus connected.\n \n Parame...
trial_gpt4o_2
{ "original_instruction": "A large university is planning the layout for its new campus, which is going to have several buildings connected by a series of roads. Each building and road is represented in the form of a graph where buildings are nodes and roads are edges. The university wants to ensure that the campus r...
0.685946
Code_Contests_25084
C
[ "minimum_total_road_length", "parse_and_solve" ]
2
[ [ "parse_and_solve", "minimum_total_road_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
230331a693cae25dc3c854c2e8df8406b92ad991
5f5f7c05e7ed37ba9749ddfa7e3caaa2453cf00c
v1.0
complete
Code_Contests
Code_Contests_26418_C
from collections import defaultdict import sys sys.setrecursionlimit(10**6) def calculate_maximum_path_sum(input_str: str) -> int: """ Calculate the maximum possible sum of weights on a simple path between any two vertices in the tree. >>> input_str = "5\\n1 2 3\\n2 3 4\\n2 4 2\\n3 5 6" >>> calculate_maxi...
from collections import defaultdict import sys sys.setrecursionlimit(10**6) def find_farthest_node(tree, start_node, n): def dfs(node, parent, distance): farthest_node[0], farthest_dist[0] = (node, distance) if distance > farthest_dist[0] else (farthest_node[0], farthest_dist[0]) for neighbor, wei...
from solution import calculate_maximum_path_sum def test_example_case(): input_str = "5\n1 2 3\n2 3 4\n2 4 2\n3 5 6" assert calculate_maximum_path_sum(input_str) == 13 def test_minimum_case(): input_str = "2\n1 2 5" assert calculate_maximum_path_sum(input_str) == 5 def test_simple_case(): input_s...
[ { "docstring": null, "function_declaration": "def find_farthest_node(tree, start_node, n):", "function_name": "find_farthest_node", "parameter_list": "(tree, start_node, n)" }, { "docstring": null, "function_declaration": "def maximum_path_sum(n, edges):", "function_name": "maximum_p...
[ 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\nimport sys\n\nsys.setrecursionlimit(10**6)\n\ndef find_farthest_node(tree, start_node, n):\n def dfs(node, parent, ...
trial_gpt4o_0
{ "original_instruction": "You are given a tree with n vertices labeled from 1 to n and with edges weighted by positive integers. Your task is to find the maximum possible sum of weights on a simple path between any two vertices in the tree.\n\nA tree with n vertices is a connected graph with n-1 edges and no cycles....
0.6285
Code_Contests_26418
C
[ "find_farthest_node", "maximum_path_sum", "calculate_maximum_path_sum" ]
3
[ [ "calculate_maximum_path_sum", "maximum_path_sum" ], [ "maximum_path_sum", "find_farthest_node" ] ]
2
[]
false
[]
false
pytest
true
[]
true
be208ea5f7ca2166a2d2c77e4532f3020b103aab
d6e98ac72f10dae7faf97d70a1b71557022a871e
v1.0
complete
Code_Contests
Code_Contests_25733_C
def is_palindromic_prime(n: int) -> str: """ Check if the given number is a palindromic prime. A palindromic number is a number that remains the same when its digits are reversed. A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself. Arg...
def is_palindrome(n): """ Returns True if n is a palindrome, False otherwise. """ return str(n) == str(n)[::-1] 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 ==...
from solution import is_palindromic_prime def test_palindromic_prime(): assert is_palindromic_prime(2) == "YES" assert is_palindromic_prime(131) == "YES" assert is_palindromic_prime(12) == "NO" assert is_palindromic_prime(9339) == "NO" def test_palindromic_not_prime(): assert is_palindromic_prime(...
[ { "docstring": "Returns True if n is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prim...
[ 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_palindromic_prime(n):\n \"\"\"\n Checks if a given number is a palindromic prime.\n\n :param n: integer, the number to be checked\n :ret...
trial_gpt4o_2
{ "original_instruction": "Petya loves palindromic numbers very much. A palindromic number is a number that remains the same when its digits are reversed. For example, numbers 121, 4774, 12321 are palindromic and numbers 123, 789, 4567 are not.\n\nPetya also loves prime numbers. A prime number is a positive integer g...
0.765161
Code_Contests_25733
C
[ "is_palindrome", "is_prime", "is_palindromic_prime" ]
3
[ [ "is_palindromic_prime", "is_palindrome" ], [ "is_palindromic_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
37444ae02b2e20141a3588972072f3360220a8aa
289fe961adcd5a35a61cd980ce10e277ca69dbde
v1.0
complete
Code_Contests
Code_Contests_26770_C
def min_cost_to_connect_parks(n: int, m: int, connections: List[Tuple[int, int, int]]) -> int: """ Calculate the minimum total cost to connect all parks based on given connections. Parameters: n (int): number of parks. m (int): number of potential connections. connections (List[Tuple[int, int, ...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot ...
from solution import min_cost_to_connect_parks def test_example1(): assert min_cost_to_connect_parks(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5)]) == 6 def test_example2(): assert min_cost_to_connect_parks(4, 3, [(1, 2, 3), (2, 3, 4), (4, 4, 1)]) == -1 def test_single_connection(): asser...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr...
trial_gpt4o_2
{ "original_instruction": "In a small town, the mayor wants to build a series of monuments and parks. There are n parks, each numbered from 1 to n, where some of them need to be connected to pipe networks to provide water. Each connection between parks is bidirectional and can supply water to both parks involved. How...
0.605336
Code_Contests_26770
C
[ "find", "union", "min_cost_to_connect_parks" ]
3
[ [ "min_cost_to_connect_parks", "find" ], [ "min_cost_to_connect_parks", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
41795db49f5e9dcf929fa24edea27beab02a9878
48956c3a18b9247173b0c01bda8b945063ce4ad1
v1.0
complete
Code_Contests
Code_Contests_26255_C
def sieve_of_eratosthenes(n): """ Returns a list of primes up to n (inclusive) using the Sieve of Eratosthenes algorithm. """ 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 +...
def sieve_of_eratosthenes(n): """ Returns a list of primes up to n (inclusive) using the Sieve of Eratosthenes algorithm. """ 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 ...
from solution import primes_product def test_single_query(): assert primes_product([(2, 4)]) == [21] def test_multiple_queries(): assert primes_product([(2, 4), (1, 3), (5, 5)]) == [21, 10, 121] def test_same_position(): assert primes_product([(5, 5)]) == [121] def test_large_query(): # Known primes...
[ { "docstring": "Returns a list of primes up to n (inclusive) using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Generates the first n prime numbers.", "...
[ 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 eratosthenes_sieve(limit):\n \"\"\" Generate all primes up to the specified limit using the Sieve of Eratosthenes \"\"\"\n is_prime = [True] * (l...
trial_gpt4o_4
{ "original_instruction": "Shreya is fascinated with numbers and she recently learned about prime numbers. She decides to create a sequence of consecutive prime numbers and wants to calculate the product of any two prime numbers in this sequence. However, Shreya finds it challenging to determine the positions in the ...
0.64807
Code_Contests_26255
C
[ "sieve_of_eratosthenes", "generate_primes", "primes_product" ]
3
[ [ "generate_primes", "sieve_of_eratosthenes" ], [ "primes_product", "generate_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d6f2f74814497dc617496651ea8f4d4f83fc2164
64b4a5a85a8738ceb4733257ffdc404acae60dd0
v1.0
complete
Code_Contests
Code_Contests_25325_C
from typing import List, Tuple def sieve_of_eratosthenes(n): """ Generate a list of booleans representing whether numbers are prime 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_pr...
def sieve_of_eratosthenes(n): """ Generate a list of booleans representing whether numbers are prime 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 ...
from solution import twin_prime_pairs def test_example_case(): assert twin_prime_pairs(3, [(1, 10), (11, 20), (1, 100)]) == [2, 2, 8] def test_no_twin_primes(): assert twin_prime_pairs(1, [(14, 16)]) == [0] def test_single_digit_range(): assert twin_prime_pairs(1, [(1, 10)]) == [2] def test_large_range(...
[ { "docstring": "Generate a list of booleans representing whether numbers are prime up to n.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_twin_primes(...
[ 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 sieve(n):\n \"\"\"\n Implements the Sieve of Eratosthenes to generate a list of primes up to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n ...
trial_gpt4o_2
{ "original_instruction": "Joan is a math enthusiast who loves working with prime numbers. She recently learned about twin primes, which are pairs of prime numbers that have a difference of 2. For example, (3, 5), (11, 13), and (17, 19) are twin primes.\n\nJoan wants to find out how many twin prime pairs exist in a g...
0.669245
Code_Contests_25325
C
[ "sieve_of_eratosthenes", "count_twin_primes", "twin_prime_pairs" ]
3
[ [ "twin_prime_pairs", "count_twin_primes" ], [ "twin_prime_pairs", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1a610fd4b8d0a7bf32feb287a56eb1c599d04a3e
16380f695c8424019d9d8eaf878afba67046c7d7
v1.0
complete
Code_Contests
Code_Contests_26254_C
from typing import List def is_prime(n: int) -> bool: """ Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(4) False """ def max_non_overlapping_subarrays_with_prime_sum(arr: List[int]) -> int: """ Find the maximum number of non-overlapping subarrays such that the sum of e...
from math import isqrt 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 max_non_overlappin...
from solution import is_prime, max_non_overlapping_subarrays_with_prime_sum 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(10) == False assert is_prime(13) == True def test_max_non_overlapping_su...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def max_non_overlapping_subarrays_with_prime_sum(arr):", "function_name": "max_non_overlapping_subarrays_with_prime_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": "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_1
{ "original_instruction": "You are given an array `arr` of `n` positive integers. Your task is to find the maximum number of non-overlapping subarrays such that the sum of each subarray is a prime number.\n\nInput\n\nThe first line contains one integer n (1 ≤ n ≤ 10^5) — the number of elements in the array.\n\nThe se...
0.663633
Code_Contests_26254
C
[ "is_prime", "max_non_overlapping_subarrays_with_prime_sum" ]
2
[ [ "max_non_overlapping_subarrays_with_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d729a16ed58054be5bbfc0edff7eb50eaf958cb0
21c2b3be2cd4f8e1bdc4099aed86cbfcabd91063
v1.0
complete
Code_Contests
Code_Contests_26330_C
def find_anagram_pairs(words: List[str]) -> List[Tuple[int, int]]: """ Implement a function find_anagram_pairs that takes a list of strings as input and returns a list of tuples where each tuple contains indices of two strings that are anagrams of each other in the original list. Ignore punctuation and capitalizati...
import re from collections import defaultdict def normalize_string(s): """ Normalize the string by removing all non-alphabetic characters and sorting. """ s = re.sub(r'[^a-zA-Z]', '', s) # Remove non-alphabetic characters return ''.join(sorted(s.lower())) # Sort characters and make lowercase def...
from solution import find_anagram_pairs def test_find_anagram_pairs_basic(): words = ["Listen", "Silent", "enlist", "inlets", "google", "gogole"] assert find_anagram_pairs(words) == [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3), (4, 5)] def test_find_anagram_pairs_empty(): assert find_anagram_pairs([]) ...
[ { "docstring": "Normalize the string by removing all non-alphabetic characters and sorting.", "function_declaration": "def normalize_string(s):", "function_name": "normalize_string", "parameter_list": "(s)" }, { "docstring": "Find pairs of indices of anagram strings in the given list of word...
[ 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 re\nfrom collections import defaultdict\n\ndef normalize_string(s):\n \"\"\"\n Normalize the string by removing non-alphanumeric characters, \...
trial_gpt4o_2
{ "original_instruction": "Implement a function `find_anagram_pairs` that takes a list of strings as input and returns a list of tuples where each tuple contains indices of two strings that are anagrams of each other in the original list. Two strings are anagrams if they can be formed by rearranging the letters of ea...
0.589558
Code_Contests_26330
C
[ "normalize_string", "find_anagram_pairs" ]
2
[ [ "find_anagram_pairs", "normalize_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e91117254ec20bb7c655a02dec8c971a8d53a8a9
de028f2d2186f3b8896f7cd1d1cd223668c9a8b2
v1.0
complete
Code_Contests
Code_Contests_26126_C
def merge(arr, l, m, r): """ Merge function for the merge sort algorithm. Merges two subarrays of arr[]. First subarray is arr[l..m] Second subarray is arr[m+1..r] >>> arr = [12, 11, 13, 5, 6, 7, 14, 9, 15, 2] >>> merge_sort(arr, 0, len(arr) - 1) >>> print(arr) [2, 5, 6, 7, 9, 11, 12...
def merge(arr, l, m, r): """ Merges two subarrays of arr[]. First subarray is arr[l..m] Second subarray is arr[m+1..r] """ n1 = m - l + 1 n2 = r - m # Create temporary arrays L = [0] * n1 R = [0] * n2 # Copy data to temporary arrays L[] and R[] for i in range(n1): ...
from solution import merge_sort def test_merge_sort(): arr = [12, 11, 13, 5, 6, 7, 14, 9, 15, 2] merge_sort(arr, 0, len(arr) - 1) assert arr == [2, 5, 6, 7, 9, 11, 12, 13, 14, 15] def test_merge_sort_single_element(): arr = [1] merge_sort(arr, 0, len(arr) - 1) assert arr == [1] def test_merge...
[ { "docstring": "Merges two subarrays of arr[].\nFirst subarray is arr[l..m]\nSecond subarray is arr[m+1..r]", "function_declaration": "def merge(arr, l, m, r):", "function_name": "merge", "parameter_list": "(arr, l, m, r)" }, { "docstring": null, "function_declaration": "def merge_sort(a...
[ 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 merge(arr, l, m, r):\n \"\"\"\n Merges two sorted subarrays of arr[l..r].\n First subarray is arr[l..m].\n Second subarray is arr[m+1..r].\...
trial_gpt4o_2
{ "original_instruction": "In a merge sort algorithm, the idea is to divide the input array into two halves, call the same function recursively to sort both halves, and then merge the two sorted halves. The `merge` function is used for merging two halves. The `merge(arr, l, m, r)` is a key process that assumes that `...
0.667181
Code_Contests_26126
C
[ "merge", "merge_sort" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b2420ac9c4e85e579c026acab361445657f68b9
f7ed1dc74805e32e15664c389726fa5f2ce6a6c3
v1.0
complete
Code_Contests
Code_Contests_24979_C
import math import sys def find_X(interact): """Figure out a target integer 1 ≤ X ≤ 10^6 using gcd queries. This function should call `interact(query)` up to 15 times and determine the value of X. Queries should be issued in the format `? Q` (1 ≤ Q ≤ 10^12) and the response should be interpreted as th...
import math import sys def find_X(interact): # We will use a range of numbers to try as queries queries = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] # To store gcd results with known queries accumulated_gcd = 0 for query in queries: gcd_result = interact(query) ...
def interact_mock(sequence): answers = {2: 2, 3: 3, 5: 5, 7: 7, 11: 1, 13: 1, 17: 1, 19: 1, 23: 1, 29: 1, 31: 1, 37: 1, 41: 1, 43: 1, 47: 1} def inner(query): return answers[query] return inner def test_find_X_correct(): interact = interact_mock([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, ...
[ { "docstring": null, "function_declaration": "def find_X(interact):", "function_name": "find_X", "parameter_list": "(interact)" }, { "docstring": null, "function_declaration": "def interact(query):", "function_name": "interact", "parameter_list": "(query)" }, { "docstring...
[ 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 sys\nimport random\nfrom math import gcd\n\ndef find_gcd_target(T):\n random.seed(3) # For reproducibility\n for _ in range(T):\n quer...
trial_gpt4o_1
{ "original_instruction": "This is an interactive problem.\n\nYou must figure out a target integer 1 ≤ X ≤ 10^6. The X remains fixed during the game. You are granted the ability to ask for the value of the greatest common divisor (gcd) with a chosen integer. Using at most 15 queries, you should guess the value of X c...
0.620316
Code_Contests_24979
C
[ "find_X", "interact", "play_game" ]
3
[ [ "play_game", "find_X" ], [ "play_game", "interact" ] ]
2
[]
false
[]
false
pytest
false
[]
true
a033f62c4f4d9b7dfe4e9c76216a3120d15e9b61
5247ced7bafff9dce613ef87397bf9effda199fa
v1.0
complete
Code_Contests
Code_Contests_25688_C
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 prime_numbers = [p for p in range(2, limit + 1) if is_prime[p]] return...
def sieve_of_eratosthenes(limit): is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 prime_numbers = [p for p in range(2, limit + 1) if is_prime[p]] return...
from solution import find_prime_pair def test_find_prime_pair_1(): p1, p2 = find_prime_pair(2, 10) assert abs(p1 - p2) == 2 assert p1 + p2 <= 10 def test_find_prime_pair_2(): p1, p2 = find_prime_pair(4, 20) assert abs(p1 - p2) == 4 assert p1 + p2 <= 20 def test_find_prime_pair_3(): p1, p2...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": null, "function_declaration": "def find_prime_pair(n, m):", "function_name": "find_prime_pair", "parameter_lis...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(n):\n \"\"\"\n Sieve of Eratosthenes to find all primes less than or equal to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime...
trial_gpt4o_9
{ "original_instruction": "A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance:\n\n* the following numbers are prime: 2, 3, 5, 7, 11;\n* the following numbers are not prime: 4, 6, 8, 9, 10.\n\nYou are given two positive integers n and m. Find a pair of...
0.639376
Code_Contests_25688
C
[ "sieve_of_eratosthenes", "find_prime_pair" ]
2
[ [ "find_prime_pair", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
58cac0c1a167dc4fb4414eb6cb9bcea693822e0a
c2b95b6f29254c1bbb478f1dc3fe1ad070f42c30