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_40471_C
def sieve_of_eratosthenes(n): """ Generate all prime numbers up to a given number n. >>> sieve_of_eratosthenes(30) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] """ def find_kth_prime(t, cases): """ Given multiple cases, find the k-th prime number for each. >>> find_kth_prime(3, [1, 10, 100]) [...
def sieve_of_eratosthenes(n): prime = [True for _ in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n + 1, p): prime[i] = False p += 1 prime_numbers = [] for p in range(2, n + 1): if prime[p]: prime...
from solution import sieve_of_eratosthenes, find_kth_prime def test_sieve_of_eratosthenes(): primes = sieve_of_eratosthenes(30) assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_find_kth_prime_small_cases(): assert find_kth_prime(3, [1, 10, 100]) == [2, 29, 541] def test_find_kth_prime_large...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def find_kth_prime(t, cases):", "function_name": "find_kth_prime", "parameter_list": "(...
[ 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(n):\n prime = [True for _ in range(n + 1)]\n p = 2\n while (p * p <= n):\n if (prime[p] == True):\n fo...
trial_gpt4o_0
{ "original_instruction": "Alicia is preparing for her school math contest and she loves prime numbers. She found a special prime number problem among the training materials and decided to practice solving it, but she needs a bit of help understanding how to implement it. The problem is as follows:\n\nGiven an intege...
0.656595
Code_Contests_40471
C
[ "sieve_of_eratosthenes", "find_kth_prime", "main" ]
3
[ [ "find_kth_prime", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7f7d15cf45aa9c79a326c4060e33c40c0aaa321
ba14e2302e14e4f75d4eb696377f442a59ab29cc
v1.0
complete
Code_Contests
Code_Contests_40172_C
def optimal_service_plan(n: int, m: int, connections: List[Tuple[int, int, int]]) -> List[Union[int, Tuple[int, int]]]: """ You are tasked with designing an optimal service plan for a new residential area. The residential area consists of `n` houses, represented as nodes in a graph. The existing connections bet...
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...
from solution import optimal_service_plan def test_optimal_service_plan_basic(): n = 4 m = 5 connections = [ (1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 5) ] result = optimal_service_plan(n, m, connections) assert result[0] == 6 assert (1, 2) i...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "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": "You are the manager of a water distribution company, and you are tasked with designing an **optimal service plan** for a new residential area. The residential area consists of `n` houses, represented as nodes in a graph. The existing connections between the houses, where water pipes can be ...
0.705648
Code_Contests_40172
C
[ "find", "union", "kruskal", "optimal_service_plan" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "optimal_service_plan", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
f177af29cfb40b0c1f6d9f9e9ba25d758325fdcb
a6614953692836f22398dbcae7e658fdc8277062
v1.0
complete
Code_Contests
Code_Contests_40084_C
def count_land_masses_from_input(input_string: str) -> int: """ Given a string representing the input for a grid where 'L' represents land and 'W' represents water, this function returns the number of connected land masses in the grid. >>> count_land_masses_from_input("5 5\nWWWWW\nWLLLW\nWLWWW\nWWLWW\nW...
def count_land_masses(grid): """ Given a grid with 'L' representing land and 'W' representing water, this function counts the number of connected land masses. """ r = len(grid) c = len(grid[0]) def dfs(x, y): if x < 0 or y < 0 or x >= r or y >= c or grid[x][y] == 'W': ...
from solution import count_land_masses_from_input def test_single_land_mass(): input_string = "3 3\nLLL\nLLW\nLLL" assert count_land_masses_from_input(input_string) == 1 def test_multiple_land_masses(): input_string = "5 5\nWWWWW\nWLLLW\nWLWWW\nWWLWW\nWWWWW" assert count_land_masses_from_input(input_s...
[ { "docstring": "Given a grid with 'L' representing land and 'W' representing water, \nthis function counts the number of connected land masses.", "function_declaration": "def count_land_masses(grid):", "function_name": "count_land_masses", "parameter_list": "(grid)" }, { "docstring": null, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_land_masses(grid):\n \"\"\"\n Count the number of connected land masses in the grid.\n \"\"\"\n if not grid:\n return 0\n\n ...
trial_gpt4o_2
{ "original_instruction": "You are given a rectangular grid of characters, where each character is either 'L', representing land, or 'W', representing water. You need to count the number of connected land masses in the grid. A land mass is defined as a group of 'L' characters connected horizontally or vertically (not...
0.594888
Code_Contests_40084
C
[ "count_land_masses", "count_land_masses_from_input" ]
2
[ [ "count_land_masses_from_input", "count_land_masses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
59f0045a71f51f911a815b97dc989d4264e7044c
683af1c8171ce249f01ed7fe30b97b64d2aebfcf
v1.0
complete
Code_Contests
Code_Contests_40135_C
from typing import List, Tuple def express_numbers_as_sums_of_primes(t: int, numbers: List[int]) -> List[str]: """ Determine if a given number can be expressed as a sum of exactly two prime numbers. Parameters: t (int): Number of test cases numbers (List[int]): List of integers to check ...
def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False 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] = False p += 1 prime_numbers = [p for p in rang...
from solution import express_numbers_as_sums_of_primes def test_case_example_1(): result = express_numbers_as_sums_of_primes(3, [8, 10, 27]) assert result == ["YES 3 5", "YES 3 7", "NO"] def test_case_small_numbers(): result = express_numbers_as_sums_of_primes(2, [2, 3]) assert result == ["NO", "NO"] ...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def can_be_expressed_as_sum_of_two_primes(n, primes, is_prime):", "function_nam...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"Generate a list of prime numbers up to max_num using the Sieve of Eratosthenes.\"\"\"\n is_prime = [True]...
trial_gpt4o_2
{ "original_instruction": "Nina loves playing with numbers and has recently started exploring prime numbers. She has a special fascination with sums of prime numbers and wonders about the possibility of expressing numbers as such sums. \n\nYour task is to determine if a given number can be expressed as a sum of exact...
0.682823
Code_Contests_40135
C
[ "sieve_of_eratosthenes", "can_be_expressed_as_sum_of_two_primes", "express_numbers_as_sums_of_primes" ]
3
[ [ "express_numbers_as_sums_of_primes", "can_be_expressed_as_sum_of_two_primes" ], [ "express_numbers_as_sums_of_primes", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3d8a903e890e0fe074c3f00850f045379625f551
630d53f7da42fbee51ff32459e268dc6b445407d
v1.0
complete
Code_Contests
Code_Contests_40219_C
from typing import List, Tuple def find_connected_components(n: int, edges: List[Tuple[int, int]]) -> List[List[int]]: """Find all the connected components in an undirected graph. Args: n (int): The number of vertices. edges (List[Tuple[int, int]]): A list of undirected edges. Returns: ...
def find_connected_components(n, edges): from collections import defaultdict, deque def bfs(node): queue = deque([node]) visited.add(node) component = [] while queue: current = queue.popleft() component.append(current) for neighbor in graph[cu...
def test_find_connected_components_case_1(): n = 6 edges = [(1, 2), (2, 3), (4, 5), (5, 6), (6, 4)] expected = [[1, 2, 3], [4, 5, 6]] result = find_connected_components(n, edges) assert result == expected def test_find_connected_components_case_2(): n = 4 edges = [(1, 2), (3, 4)] expect...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges):", "function_name": "find_connected_components", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def print_connected_components(n, edges):", "function_name": "print_c...
[ 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_connected_components(n, edges):\n from collections import defaultdict, deque\n \n def bfs(start, visited, graph):\n queue = deque(...
trial_gpt4o_2
{ "original_instruction": "Alex is learning about connected components in undirected graphs. He wants to practice by identifying all the connected components in a given graph.\n\nA connected component of an undirected graph is a set of vertices such that there is a path between any two vertices in this set, and no ve...
0.556288
Code_Contests_40219
C
[ "find_connected_components", "print_connected_components" ]
2
[ [ "print_connected_components", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c7c516bf22569f8589cb46e8e893870cad0436cd
dff4d011846396938d3dc123a0620a6ad909a0ad
v1.0
complete
Code_Contests
Code_Contests_40192_C
from typing import List def detect_sentiment(review: str) -> str: positive_keywords = ["good", "great", "excellent", "awesome", "fantastic", "like", "love", "nice"] negative_keywords = ["bad", "poor", "terrible", "awful", "worst", "dislike", "hate", "horrible"] neutral_keywords = ["okay", "fine", "neutral"...
def detect_sentiment(review): positive_keywords = ["good", "great", "excellent", "awesome", "fantastic", "like", "love", "nice"] negative_keywords = ["bad", "poor", "terrible", "awful", "worst", "dislike", "hate", "horrible"] review_words = review.lower().split() positive_count = sum(word in posit...
from solution import analyze_reviews def test_analyze_reviews_all_sentiments(): input_reviews = [ "I love this product, it is awesome!", "This is the worst service I have ever experienced.", "The movie was okay, but not fantastic.", "Everything was average, just so-so.", "I ...
[ { "docstring": null, "function_declaration": "def detect_sentiment(review):", "function_name": "detect_sentiment", "parameter_list": "(review)" }, { "docstring": null, "function_declaration": "def analyze_reviews(reviews):", "function_name": "analyze_reviews", "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": "def analyze_sentiment(review):\n positive_keywords = [\"good\", \"great\", \"excellent\", \"awesome\", \"fantastic\", \"like\", \"love\", \"nice\"]\n ...
trial_gpt4o_2
{ "original_instruction": "A software company is developing a new system for analyzing customer reviews. As part of this system, they need to categorize each review based on its sentiment as \"Positive\", \"Negative\", or \"Neutral\". To achieve this, they have devised a straightforward algorithm using the presence o...
0.767637
Code_Contests_40192
C
[ "detect_sentiment", "analyze_reviews" ]
2
[ [ "analyze_reviews", "detect_sentiment" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98f2ff1e53503f674c151365598a6369d5f4e350
d7da0886ea0107262b4f11a3b5809ba6d3004a5a
v1.0
complete
Code_Contests
Code_Contests_40927_C
from typing import List def transform_list(n: int, nums: List[int]) -> List[int]: """ Given a list of integers, this function returns a new list where each element at index i is the product of all the elements in the original list except the one at i. Examples: >>> transform_list(4, [1, 2, 3, 4]) ...
def product_except_self(nums): """ Given a list of integers, this function returns a new list where each element at index i is the product of all the elements in the original list except the one at i. """ n = len(nums) left_products = [1] * n right_products = [1] * n result = [1] * n ...
def test_product_except_self(): # Import the function from the main solution file from solution import transform_list # Test cases based on the examples and additional edge cases assert transform_list(4, [1, 2, 3, 4]) == [24, 12, 8, 6] assert transform_list(3, [2, 3, 4]) == [12, 8, 6] ...
[ { "docstring": "Given a list of integers, this function returns a new list where each element\nat index i is the product of all the elements in the original list except the one at i.", "function_declaration": "def product_except_self(nums):", "function_name": "product_except_self", "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 product_except_self(nums):\n \"\"\"\n Given a list of integers, this function returns a new list where each element\n at index i is the produc...
trial_gpt4o_0
{ "original_instruction": "Given a list of integers, you need to transform the list into a new list where each element at index \\(i\\) of the new list is the product of all the numbers in the original list except the one at \\(i\\).\n\nWrite a program that receives a list of integers and returns the transformed list...
0.734205
Code_Contests_40927
C
[ "product_except_self", "transform_list" ]
2
[ [ "transform_list", "product_except_self" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0c06fab675363e442a8400c64af595ad18b1c76d
80a53ff187e6f9ca7aac64bfe5ecff528b35bb53
v1.0
complete
Code_Contests
Code_Contests_40860_C
def organize_bookshelfs(input_data: str) -> str: """ Alex is organizing his bookshelf. His goal is to arrange his books such that all books of the same height are grouped together. Furthermore, within each height group, the books should be sorted by their titles in alphabetical order. Given that each book ...
def sort_books(book_data): """ Sorts books first by height and then by title in alphabetical order if heights are the same. """ result = [] for books in book_data: books.sort(key=lambda book: (book[1], book[0])) result.append([book[0] for book in books]) return result def parse_...
from solution import organize_bookshelfs def test_example_case_1(): input_data = """3 HarryPotter 20 WarAndPeace 20 TheHobbit 30 2 AnimalFarm 10 BraveNewWorld 10 0""" expected_output = """HarryPotter WarAndPeace TheHobbit AnimalFarm BraveNewWorld""" assert organize_bookshelfs(input_data) == expected_outpu...
[ { "docstring": "Sorts books first by height and then by title in alphabetical order if heights are the same.", "function_declaration": "def sort_books(book_data):", "function_name": "sort_books", "parameter_list": "(book_data)" }, { "docstring": "Parses the input data into a list of test cas...
[ 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(books):\n \"\"\"\n Sorts the books based on the specified criteria: grouped by height, and within each group, titles are sorted alphab...
trial_gpt4o_1
{ "original_instruction": "Alex is organizing his bookshelf. His goal is to arrange his books such that all books of the same height are grouped together. Furthermore, within each height group, the books should be sorted by their titles in alphabetical order. Given that each book has a unique title but may share the ...
0.586712
Code_Contests_40860
C
[ "sort_books", "parse_input", "format_output", "organize_bookshelfs" ]
4
[ [ "organize_bookshelfs", "format_output" ], [ "organize_bookshelfs", "parse_input" ], [ "organize_bookshelfs", "sort_books" ] ]
3
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
e3f0dc1bb4bcda0dc5a155384586adfe51e0ff8d
0e0ed8caf88262b95833bc648ea3f964a2ac676f
v1.0
complete
Code_Contests
Code_Contests_40969_C
def determine_game_result(n: int, m: int, grid: List[str]) -> str: """ Determine the current state of a game played by Alice and Bob on a NxM grid. >>> determine_game_result(3, 3, ["AAA", "...", "B.B"]) 'Alice' >>> determine_game_result(3, 3, ["A.B", "A.B", ".BB"]) 'Bob' >>> determine_game_resul...
def check_winner(grid, n, m): def check_line_winner(line): for i in range(len(line) - 2): if line[i] != '.' and line[i] == line[i+1] == line[i+2]: if line[i] == 'A': return "Alice" elif line[i] == 'B': return "Bob" r...
from solution import determine_game_result def test_alice_wins_row(): grid = [ "AAA", "...", "B.B" ] assert determine_game_result(3, 3, grid) == "Alice" def test_bob_wins_column(): grid = [ "A.B", "A.B", ".BB" ] assert determine_game_result(3, 3,...
[ { "docstring": null, "function_declaration": "def check_winner(grid, n, m):", "function_name": "check_winner", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def determine_game_result(n, m, grid):", "function_name": "determine_game_result", "par...
[ 0, 0, 0, 0, 0, 0, 1, 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 check_winner(grid, N, M):\n def check_line_win(line, ch):\n count = 0\n for cell in line:\n if cell == ch:\n ...
trial_gpt4o_6
{ "original_instruction": "problem\n\nAlice and Bob are playing a game on a rectangular grid with dimensions `N x M`. The grid is initially empty, and each cell can contain one character. The players take turns to fill in cells in the grid with characters 'A' for Alice and 'B' for Bob. Alice always starts first. The ...
0.630837
Code_Contests_40969
C
[ "check_winner", "determine_game_result" ]
2
[ [ "determine_game_result", "check_winner" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83eff16f8d6aed7c9f1afe4a5e53f6e25f76e41c
81906a9b5259762e06a402261ea659ac70b6c6be
v1.0
complete
Code_Contests
Code_Contests_40827_C
def count_flowerbeds(grid, N, M): """Counts the number of flowerbeds in the given grid. Args: grid (List[List[int]]): The grid representing the farm. N (int): Number of rows in the grid. M (int): Number of columns in the grid. Returns: int: The maximum number of flow...
def count_flowerbeds(grid, N, M): def is_valid(i, j): return 0 <= i < N and 0 <= j < M and grid[i][j] == 1 def dfs(i, j): grid[i][j] = -1 # Mark as visited for d in [(1, 0), (-1, 0), (0, 1), (0, -1)]: ni, nj = i + d[0], j + d[1] if is_valid(ni, nj): ...
import pytest from solution import main, parse_input, solve_flowerbeds def test_example_case(): input_str = "1\n3 3\n1 0 1\n0 1 0\n1 0 1\n" expected_output = [5] assert main(input_str) == expected_output def test_all_barren(): input_str = "1\n3 3\n0 0 0\n0 0 0\n0 0 0\n" expected_output = [0] a...
[ { "docstring": null, "function_declaration": "def count_flowerbeds(grid, N, M):", "function_name": "count_flowerbeds", "parameter_list": "(grid, N, M)" }, { "docstring": null, "function_declaration": "def solve_flowerbeds(test_cases):", "function_name": "solve_flowerbeds", "param...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_flowerbeds(grid, N, M):\n def is_valid(i, j):\n return 0 <= i < N and 0 <= j < M and grid[i][j] == 1\n \n def dfs(i, j):\n ...
trial_gpt4o_0
{ "original_instruction": "In a city, there is a grid of size N x M representing a farm. Each cell of the grid can be either fertile (denoted by 1) or barren (denoted by 0). A gardener wants to plant flowers in such a way that he gets the maximum number of flowerbeds while ensuring no two flowerbeds are adjacent vert...
0.611023
Code_Contests_40827
C
[ "count_flowerbeds", "solve_flowerbeds", "parse_input", "main" ]
4
[ [ "solve_flowerbeds", "count_flowerbeds" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
1fa6a9af79136aef79198374820a792c9b842879
defb91b36e4c2b8f4deaa8c3c71c1b3a456eaf6e
v1.0
complete
Code_Contests
Code_Contests_40852_C
from typing import List def solve(input_data: str) -> str: """ Organize books into genres and print their titles in alphabetical order. Args: input_data (str): The input data containing multiple test cases. Returns: str: The formatted output with genres and sorted book titles. Ex...
def categorize_books(test_cases): from collections import defaultdict results = [] for case in test_cases: n = case[0] books = case[1:] genre_dict = defaultdict(list) for book in books: title, genre = book.split(", ") genre_dict...
import pytest from solution import solve def test_example_input(): input_data = "2\n3\nThe Great Gatsby, Fiction\nMoby Dick, Fiction\nA Brief History of Time, Science\n2\nThe Selfish Gene, Science\nWar and Peace, History" expected_output = "Fiction: Moby Dick, The Great Gatsby\nScience: A Brief History of Time...
[ { "docstring": null, "function_declaration": "def categorize_books(test_cases):", "function_name": "categorize_books", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", "parameter_l...
[ 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 categorize_books_by_genre(T, test_cases):\n from collections import defaultdict\n\n results = []\n for i in range(T):\n N = test_cases[...
trial_gpt4o_2
{ "original_instruction": "Arjun is organizing his bookshelf and wants to group the books by their genre. Each book has a title and a genre associated with it. Help Arjun by writing a program that categorizes the books by genre and prints the titles under each genre in alphabetical order.\n\nINPUT:\nThe first line of...
0.548575
Code_Contests_40852
C
[ "categorize_books", "process_input", "solve" ]
3
[ [ "solve", "categorize_books" ], [ "solve", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
5f7c8b2a27f496952fbb84d4b1faf5cf179d35ac
3b808d607819e20dac9676196989bf0323127248
v1.0
complete
Code_Contests
Code_Contests_41471_C
MOD = 1000000007 def factorial(n): """ Helper function to compute factorial modulo MOD """ result = 1 for i in range(2, n+1): result = (result * i) % MOD return result def count_permutations(n, swap_limits): """ Returns the number of distinct possible sequences after swaps Paramet...
MOD = 1000000007 def factorial(n): """ Helper function to compute factorial modulo MOD """ result = 1 for i in range(2, n+1): result = (result * i) % MOD return result def count_permutations(n, swap_limits): """ Returns the number of distinct possible sequences after swaps """ ...
from solution import count_permutations, factorial def test_count_permutations(): assert count_permutations(4, [2, 1, 3, 2]) == 24 assert count_permutations(1, [0]) == 1 assert count_permutations(3, [1, 1, 1]) == 6 assert count_permutations(5, [1, 2, 2, 2, 2]) == 120 assert count_permutations(2, [0...
[ { "docstring": "Helper function to compute factorial modulo MOD ", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the number of distinct possible sequences after swaps", "function_declaration": "def count_perm...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_possible_sequences(n, swaps_limits):\n MOD = 1000000007\n \n # Calculate factorials and inverse factorials for combinatorial calculation...
trial_gpt4o_2
{ "original_instruction": "A certain number of students are playing a game with colored balls in a line. Each student receives one ball at the beginning, and each ball has a distinct color. The game rules allow students to swap their balls, following certain constraints. At the end of the game, the sequence of ball c...
0.596765
Code_Contests_41471
C
[ "factorial", "count_permutations" ]
2
[ [ "count_permutations", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b89914d405de2c86156cc8cbec0a5bcf2ac937e5
264f69ba2d3e0b86765ab029c8725ecb10cb4831
v1.0
complete
Code_Contests
Code_Contests_41209_C
def minimum_cost_to_connect_all_cities(n, m, highways): """ Determine the minimum total cost to connect all cities with highways. Args: n (int): Number of cities. m (int): Number of possible highways. highways (List[List[int]]): List of possible highways where each highway is represented as [u, v, w...
def find(parent, i): if parent[i] == i: return i else: 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]...
def test_example_case_1(): n = 4 m = 5 highways = [ [1, 2, 10], [1, 3, 6], [1, 4, 5], [2, 3, 5], [3, 4, 4] ] assert minimum_cost_to_connect_all_cities(n, m, highways) == 14 def test_example_case_2(): n = 3 m = 3 highways = [ [1, 2, 5], ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 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 kruskal_minimum_cost(n, edges):\n \"\"\"\n Uses Kruskal's algorithm to find the minimum cost to connect all cities.\n\n :param n: Number of ci...
trial_gpt4o_2
{ "original_instruction": "A country's transport ministry is planning to build several new highways to connect isolated cities in a certain region. They want to ensure that the costs are minimized while connecting all cities such that there is a path between any two cities.\n\nThe region consists of n cities, and the...
0.705663
Code_Contests_41209
C
[ "find", "union", "minimum_cost_to_connect_all_cities" ]
3
[ [ "minimum_cost_to_connect_all_cities", "find" ], [ "minimum_cost_to_connect_all_cities", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
dc0596ea7ebf1be01339f2becef77730491911a5
62247252bfee48664dd1c5aa57aac9b5d1ce0aec
v1.0
complete
Code_Contests
Code_Contests_40883_C
from typing import List, Tuple def max_sum_odd_submatrix(matrix: List[List[int]]) -> int: """ Find the maximum sum of elements of any submatrix with odd row and column lengths. >>> matrix = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9] ... ] >>> max_sum_odd_submatrix(matrix) ...
def max_sum_odd_submatrix(matrix): n = len(matrix) m = len(matrix[0]) def submatrix_sum(r1, c1, r2, c2): total = 0 for r in range(r1, r2+1): for c in range(c1, c2+1): total += matrix[r][c] return total max_sum = float('-inf') for r1 ...
import pytest from solution import max_sum_odd_submatrix, max_sum_odd_submatrix_cases, process_input def test_max_sum_odd_submatrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert max_sum_odd_submatrix(matrix) == 45 matrix = [ [-1, -2], [-3, -4] ] ...
[ { "docstring": null, "function_declaration": "def max_sum_odd_submatrix(matrix):", "function_name": "max_sum_odd_submatrix", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def max_sum_odd_submatrix_cases(t, cases):", "function_name": "max_sum_odd_submat...
[ 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 max_odd_submatrix_sum(test_cases):\n results = []\n \n for matrix, n, m in test_cases:\n max_sum = float('-inf')\n \n for...
trial_gpt4o_8
{ "original_instruction": "You are given a matrix of size n x m filled with integers. Your task is to find the maximum sum of elements of any submatrix that has odd row and column lengths. An odd row length means the submatrix has an odd number of rows, and an odd column length means the submatrix has an odd number o...
0.58699
Code_Contests_40883
C
[ "max_sum_odd_submatrix", "max_sum_odd_submatrix_cases", "process_input" ]
3
[ [ "max_sum_odd_submatrix_cases", "max_sum_odd_submatrix" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
2e5adc3eb82f4be5a4ffeefa0dd88530f739169d
a864b629a08b9e3ed4f9348d6a3587a6e6774ff6
v1.0
complete
Code_Contests
Code_Contests_41029_C
from typing import List, Tuple def is_sorted(lst: List[int]) -> bool: """ Check if a list is sorted in non-decreasing order. >>> is_sorted([1, 2, 3, 4]) True >>> is_sorted([1, 3, 2, 4]) False """ ... def bfs_min_reversals(arr: List[int]) -> int: """ Find the minimum number of reversals to sort...
from collections import deque def is_sorted(lst): return all(lst[i] <= lst[i + 1] for i in range(len(lst) - 1)) def bfs_min_reversals(arr): N = len(arr) if is_sorted(arr): return 0 queue = deque([(arr, 0)]) visited = set() visited.add(tuple(arr)) while queue: curr...
def test_is_sorted(): assert is_sorted([1, 2, 3, 4]) == True assert is_sorted([1, 3, 2, 4]) == False def test_bfs_min_reversals(): assert bfs_min_reversals([4, 3, 2, 1]) == 1 assert bfs_min_reversals([1, 3, 5, 4, 2]) == 2 assert bfs_min_reversals([1, 2, 3, 4, 5, 6]) == 0 assert bfs_min_reversal...
[ { "docstring": null, "function_declaration": "def is_sorted(lst):", "function_name": "is_sorted", "parameter_list": "(lst)" }, { "docstring": null, "function_declaration": "def bfs_min_reversals(arr):", "function_name": "bfs_min_reversals", "parameter_list": "(arr)" }, { ...
[ 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_reversals_to_sort_array(array):\n \"\"\"\n This function returns the minimum number of subarray reversals needed to sort the array in non-dec...
trial_gpt4o_3
{ "original_instruction": "Vishal is managing the inventory of a library and wants an automated way to sort the book IDs. Each book has a unique integer ID and the current state of the inventory is represented by an array of these IDs.\n\nVishal needs a function that sorts the array of book IDs in non-decreasing orde...
0.656137
Code_Contests_41029
C
[ "is_sorted", "bfs_min_reversals", "min_reversal_sort" ]
3
[ [ "bfs_min_reversals", "is_sorted" ], [ "min_reversal_sort", "bfs_min_reversals" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b38d8e121add7fded4982e60991d0404d9b97d89
f04e1c161cc30738f1fae598f40fadc335b7cf28
v1.0
complete
Code_Contests
Code_Contests_41593_C
def is_prime(num: int) -> bool: """ Check if a number is prime. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(29) == True """ def is_palindrome(num: int) -> bool: """ Check if a number is a palindrome. >>> is_palindrome(121) == True >...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6...
from solution import is_prime, is_palindrome, find_palindromic_prime, palindromic_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(1) == False def test_is_palindrome(): assert is_palind...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrom...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "**Problem Description:**\nAmy loves palindromes and prime numbers. A palindrome is a number that reads the same forwards and backwards. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Amy is interested in finding numbers that are both palindr...
0.696846
Code_Contests_41593
C
[ "is_prime", "is_palindrome", "find_palindromic_prime", "palindromic_primes" ]
4
[ [ "find_palindromic_prime", "is_palindrome" ], [ "find_palindromic_prime", "is_prime" ], [ "palindromic_primes", "find_palindromic_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
424fd42864b13375801b39011ffae695c11f21f8
3a4d402439485738ecd3ef82c3d43a9c67cb154f
v1.0
complete
Code_Contests
Code_Contests_41812_C
def convert_temperature_readings(readings: List[str]) -> List[str]: """Convert a list of temperature readings in Celsius to Fahrenheit. Temperatures that are already in Fahrenheit are left unchanged. Readings in Celsius are converted to Fahrenheit using the formula: F = C * 9/5 + 32 Converted readings a...
def celsius_to_fahrenheit(celsius): return (float(celsius) * 9/5) + 32 def convert_temperature_readings(readings): result = [] for reading in readings: if reading.endswith('F'): result.append(reading) else: fahrenheit = celsius_to_fahrenheit(reading) resu...
from solution import convert_temperature_readings def test_convert_temperature_readings(): assert convert_temperature_readings(["0", "10", "25", "32F", "-40"]) == ["32.0F", "50.0F", "77.0F", "32F", "-40.0F"] assert convert_temperature_readings(["100", "-30", "40F", "15", "80"]) == ["212.0F", "-22.0F", "40F", "...
[ { "docstring": null, "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": null, "function_declaration": "def convert_temperature_readings(readings):", "function_name": "convert_tempera...
[ 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 convert_to_fahrenheit(temperature_readings):\n \"\"\"\n Converts a list of temperature readings to Fahrenheit.\n \n Parameters:\n temper...
trial_gpt4o_1
{ "original_instruction": "You are given the task of writing a function that takes a list of strings representing temperature readings and returns a new list of strings, where each temperature reading is converted to its Fahrenheit equivalent.\n\nThe list of temperature readings will be in Celsius, unless the reading...
0.546402
Code_Contests_41812
C
[ "celsius_to_fahrenheit", "convert_temperature_readings" ]
2
[ [ "convert_temperature_readings", "celsius_to_fahrenheit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea372972381668e51ecd5e275880525762441f69
25bcca7c5197497e2355eb61b247375cef13c909
v1.0
complete
Code_Contests
Code_Contests_41669_C
def fibonacci_series(n: int) -> List[int]: """ Returns the first n terms of the Fibonacci series. >>> fibonacci_series(0) == [] >>> fibonacci_series(1) == [0] >>> fibonacci_series(2) == [0, 1] >>> fibonacci_series(3) == [0, 1, 1] >>> fibonacci_series(5) == [0, 1, 1, 2, 3] >>> fibonacci_s...
def fibonacci_series(n): """ Returns the first n terms of the Fibonacci series. """ if n == 0: return [] fibonacci = [0, 1] while len(fibonacci) < n: fibonacci.append(fibonacci[-1] + fibonacci[-2]) return fibonacci[:n] def print_fibonacci_series(n): ""...
def test_fibonacci_series(): assert fibonacci_series(0) == [] assert fibonacci_series(1) == [0] assert fibonacci_series(2) == [0, 1] assert fibonacci_series(3) == [0, 1, 1] assert fibonacci_series(5) == [0, 1, 1, 2, 3] assert fibonacci_series(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] def tes...
[ { "docstring": "Returns the first n terms of the Fibonacci series.", "function_declaration": "def fibonacci_series(n):", "function_name": "fibonacci_series", "parameter_list": "(n)" }, { "docstring": "Prints the first n terms of the Fibonacci series as required.", "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 fibonacci_series(n):\n \"\"\"\n Prints the first n terms of the Fibonacci series.\n If n is 0, prints an empty line.\n \"\"\"\n if n == ...
trial_gpt4o_2
{ "original_instruction": "Given an integer \\( n \\), print the first \\( n \\) terms of the Fibonacci series.\n\nConstraints\n\n* \\( n \\) is a non-negative integer and \\( 0 \\leq n \\leq 50 \\).\n\nInput\n\nInput is given from Standard Input in the following format:\n\n\nn\n\n\nOutput\n\nPrint the first \\( n \\...
0.841934
Code_Contests_41669
C
[ "fibonacci_series", "print_fibonacci_series" ]
2
[ [ "print_fibonacci_series", "fibonacci_series" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e35f247225a4fc0a70d962329f52f176a36f0393
2a65f3f18e01b8c31ec6e53f39a37f44e7dda6a6
v1.0
complete
Code_Contests
Code_Contests_41646_C
import math from typing import List, Tuple def is_prime(n: int) -> bool: """ Checks if a number is a prime number. >>> is_prime(2) True >>> is_prime(4) False """ pass def find_prime_factors(c: int) -> Tuple[int, int]: """ Finds a pair of prime factors (P1, P2) such that C = P1 ...
import math def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, find_prime_factors, prime_factors_pairs def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(11) def test_find_prime_factors(): assert find_prime_factors(15) == (3, 5) ...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds a pair of prime factors (P1, P2) such that C = P1 * P2.", "function_declaration": "def find_prime_factors(c):"...
[ 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 sieve(n):\n \"\"\"\n Utilizes the Sieve of Eratosthenes to find all prime numbers up to n.\n\n :param n: The upper limit to generate primes.\n...
trial_gpt4o_1
{ "original_instruction": "Amanda is fascinated by numbers and has recently come to know about prime numbers. She decided to construct a composite number using prime numbers in such a way that, for a given composite number `C`, it can be factorized into at least one pair of prime numbers `(P1, P2)` such that `C = P1 ...
0.804878
Code_Contests_41646
C
[ "is_prime", "find_prime_factors", "prime_factors_pairs" ]
3
[ [ "find_prime_factors", "is_prime" ], [ "prime_factors_pairs", "find_prime_factors" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bc2e9f8447248617b7c1c895081894e558ca6540
1de929ca9cf423b7bde06ff661a770b5ba804959
v1.0
complete
Code_Contests
Code_Contests_42026_C
from typing import List def is_prime(n: int) -> bool: """ Check if a number n is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(13) True >>> is_prime(1) False >>> is_prime(0) False >>> is_prime(-1) False """ def sum_of_primes(a: int, b: int) -> ...
def is_prime(n): """ Check if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return Tr...
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_sum_of_primes(): ...
[ { "docstring": "Check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers between a and b inclusive.", "function_declaration": "def sum_of_primes(a, b):", "f...
[ 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": "Sarah loves solving puzzles and recently she learned about prime numbers. As a challenge, she decided to write a program that checks if numbers are prime and sums up all prime numbers within a given range. Your task is to help Sarah by writing the program.\n\nInput\n\nThe first line contain...
0.768763
Code_Contests_42026
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38412b6c79d33baab94be0396231a228ec93f7ba
dafa094262a701e063a68edc81e4f39682cf1667
v1.0
complete
Code_Contests
Code_Contests_41877_C
import re from typing import List def check_passwords(passwords: List[str]) -> List[str]: """ Check if passwords meet the given criteria for complexity. >>> check_passwords(["Password123!"]) ["Valid"] >>> check_passwords(["Pass123"]) ["Invalid: Password must be at least 8 characters long."] >>>...
import re def check_passwords(passwords): results = [] for password in passwords: if len(password) < 8: results.append("Invalid: Password must be at least 8 characters long.") elif not re.search(r'[A-Z]', password): results.append("Invalid: Password must contain at leas...
import pytest from solution import check_passwords, validate_passwords_from_input def test_valid_password(): assert check_passwords(["Password123!"]) == ["Valid"] def test_short_password(): assert check_passwords(["Pass123"]) == ["Invalid: Password must be at least 8 characters long."] def test_no_up...
[ { "docstring": null, "function_declaration": "def check_passwords(passwords):", "function_name": "check_passwords", "parameter_list": "(passwords)" }, { "docstring": null, "function_declaration": "def validate_passwords_from_input(input_data):", "function_name": "validate_passwords_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\n\ndef check_passwords(passwords):\n results = []\n\n for password in passwords:\n if len(password) < 8:\n results.append...
trial_gpt4o_0
{ "original_instruction": "In the world of computer security, maintaining secure passwords is paramount. One element of a strong password is that it should not be easily guessable, nor should it contain sequences that can be easily predicted. To aid in this, we need to evaluate passwords to determine if they meet cer...
0.638731
Code_Contests_41877
C
[ "check_passwords", "validate_passwords_from_input" ]
2
[ [ "validate_passwords_from_input", "check_passwords" ] ]
1
[]
false
[]
false
pytest
true
[]
true
28389580c7635a1cb274bfbf3d06e99a80d0664f
c114174c5b8f3b503061fba003b6c4c820880512
v1.0
complete
Code_Contests
Code_Contests_41208_C
from typing import List def hybrid_sort(arr: List[int], threshold: int) -> List[int]: """ Perform a hybrid sort on a list of integers using quicksort and insertion sort. The algorithm uses quicksort for larger partitions and switches to insertion sort when the partitions become smaller than a give...
from typing import List def insertion_sort(arr: List[int], low: int, high: int) -> None: for i in range(low + 1, high + 1): key = arr[i] j = i - 1 while j >= low and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def quicksort(arr: List[int], low:...
def test_hybrid_sort_basic(): assert hybrid_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5], 3) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] def test_hybrid_sort_reverse_order(): assert hybrid_sort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def test_hybrid_sort_all_equal(): assert hybrid_sort([...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, low, high):", "function_name": "insertion_sort", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def quicksort(arr, low, high, threshold):", "function_name": "quicksort", "...
[ 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 insertion_sort(arr: List[int], left: int, right: int) -> None:\n \"\"\"\n Sorts the portion of the array from index 'l...
trial_gpt4o_2
{ "original_instruction": "Roberta is working on a project that requires sorting a large dataset of integers. To optimize her workflow, she decided to implement her own sorting algorithm. One of her colleagues suggested trying a hybrid approach by combining quicksort and insertion sort. The idea is to use quicksort f...
0.624579
Code_Contests_41208
C
[ "insertion_sort", "quicksort", "partition", "hybrid_sort" ]
4
[ [ "hybrid_sort", "quicksort" ], [ "quicksort", "insertion_sort" ], [ "quicksort", "partition" ] ]
3
[]
false
[]
false
pytest
false
[]
true
b96cbd21a5840cad2bc2b68d51fb058e91d7a802
1468053e31685be6834038420a4ebb08d520bdf6
v1.0
complete
Code_Contests
Code_Contests_41647_C
def is_prime(n: int) -> bool: """ Determine if a given number is prime. >>> is_prime(2) True >>> is_prime(4) False >>> is_prime(17) True """ def sum_of_primes_up_to(n: int) -> int: """ Calculate the sum of all primes less than or equal to a given number. >>> sum_of_primes_up_to(10) 17 ...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_of_primes_up_to(n): return sum(i for i in range(2, n + 1) if is_prime(i)...
from solution import is_prime, sum_of_primes_up_to, prime_sums def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False def test_sum_of_primes_up_to(): assert s...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_of_primes_up_to(n):", "function_name": "sum_of_primes_up_to", "parameter_list": "(n)" }, { "docst...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3...
trial_gpt4o_0
{ "original_instruction": "Write a program that takes a positive integer N (1 ≤ N ≤ 1000) and outputs the sum of all prime numbers less than or equal to N.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The first few prime numbers are: 2, 3, 5, 7, 11, ...\n\...
0.730354
Code_Contests_41647
C
[ "is_prime", "sum_of_primes_up_to", "prime_sums" ]
3
[ [ "prime_sums", "sum_of_primes_up_to" ], [ "sum_of_primes_up_to", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5eddcd5e8ac9b335c6d46e29a06390e891a5cbe0
d80a1eb13ab38d1f0709f30bab8b8bdef407d651
v1.0
complete
Code_Contests
Code_Contests_40916_C
class TreeNode: def __init__(self, index, letter): self.index = index self.letter = letter self.left = None self.right = None def build_tree(nodes_info): nodes = {} for idx, letter, left, right in nodes_info: if idx not in nodes: nodes[idx] = TreeNode(idx...
class TreeNode: def __init__(self, index, letter): self.index = index self.letter = letter self.left = None self.right = None def build_tree(nodes_info): nodes = {} for idx, letter, left, right in nodes_info: if idx not in nodes: nodes[idx] = TreeNod...
def test_has_palindromic_path(): n1 = 5 nodes_info1 = [ (1, 'A', 2, 3), (2, 'B', 4, -1), (3, 'C', -1, 5), (4, 'A', -1, -1), (5, 'A', -1, -1) ] assert has_palindromic_path(n1, nodes_info1) == "YES" n2 = 3 nodes_info2 = [ (1, 'A', 2, 3), (2,...
[]
[ 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": "class TreeNode:\n def __init__(self, index, letter):\n self.index = index\n self.letter = letter\n self.left = None\n self.r...
trial_gpt4o_2
{ "original_instruction": "You are given a binary tree, and each node has an uppercase English letter associated with it. Your task is to determine whether there exists a path from the root to a leaf such that the letters along this path, when concatenated, form a palindrome.\n\nA palindrome is a word that reads the ...
0.753053
Code_Contests_40916
C
[ "build_tree", "is_palindrome", "find_palindromic_path", "has_palindromic_path" ]
4
[ [ "find_palindromic_path", "is_palindrome" ], [ "has_palindromic_path", "build_tree" ], [ "has_palindromic_path", "find_palindromic_path" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
f179ec7528ebd6dd1280b02d81382f6b97e7b044
b861b0eb41f19a919da69fadee05f210dbe05038
v1.0
complete
Code_Contests
Code_Contests_41833_C
def is_prime(n: int) -> bool: """ Determine if a number is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True """ def process_input(n: int, test_cases: List[int]) -> List[str]: """ Check a list of numbers and return 'YES...
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 check_prime_numbers(numbers): results ...
from solution import is_prime, process_input def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_process_input(): assert process_input(3, [5, 4, ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def check_prime_numbers(numbers):", "function_name": "check_prime_numbers", "parameter_list": "(numbers)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "## Task\nGiven a list of numbers, write a program to determine if each number is a prime number or not.\n\n### Input\n- The first line contains `N`, the number of test cases.\n- The following lines contain the numbers to be checked.\n\n### Output\n- Print \"YES\" if the number is a prime nu...
0.75744
Code_Contests_41833
C
[ "is_prime", "check_prime_numbers", "process_input" ]
3
[ [ "check_prime_numbers", "is_prime" ], [ "process_input", "check_prime_numbers" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
7a0c32c6a67817f6a58078768ce55921f6282ea9
affbe49bd41d54911302196804db35630cdcc54e
v1.0
complete
Code_Contests
Code_Contests_42091_C
def check_rectangle(n: int, points: List[Tuple[int, int]]) -> str: """ Determines if there is a rectangle with sides parallel to the coordinate axes that contains only the given points as its vertices. >>> check_rectangle(4, [(0, 0), (0, 1), (1, 0), (1, 1)]) "YES" >>> check_rectangle(4, [(0, 0), (2,...
def is_rectangle(points): """ Determines if there is a rectangle with sides parallel to the coordinate axes that contains only the given points as its vertices. """ # Create a set of points for fast lookup point_set = set(points) # Iterate through every pair of points to find two opposi...
from solution import check_rectangle def test_example_1(): points = [(0, 0), (0, 1), (1, 0), (1, 1)] assert check_rectangle(4, points) == "YES" def test_example_2(): points = [(0, 0), (2, 0), (1, 1), (1, 2)] assert check_rectangle(4, points) == "NO" def test_no_rectangle(): points = [(0, 0), (1, ...
[ { "docstring": "Determines if there is a rectangle with sides parallel to the coordinate axes\nthat contains only the given points as its vertices.", "function_declaration": "def is_rectangle(points):", "function_name": "is_rectangle", "parameter_list": "(points)" }, { "docstring": null, ...
[ 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_rectangle(points):\n \"\"\"\n Determines if there exists a rectangle whose sides are parallel to the coordinate axes that contains \n only ...
trial_gpt4o_1
{ "original_instruction": "You are given a list of points in a 2D plane. Your task is to determine if there exists a rectangle whose sides are parallel to the coordinate axes that contains only the given points as its vertices. \n\nInput\n\nThe first line contains an integer n (1 ≤ n ≤ 10^5) – the number of points. E...
0.625338
Code_Contests_42091
C
[ "is_rectangle", "check_rectangle" ]
2
[ [ "check_rectangle", "is_rectangle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5892f94d0dcb3b54a3e041db7d19e99e51925ed1
2b18782ecae42f37673e6dcdd3ace9e7220f3824
v1.0
complete
Code_Contests
Code_Contests_41415_C
def max_subarray_with_even(arr: List[int]) -> int: """ This function returns the maximum sum of a subarray that contains at least one even number. >>> max_subarray_with_even([1, 2, 3, -2, 5, -10]) 9 >>> max_subarray_with_even([-1, -2, -3, -4]) -2 >>> max_subarray_with_even([1, 3, 5, 7, 9, 2, 11,...
def max_subarray_with_even(arr): """ This function returns the maximum sum of a subarray that contains at least one even number. """ n = len(arr) # Initialize current maximum and overall maximum sums current_max = float('-inf') overall_max = float('-inf') # Flag to check if the...
from solution import max_subarray_with_even, solve_puzzle def test_max_subarray_with_even(): assert max_subarray_with_even([1, 2, 3, -2, 5, -10]) == 9 assert max_subarray_with_even([-1, -2, -3, -4]) == -2 assert max_subarray_with_even([1, 3, 5, 7, 9, 2, 11, 6]) == 44 assert max_subarray_with_even([10, ...
[ { "docstring": "This function returns the maximum sum of a subarray that contains at least one even number.", "function_declaration": "def max_subarray_with_even(arr):", "function_name": "max_subarray_with_even", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_with_even(nums):\n n = len(nums)\n max_sum = float('-inf')\n current_sum = 0\n has_even = False\n\n for num in nums:\n ...
trial_gpt4o_1
{ "original_instruction": "John loves solving puzzles. One day he came across a puzzle involving a list of integers. The puzzle required him to find a subarray with the maximum sum. However, this subarray must contain at least one number whose value is even.\n\nGiven a list of integers, write a program to solve this ...
0.674514
Code_Contests_41415
C
[ "max_subarray_with_even", "solve_puzzle" ]
2
[ [ "solve_puzzle", "max_subarray_with_even" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eaab8feb1ac714efe33575d14e83dfc685cb8090
4518973bcaba3bb4772420c77c2b8a385911819c
v1.0
complete
Code_Contests
Code_Contests_41975_C
def lexicographically_smallest_string(T: int, test_cases: List[str]) -> List[str]: """ Given a list of test cases with strings, this function returns the lexicographically smallest string possible after any number of allowed swaps. Args: T: int - the number of test cases test_cases: List[st...
def lexicographically_smallest_string(test_cases): """ Given a list of test cases with strings, this function returns the lexicographically smallest string possible after any number of allowed swaps. """ result = [] for s in test_cases: result.append(''.join(sorted(s))) return result...
from solution import solve def test_lexicographically_smallest_string(): assert solve(4, ["bca", "az", "abac", "zyx"]) == ["abc", "az", "aabc", "xyz"] def test_single_character_strings(): assert solve(3, ["a", "b", "c"]) == ["a", "b", "c"] def test_identical_characters(): assert solve(2, ["aaa", "zzz...
[ { "docstring": "Given a list of test cases with strings, this function returns the lexicographically smallest string possible\nafter any number of allowed swaps.", "function_declaration": "def lexicographically_smallest_string(test_cases):", "function_name": "lexicographically_smallest_string", "par...
[ 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 smallest_lexicographic_string(s):\n \"\"\"\n Given a string s, returns the lexicographically smallest string possible\n after applying the all...
trial_gpt4o_2
{ "original_instruction": "You are given a string s consisting of n lowercase Latin letters.\n\nYou are allowed to perform the following operation any number of times on the string:\n\nChoose any two consecutive characters in the string and swap them.\n\nYour task is to find the lexicographically smallest string poss...
0.757691
Code_Contests_41975
C
[ "lexicographically_smallest_string", "solve" ]
2
[ [ "solve", "lexicographically_smallest_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bbf32431213de48c30c0552e11d088619e4b6aa7
9dc0f20cd6de4064a5ce448ddd7e1d93498aa4d0
v1.0
complete
Code_Contests
Code_Contests_41778_C
def flip_adjacent_cells(grid: List[List[int]], n: int, m: int) -> int: """ Determine the minimum number of flips required to achieve the desired grid configuration. Each cell in the n x m grid contains either a 0 or a 1. The grid needs to be configured such that no adjacent cells have the same value. >>> fl...
def minimum_flips(grid, n, m): # Two possible target grids: # Target 1: Start with 0 and alternate target1 = [[(i + j) % 2 for j in range(m)] for i in range(n)] # Target 2: Start with 1 and alternate target2 = [[(i + j + 1) % 2 for j in range(m)] for i in range(n)] flips1, flips2 = 0, 0 fo...
from solution import flip_adjacent_cells def test_flip_adjacent_cells1(): grid = [ [0, 1, 0], [1, 0, 1], [0, 1, 0] ] assert flip_adjacent_cells(grid, 3, 3) == 0 def test_flip_adjacent_cells2(): grid = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] assert fl...
[ { "docstring": null, "function_declaration": "def minimum_flips(grid, n, m):", "function_name": "minimum_flips", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def flip_adjacent_cells(grid, n, m):", "function_name": "flip_adjacent_cells", "param...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_flips_to_alternate_grid(n, m, grid):\n def count_mismatches(reference):\n mismatches = 0\n for i in range(n):\n for j i...
trial_gpt4o_2
{ "original_instruction": "You are given a 2D grid of size n x m, where each cell contains either a 0 or a 1. The objective is to flip some of the cells (change a 0 to 1 or a 1 to 0) such that the resulting grid contains no adjacent cells with the same value. Two cells are considered adjacent if they share a common e...
0.660199
Code_Contests_41778
C
[ "minimum_flips", "flip_adjacent_cells" ]
2
[ [ "flip_adjacent_cells", "minimum_flips" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a22581efeb5eada2512ac3cd11cc33e06e0539cc
4fbb8288c4619cb1a6ec322773160c937c0f6880
v1.0
complete
Code_Contests
Code_Contests_41854_C
from typing import List, Tuple from collections import defaultdict, deque def find_tree_diameter(n: int, edges: List[Tuple[int, int]]) -> Tuple[int, int, int]: """ Find two nodes such that the distance between them is the largest among all pairs of nodes in the tree. >>> find_tree_diameter(5, [(1, 2), (1,...
import sys from collections import defaultdict, deque def find_furthest_node(start, graph, n): visited = [False] * (n + 1) distance = [0] * (n + 1) queue = deque([start]) visited[start] = True while queue: node = queue.popleft() for neighbor in graph[node]: if not v...
def test_find_tree_diameter_simple(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert find_tree_diameter(n, edges) == (2, 4, 3) or find_tree_diameter(n, edges) == (4,2,3) def test_find_tree_diameter_line(): n = 4 edges = [(1, 2), (2, 3), (3, 4)] assert find_tree_diameter(n, edges) == (1, ...
[ { "docstring": null, "function_declaration": "def find_furthest_node(start, graph, n):", "function_name": "find_furthest_node", "parameter_list": "(start, graph, n)" }, { "docstring": null, "function_declaration": "def find_tree_diameter(n, edges):", "function_name": "find_tree_diame...
[ 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\nfrom collections import deque\n\ndef find_farthest_node(n, adjacency_list, start_node):\n \"\"\"\n Performs BFS to find the farthest node...
trial_gpt4o_1
{ "original_instruction": "A tree is a connected, undirected graph without cycles. Given a tree with `N` nodes labeled from `1` to `N`, you are required to find two nodes such that the distance between them is the largest among all pairs of nodes in the tree. Output the two nodes and the distance between them.\n\n###...
0.740592
Code_Contests_41854
C
[ "find_furthest_node", "find_tree_diameter" ]
2
[ [ "find_tree_diameter", "find_furthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
dcd6fc56250c57d734a7841aa2d4d524d4847e40
6344f5c0f06dbe153d8f45ae1638ee4d77b12bee
v1.0
complete
Code_Contests
Code_Contests_41511_C
def solve_vasya_sequence(n: int, sequence: List[int]) -> str: """ Little Vasya loves sequences and enjoys solving mathematical puzzles. Vasya's game involves an ordered sequence of integers. He defines a special "transformation" operation which is applied as follows: 1. If the sequence length is odd, remov...
def vasya_sequence(n, sequence): removed_elements = [] while sequence: length = len(sequence) mid = length // 2 if length % 2 == 1: removed_elements.append(sequence.pop(mid)) else: removed_elements.append(sequence.pop(mid - 1)) removed_elements...
from solution import solve_vasya_sequence def test_example_1(): assert solve_vasya_sequence(5, [1, 2, 3, 4, 5]) == "3 2 4 1 5" def test_example_2(): assert solve_vasya_sequence(6, [1, 2, 3, 4, 5, 6]) == "3 4 2 5 1 6" def test_single_element(): assert solve_vasya_sequence(1, [1]) == "1" def test_two_elem...
[ { "docstring": null, "function_declaration": "def vasya_sequence(n, sequence):", "function_name": "vasya_sequence", "parameter_list": "(n, sequence)" }, { "docstring": null, "function_declaration": "def solve_vasya_sequence(n, sequence):", "function_name": "solve_vasya_sequence", ...
[ 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 vasya_sequence_transformation(n, sequence):\n \"\"\"\n Performs Vasya's sequence transformation operation repeatedly until the sequence is empty....
trial_gpt4o_1
{ "original_instruction": "Little Vasya loves sequences and enjoys solving mathematical puzzles. One day he came across a sequence game that puzzled him and decided to ask for your help. \n\nVasya's game involves an ordered sequence of integers. He defines a special \"transformation\" operation which is applied as fo...
0.693746
Code_Contests_41511
C
[ "vasya_sequence", "solve_vasya_sequence" ]
2
[ [ "solve_vasya_sequence", "vasya_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43d9a2d4b887bd2bc09375f87dbf9d51b384ae18
0304481726d6f8f48c5ba7f9c0128475dac06373
v1.0
complete
Code_Contests
Code_Contests_41952_C
from typing import List, Tuple from collections import defaultdict, deque def tree_diameter(n: int, edges: List[Tuple[int, int]]) -> int: """ Compute the diameter of a tree. :param n: The number of nodes in the tree. :param edges: The list of edges in the tree. :return: The diameter of the tre...
from collections import deque, defaultdict def find_farthest_node(start, n, tree): """ Perform BFS to find the farthest node and the distance from the start node. :param start: The starting node for BFS. :param n: The number of nodes in the tree. :param tree: The adjacency list representing the tre...
from solution import tree_diameter def test_tree_diameter_example1(): edges = [ (1, 2), (1, 3), (3, 4), (3, 5), ] assert tree_diameter(5, edges) == 4 def test_tree_diameter_example2(): edges = [ (1, 2), (2, 3), ] assert tree_diameter(3, edges) ==...
[ { "docstring": "Perform BFS to find the farthest node and the distance from the start node.\n:param start: The starting node for BFS.\n:param n: The number of nodes in the tree.\n:param tree: The adjacency list representing the tree.\n:return: A tuple of the farthest node and the distance to it.", "function...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque, defaultdict\n\ndef longest_path_length(n, edges):\n if n == 1:\n return 1\n\n def bfs(start_node):\n vis...
trial_gpt4o_3
{ "original_instruction": "You are given a tree (a connected, undirected graph with no cycles) with n vertices, where n is between 1 and 10^5. Each node of the tree is numbered from 1 to n. We need to make the tree valid by ensuring that every pair of nodes in the tree has at least one unique path connecting them, i....
0.635551
Code_Contests_41952
C
[ "find_farthest_node", "tree_diameter" ]
2
[ [ "tree_diameter", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
true
[]
true
25de7bb7f3e0f1de2d0dcd92c7d2b826a9cea7d6
e107b01b194123583c1ecd3e005908f77418ca8f
v1.0
complete
Code_Contests
Code_Contests_42526_C
def is_prime(n: int) -> bool: """Check if a number is prime. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False """ pass def is_palindrome(n: int) -> bool: """Check if a number is a palindrome. >>> is_palindrome(121) == True >>> is_palindrome(123) == False ...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def is_p...
from solution import smallest_prime_palindrome def test_example_case(): assert smallest_prime_palindrome(31) == 101 def test_smallest_numbers(): assert smallest_prime_palindrome(1) == 2 assert smallest_prime_palindrome(2) == 2 assert smallest_prime_palindrome(3) == 3 def test_next_prime_palindrome():...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", ...
[ 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_1
{ "original_instruction": "Problem description.\n\nMason loves prime numbers and also palindromes. He came up with a challenge to test his friends. He asked them to find the smallest prime palindrome greater than or equal to a given number N. A number is called a palindrome if it reads the same backward as forward.\n...
0.714609
Code_Contests_42526
C
[ "is_prime", "is_palindrome", "smallest_prime_palindrome" ]
3
[ [ "smallest_prime_palindrome", "is_palindrome" ], [ "smallest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d3ad2d21cf632cdc5d16515c3d8ef5f85a99ff25
30c221d0a883d520e0fb44ab4cd66a8318015be4
v1.0
complete
Code_Contests
Code_Contests_42064_C
class TreeNode: def __init__(self): self.connections = [] def min_travel_cost(n: int, roads: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]: """ Calculate the minimum travel cost for each pair of cities given. Args: n (int): the number of cities. roads (List[T...
class TreeNode: def __init__(self): self.connections = [] def dfs(node, parent, graph, cost): for neighbor, weight in graph[node].connections: if neighbor != parent: cost[neighbor] = cost[node] + weight dfs(neighbor, node, graph, cost) def preprocess_lca(n, graph, root=...
from solution import min_travel_cost def test_min_travel_cost_simple(): n = 5 roads = [(1, 2, 3), (1, 3, 2), (2, 4, 4), (2, 5, 1)] queries = [(1, 4), (3, 5), (4, 5)] assert min_travel_cost(n, roads, queries) == [7, 6, 5] def test_min_travel_cost_complex(): n = 6 roads = [(1, 2, 1), (2, 3, 1), ...
[]
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport heapq\nfrom collections import defaultdict\n\ndef min_travel_cost(n, roads, queries):\n def dijkstra(start):\n dist = {i: floa...
trial_gpt4o_2
{ "original_instruction": "In a given country, there are multiple cities connected by roads. Each road connects exactly two cities and has a travel cost associated with it. Cities are numbered from 1 to n, and there are exactly n-1 roads, ensuring that every city can be reached from any other city, meaning the cities...
0.65297
Code_Contests_42064
C
[ "dfs", "preprocess_lca", "get_lca", "min_travel_cost" ]
4
[ [ "min_travel_cost", "get_lca" ], [ "min_travel_cost", "preprocess_lca" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
39b067c335481b678fd805135b75f32268ca5bf3
aca127724d90fbb9b8fde57eb293dc8cb75333a0
v1.0
complete
Code_Contests
Code_Contests_41915_C
from typing import List, Tuple def dijkstra(n: int, graph: Dict[int, List[Tuple[int, int]]], start: int) -> Dict[int, int]: """ Runs Dijkstra's algorithm to find the shortest path from the start node to all other nodes in the graph. """ pass def shortest_travel_times(n: int, m: int, q: int, edges: List[Tu...
import heapq from collections import defaultdict def dijkstra(n, graph, start): distances = {i: float('inf') for i in range(1, n+1)} distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if c...
from solution import shortest_travel_times def test_example_1(): n, m, q = 4, 5, 2 edges = [ (1, 2, 4), (1, 3, 2), (2, 3, 5), (2, 4, 10), (3, 4, 3) ] queries = [ (1, 4), (2, 3) ] assert shortest_travel_times(n, m, q, edges, queries) == [5,...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def shortest_travel_times(n, m, q, edges, queries):", "function_name": "shortest_travel_t...
[ 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(graph, start):\n n = len(graph)\n distances = [float('inf')] * n\n distances[start] = 0\n pq = [(0, start)]\n w...
trial_gpt4o_2
{ "original_instruction": "Warehouses and Deliveries\n\nYou have been contracted by a logistics company to optimize their delivery routes between different warehouses. The company has a network of warehouses and direct routes connecting them. Each direct route has a designated travel time, and not all warehouses are ...
0.685398
Code_Contests_41915
C
[ "dijkstra", "shortest_travel_times" ]
2
[ [ "shortest_travel_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af118853695e5f23e38c92707efc735c35032a07
2263c45b92058d57d2aa760c489d296d300f142a
v1.0
complete
Code_Contests
Code_Contests_42558_C
def sum_of_digits(uin: str) -> int: """ Computes the check digit for the given UIN. """ # Insert code here def process_uins(uins: List[str]) -> List[int]: """ Processes a list of UIN strings, computing the check digit for each. """ # Insert code here # Example usage: # uins = ["9875", ...
def sum_of_digits(uin): """ Computes the check digit for the given UIN. """ while len(uin) > 1: uin = str(sum(int(digit) for digit in uin)) return int(uin) def process_uins(uins): """ Processes a list of UIN strings, computing the check digit for each. """ results = [] f...
from solution import sum_of_digits, process_uins def test_sum_of_digits_single_digit(): assert sum_of_digits("5") == 5 def test_sum_of_digits_multiple_iterations(): assert sum_of_digits("9875") == 2 assert sum_of_digits("12345") == 6 def test_process_uins_with_termination(): assert process_uins(["987...
[ { "docstring": "Computes the check digit for the given UIN.", "function_declaration": "def sum_of_digits(uin):", "function_name": "sum_of_digits", "parameter_list": "(uin)" }, { "docstring": "Processes a list of UIN strings, computing the check digit for each.", "function_declaration": "...
[ 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 check_digit(uin):\n \"\"\"\n Returns the check digit for a given UIN by repeatedly summing the digits until a single-digit number is obtained.\n ...
trial_gpt4o_2
{ "original_instruction": "Sum of Digits\n\nIn the United Kingdom of XYZ, every citizen is required to have a unique identification number called the Unique Identity Number (UIN). This number is a positive integer composed of up to 64 digits.\n\nThe government decides to introduce a security system where citizens' UI...
0.524663
Code_Contests_42558
C
[ "sum_of_digits", "process_uins" ]
2
[ [ "process_uins", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0a6266aaecc554eb139a17f93f88c708d14a93f
d44738718f2ac6717689cf8c9f9ee3501213f1f6
v1.0
complete
Code_Contests
Code_Contests_42104_C
def is_prime(n): """ Check if a number n is a prime number. """ pass def sum_of_primes(nums): """ Returns the sum of prime numbers in the list nums. """ pass def process_test_cases(test_cases): """ Process multiple test cases. Each test case is represented as a tuple (N, intege...
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_of_primes(nums): ...
from solution import is_prime, sum_of_primes, decode_message 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(11) == True assert is_prime(20) == False def test_sum_of_primes(): assert sum_of_pr...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of prime numbers in the list nums.", "function_declaration": "def sum_of_primes(nums):", "funct...
[ 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 is_prime(n):\n \"\"\"\n Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return ...
trial_gpt4o_0
{ "original_instruction": "Sherlock is back on the case, deciphering yet another cryptic message. This time, Moriarty has sent him a sequence of N integers, and Sherlock must decode the message's true meaning by identifying prime numbers and summing them up.\n\nHelp Sherlock by writing a program that takes a list of ...
0.716751
Code_Contests_42104
C
[ "is_prime", "sum_of_primes", "process_test_cases", "decode_message" ]
4
[ [ "decode_message", "process_test_cases" ], [ "process_test_cases", "sum_of_primes" ], [ "sum_of_primes", "is_prime" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
e908a7e65d82c906c93d0a449a6c5d342015137e
0393d95ac20a2dbb8fc32a883704794c3cfcde94
v1.0
complete
Code_Contests
Code_Contests_42279_C
def can_be_palindrome(s: str) -> str: """ Determine if it is possible to transform the given string into a palindrome by changing at most one character. >>> can_be_palindrome("abca") "YES" >>> can_be_palindrome("abcba") "YES" >>> can_be_palindrome("abcde") "NO" >>> can_be_palindrome("a")...
def can_become_palindrome(s): """ Checks if the given string can be transformed into a palindrome by changing at most one character. """ def is_palindrome_range(i, j): while i < j: if s[i] != s[j]: return False i += 1 j -= 1 return True...
from solution import can_be_palindrome def test_case_1(): assert can_be_palindrome("abca") == "YES" def test_case_2(): assert can_be_palindrome("abcba") == "YES" def test_case_3(): assert can_be_palindrome("abcde") == "NO" def test_single_char(): assert can_be_palindrome("a") == "YES" def test_two_...
[ { "docstring": "Checks if the given string can be transformed into a palindrome by changing at most one character.", "function_declaration": "def can_become_palindrome(s):", "function_name": "can_become_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_palindrome_with_one_change(s):\n \"\"\"\n Determines if the string can be changed into a palindrome by changing at most one character.\n ...
trial_gpt4o_9
{ "original_instruction": "In a faraway kingdom named Techland, a new programming competition is being held. Each participant in the competition is given a string, and they need to transform it into a palindrome by performing at most one character replacement.\n\nA string is considered a palindrome if it reads the sa...
0.81415
Code_Contests_42279
C
[ "can_become_palindrome", "can_be_palindrome" ]
2
[ [ "can_be_palindrome", "can_become_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4266f657afdf51f97e6218ebdf6da412a4053a4f
199b43efbc762b89ceb43605eec3b6219b971bc3
v1.0
complete
Code_Contests
Code_Contests_42167_C
from collections import defaultdict, deque MOD = 10**9 + 7 def count_paths_in_dag(N, M, edges): """ Given a directed acyclic graph (DAG) with N nodes numbered 1 to N and M edges, where the i-th edge is directed from node u_i to node v_i, find the number of different paths from the node numbered 1 to the n...
from collections import defaultdict, deque MOD = 10**9 + 7 def count_paths_in_dag(N, M, edges): adj_list = defaultdict(list) in_degree = [0] * (N + 1) for u, v in edges: adj_list[u].append(v) in_degree[v] += 1 # Topological sort (Kahn's algorithm) topological_order = [] ...
def test_count_paths(): assert count_paths_in_dag(4, 4, [(1, 2), (2, 3), (3, 4), (1, 3)]) == 2 assert count_paths_in_dag(5, 6, [(1, 2), (1, 3), (2, 4), (3, 4), (4, 5), (2, 5)]) == 3 assert count_paths_in_dag(2, 1, [(1, 2)]) == 1 assert count_paths_in_dag(3, 2, [(1, 2), (2, 3)]) == 1 assert count_pat...
[ { "docstring": null, "function_declaration": "def count_paths_in_dag(N, M, edges):", "function_name": "count_paths_in_dag", "parameter_list": "(N, M, edges)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "parameter_list": "()" } ]
[ 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 count_paths_in_dag(n, edges):\n from collections import defaultdict, deque\n\n MOD = 10**9 + 7\n \n # Create the adjacency list\n graph ...
trial_gpt4o_1
{ "original_instruction": "Given a directed acyclic graph (DAG) with N nodes numbered 1 to N and M edges, where the i-th edge is directed from node u_i to node v_i, solve the following problem:\n\n* Find the number of different paths from the node numbered 1 to the node numbered N in the graph. Given that the number ...
0.666865
Code_Contests_42167
C
[ "count_paths_in_dag", "solve" ]
2
[ [ "solve", "count_paths_in_dag" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c03ed1139a2f24c6f845856a508646765207d591
12266f7cc24e84a1fa80ae297cffbdba52040e18
v1.0
complete
Code_Contests
Code_Contests_42534_C
import re from typing import List def is_valid_password(password: str) -> bool: """Checks if the given password meets the new policy requirements. A valid password must have the following characteristics: - At least 8 characters long - Contains at least one uppercase letter - Contains at least one ...
import re def is_valid_password(password): """ Checks if the given password meets the new policy requirements. """ if len(password) < 8: return False if not re.search(r'[A-Z]', password): return False if not re.search(r'[a-z]', password): return False if not re.searc...
from solution import is_valid_password, check_passwords def test_is_valid_password(): assert is_valid_password("Password123!") == True assert is_valid_password("password123") == False assert is_valid_password("PASSWORD123!") == False assert is_valid_password("Passw0rd") == False assert is_valid_pas...
[ { "docstring": "Checks if the given password meets the new policy requirements.", "function_declaration": "def is_valid_password(password):", "function_name": "is_valid_password", "parameter_list": "(password)" }, { "docstring": "Given a list of passwords, return a list of \"YES\" or \"NO\" ...
[ 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\n\ndef is_valid_password(password):\n if len(password) < 8:\n return \"NO\"\n if not re.search(r'[A-Z]', password):\n return ...
trial_gpt4o_2
{ "original_instruction": "A company is launching a new password policy to strengthen security. The new policy mandates that a valid password must have the following characteristics:\n- At least 8 characters long\n- Contains at least one uppercase letter\n- Contains at least one lowercase letter\n- Contains at least ...
0.601644
Code_Contests_42534
C
[ "is_valid_password", "check_passwords" ]
2
[ [ "check_passwords", "is_valid_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
426ded9a1d8a40777bcb39e0d852ab8f300b65c8
c6966355b5084a8f44bf7e9ee26d509d67616b26
v1.0
complete
Code_Contests
Code_Contests_42494_C
from typing import List def determine_sequence(n: int, m: int, grid: List[str]) -> str: """ Determines the sequence of moves to place the watering system in the target cell. Args: n (int): Number of rows in the farm grid. m (int): Number of columns in the farm grid. grid (List[str]): De...
from collections import deque # Directions for moving and pushing the system & corresponding changes in coordinates dirs = [("U", -1, 0), ("D", 1, 0), ("L", 0, -1), ("R", 0, 1)] pdirs = {"U": ("PU", -2, 0), "D": ("PD", 2, 0), "L": ("PL", 0, -2), "R": ("PR", 0, 2)} def bfs(start, is_valid): """ Standard BFS for sh...
from solution import main from io import StringIO import sys def test_possible_case_1(capsys): input_str = "5 5\n.....\n.R..X\n..X..\n..W..\n....T\n" sys.stdin = StringIO(input_str) main(5, 5, [ ".....", ".R..X", "..X..", "..W..", "....T" ]) captured = capsys...
[ { "docstring": "Standard BFS for shortest path search ", "function_declaration": "def bfs(start, is_valid):", "function_name": "bfs", "parameter_list": "(start, is_valid)" }, { "docstring": "Returns a function for valid cell checking ", "function_declaration": "def is_valid_factory(n, m,...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_shortest_path(grid, start, end, robot_initial):\n n, m = len(grid), len(grid[0])\n directions = [('U', -1, ...
trial_gpt4o_9
{ "original_instruction": "A grid-based farm has dimensions n x m, containing several types of cells - open land for planting crops (.), rocks that cannot be moved (X), and a watering system that should be placed in one specific cell (W). A robot placed on one of the open land cells must navigate the farm to place th...
0.618145
Code_Contests_42494
C
[ "bfs", "is_valid_factory", "determine_sequence", "main" ]
4
[ [ "determine_sequence", "bfs" ], [ "determine_sequence", "is_valid_factory" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ae7a91bf45e09c4587196c30008670d6239c182e
486c1406ac8168a39cd5fba0982f57e6b79a0ae1
v1.0
complete
Code_Contests
Code_Contests_42346_C
def solve(n: int, initial_tree: List[Tuple[int, int, int]], target_tree: List[Tuple[int, int, int]]) -> str: """ Determine if it is possible to transform the initial binary tree into a target binary tree. Args: n: int - number of nodes in the trees initial_tree: list of tuples describing the initial tr...
class TreeNode: def __init__(self, value=-1, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(node_descriptors): nodes = {} for desc in node_descriptors: value, left, right = desc if value not in nodes: nodes[v...
def test_basic_case(): initial_tree = [ (1, 2, 3), (2, 4, -1), (3, -1, 5), (4, -1, -1), (5, -1, 6), (6, -1, -1) ] target_tree =[ (1, 3, 2), (3, 5, -1), (2, 6, 4), (5, -1, -1), (6, -1, -1), (4, -1, -1) ] ...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\...
trial_gpt4o_2
{ "original_instruction": "You are a prisoner in a strange world with only your laptop as a companion. Suddenly, a mystical creature appears, offering you freedom if you can solve the following challenge:\n\nYou are given a binary tree with `n` nodes, where each node has a unique value from `1` to `n`. For each node,...
0.633351
Code_Contests_42346
C
[ "build_tree", "trees_are_identical", "swap_children", "can_transform", "solve" ]
5
[ [ "can_transform", "swap_children" ], [ "can_transform", "trees_are_identical" ], [ "solve", "build_tree" ], [ "solve", "can_transform" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
52485405ac412a06afa9c348c6c0e8a1c51b7323
fb1b8891211279da62ee9b93a3c47640ea8f846a
v1.0
complete
Code_Contests
Code_Contests_41761_C
def transpose_matrix(matrix: List[List[int]]) -> List[List[int]]: """ Returns the transpose of the given MxN matrix as a new NxM matrix. >>> transpose_matrix([ >>> [1, 2, 3, 4], >>> [5, 6, 7, 8], >>> [9, 10, 11, 12] >>> ]) [ >>> [1, 5, 9], >>> [2, 6, 10], >>> [3, 7,...
def transpose_matrix(matrix): """ Returns the transpose of the given MxN matrix as a new NxM matrix. """ M = len(matrix) N = len(matrix[0]) transposed = [[0]*M for _ in range(N)] for i in range(M): for j in range(N): transposed[j][i] = matrix[i][j] return transposed ...
from solution import transpose_matrix, transpose_input_matrix def test_transpose_matrix(): matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ] expected = [ [1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12] ] assert transpose_matrix(matrix) ==...
[ { "docstring": "Returns the transpose of the given MxN matrix as a new NxM matrix.", "function_declaration": "def transpose_matrix(matrix):", "function_name": "transpose_matrix", "parameter_list": "(matrix)" }, { "docstring": "Parses the input and returns the transposed matrix.", "functi...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def transpose_matrix(matrix, M, N):\n \"\"\"\n Returns the transposed matrix of given MxN matrix.\n \n Parameters:\n - matrix (list of lists...
trial_gpt4o_2
{ "original_instruction": "Write a program that transposes a given MxN matrix. The transposed matrix is obtained by changing the rows into columns and the columns into rows.\n\nInput\n\nThe first line of input contains two integers M and N (1 ≤ M, N ≤ 100), representing the number of rows and columns of the matrix. T...
0.550078
Code_Contests_41761
C
[ "transpose_matrix", "transpose_input_matrix" ]
2
[ [ "transpose_input_matrix", "transpose_matrix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24205251098c08df51607c5a3d0a3086378b39e3
316662d72a2c73e886ceadfc4e51fbb2e3ca1c1c
v1.0
complete
Code_Contests
Code_Contests_41170_C
from collections import defaultdict import heapq from typing import List, Tuple def shortest_path(num_rooms: int, num_doorways: int, edges: List[Tuple[int, int]], start_room: int) -> List[int]: """ Calculate the shortest path from the starting room to all other rooms. """ # Your implementation here def au...
import heapq from collections import defaultdict def shortest_path(num_rooms, num_doorways, edges, start_room): graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) distances = {i: float('infinity') for i in range(1, num_rooms + 1)} distances[start_roo...
def test_shortest_path(): num_rooms, num_doorways = 5, 6 edges = [(1, 2), (1, 3), (1, 4), (2, 5), (3, 5), (4, 5)] start_room = 1 assert shortest_path(num_rooms, num_doorways, edges, start_room) == [0, 1, 1, 1, 2] num_rooms, num_doorways = 4, 3 edges = [(1, 2), (1, 3), (2, 4)] start_room = 2...
[ { "docstring": null, "function_declaration": "def shortest_path(num_rooms, num_doorways, edges, start_room):", "function_name": "shortest_path", "parameter_list": "(num_rooms, num_doorways, edges, start_room)" }, { "docstring": null, "function_declaration": "def automated_cleaning(t, dat...
[ 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": "from collections import deque, defaultdict\n\ndef shortest_path_to_all_rooms(num_rooms, num_doorways, edges, start_room):\n graph = defaultdict(list)\n ...
trial_gpt4o_7
{ "original_instruction": "You are given an abandoned paint factory with multiple rooms that need cleaning and inspection. To make this process efficient, you have decided to automate this task. Each room in the factory is connected by a series of doorways, and you need to determine a path for your cleaning robot to ...
0.582286
Code_Contests_41170
C
[ "shortest_path", "automated_cleaning", "read_input" ]
3
[ [ "automated_cleaning", "shortest_path" ] ]
1
[ "read_input" ]
false
[]
false
pytest
false
[]
true
0f0e576016bb5887aed820eaac1bb8c1ee98884f
17767ddfcb75064e945b1c27a84c885d1c9944c7
v1.0
complete
Code_Contests
Code_Contests_42620_C
def is_prime(num): """ Helper function to check if a number is prime. >>> is_prime(2) True >>> is_prime(4) False """ # Implementation goes here def count_prime_numbers(lists): """ Takes a list of lists of numbers and returns a list of counts of prime numbers in each sublist. >>>...
def is_prime(num): """ Helper function to check if a number is prime """ if num <= 1: return False if num == 2: return True # 2 is the only even prime number if num % 2 == 0: return False # Other even numbers are not primes for i in range(3, int(num**0.5) + 1, 2): ...
from solution import count_prime_numbers def test_valid_case(): assert count_prime_numbers([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 13, 17, 19, 23, 24, 25, 26]]) == [4, 5] def test_zero_lists(): assert count_prime_numbers([]) == "Invalid Test" def test_too_many_lists(): lists = [[1] for _ in range(11)] ...
[ { "docstring": "Helper function to check if a number is prime ", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Takes a list of lists of numbers and returns a list of counts of prime numbers in each sublist.", "func...
[ 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_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n elif num == 2:\n return Tru...
trial_gpt4o_1
{ "original_instruction": "Jack loves prime numbers. According to him, a prime number is an integer greater than 1 that has no positive divisors other than 1 and itself.\nWhile preparing for a math competition, he encounters many lists of numbers and wants to find prime numbers in these lists.\nHe also wants to count...
0.790936
Code_Contests_42620
C
[ "is_prime", "count_prime_numbers" ]
2
[ [ "count_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ed8265c740b53677186cd5a1ff168ad570118ff1
65a656ba84cf8dc768187063d4c0755789259a0d
v1.0
complete
Code_Contests
Code_Contests_41856_C
from typing import List, Tuple def minimal_enclosing_circles(T: int, tests: List[Tuple[int, List[Tuple[int, int]]]]) -> List[str]: """ Find the smallest circle that encloses all the given points for multiple test cases. Parameters: T (int): Number of test cases. tests (List[Tuple[int, List[Tu...
import math import random def dist(a, b): return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) def is_in_circle(point, circle): center, radius = circle return dist(point, center) <= radius def circle_from_two_points(p1, p2): center = ((p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2) radius = dist(p...
import pytest from solution import minimal_enclosing_circles def test_case_1(): T = 2 tests = [ (3, [(1, 1), (2, 2), (3, 3)]), (4, [(2, 2), (2, -2), (-2, -2), (-2, 2)]) ] expected = ["2.000000 2.000000 1.414214", "0.000000 0.000000 2.828427"] assert minimal_enclosing_circles(T, test...
[ { "docstring": null, "function_declaration": "def dist(a, b):", "function_name": "dist", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def is_in_circle(point, circle):", "function_name": "is_in_circle", "parameter_list": "(point, circle)" }, { ...
[ 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\nimport random\n\ndef dist(a, b):\n return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)\n\ndef is_in_circle(point, circle):\n cente...
trial_gpt4o_0
{ "original_instruction": "You are given a set of points in a two-dimensional plane. Your task is to find the smallest circle that encloses all the given points. This problem is known as finding the Minimum Enclosing Circle (MEC). \n\nInput\nThe first line contains an integer T (1 ≤ T ≤ 1000) denoting the number of t...
0.58537
Code_Contests_41856
C
[ "dist", "is_in_circle", "circle_from_two_points", "circle_from_three_points", "min_enclosing_circle", "minimal_enclosing_circles" ]
6
[ [ "circle_from_three_points", "dist" ], [ "circle_from_two_points", "dist" ], [ "is_in_circle", "dist" ], [ "min_enclosing_circle", "circle_from_three_points" ], [ "min_enclosing_circle", "circle_from_two_points" ], [ "min_enclosing_circle", "is_in...
7
[]
false
[]
false
pytest
true
[]
true
f77f77f68796599de7692baeef1896e5c3fc2abd
fa283782380f38ed72d20968180469d2b88af5a6
v1.0
complete
Code_Contests
Code_Contests_42876_C
from typing import List def is_prime(n: int) -> bool: """ Determine if a number is a prime number. >>> is_prime(0) False >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True """ def smallest_prime_greater_than(N: int) -> int: ...
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 smallest_prime_greater_than(N): candid...
from solution import is_prime, smallest_prime_greater_than def test_is_prime(): assert not is_prime(0) assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(6) assert is_prime(7) assert not is_prime(9) assert i...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def smallest_prime_greater_than(N):", "function_name": "smallest_prime_greater_than", "parameter_list": "(N)" }...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if the number is prime, otherwise False\n \"\"\"\n if num <= 1:\n return False\n if num <=...
trial_gpt4o_2
{ "original_instruction": "Calculate the smallest prime number that is greater than a given integer N.\n\nConstraints\n\n* 0 \\leq N \\leq 10^6\n\nInput\n\nInput is given from Standard Input in the following format:\n\n\nN\n\n\nOutput\n\nPrint the smallest prime number greater than N.\n\nExamples\n\nInput\n\n10\n\n\n...
0.778192
Code_Contests_42876
C
[ "is_prime", "smallest_prime_greater_than" ]
2
[ [ "smallest_prime_greater_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
54e42801385e8ef82be85921a41e34824eaa8f86
61e4a683c00bc5c50c386fe31b8b2ffee6c6189b
v1.0
complete
Code_Contests
Code_Contests_41272_C
def is_valid_sudoku(board): """ Check if a given 9x9 Sudoku board is valid. Args: board (list of list of str): a 9x9 grid where each cell is either a digit '1'-'9' or '.' Returns: bool: True if the board is valid, False otherwise """ # Check if all rows are valid for row in...
def is_valid_sudoku(board): """ Check if a given 9x9 Sudoku board is valid. Args: board (list of list of str): a 9x9 grid where each cell is either a digit '1'-'9' or '.' Returns: bool: True if the board is valid, False otherwise """ # Check if all rows are valid for row in...
from solution import is_valid_sudoku def test_valid_sudoku(): board = [ ["5", "3", ".", ".", "7", ".", ".", ".", "."], ["6", ".", ".", "1", "9", "5", ".", ".", "."], [".", "9", "8", ".", ".", ".", ".", "6", "."], ["8", ".", ".", ".", "6", ".", ".", ".", "3"], ["4", ".", ".",...
[ { "docstring": "Check if a given 9x9 Sudoku board is valid.\n\nArgs:\nboard (list of list of str): a 9x9 grid where each cell is either a digit '1'-'9' or '.'\n\nReturns:\nbool: True if the board is valid, False otherwise", "function_declaration": "def is_valid_sudoku(board):", "function_name": "is_vali...
[ 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_valid_sudoku(board):\n def is_valid_block(block):\n block = [num for num in block if num != '.']\n return len(block) == len(set(blo...
trial_gpt4o_2
{ "original_instruction": "James is practicing for a Sudoku competition, and he needs a program that checks if a completed 9x9 Sudoku board is valid. A valid Sudoku board means that:\n1. Each row contains the numbers 1-9 with no repetition.\n2. Each column contains the numbers 1-9 with no repetition.\n3. Each of the ...
0.628894
Code_Contests_41272
C
[ "is_valid_sudoku", "is_valid_unit" ]
2
[ [ "is_valid_sudoku", "is_valid_unit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1e6df658247d4ae546eba3d0060b34ce1f8b529e
ca709eaee62e7315d8df418a075a56a80d2aedb9
v1.0
complete
Code_Contests
Code_Contests_42535_C
def count_unique_colors(n: int, color_ratios: List[Tuple[int, int, int]]) -> int: """ Determine the number of unique colors Mike can create based on the given color ratios. :param n: The number of colors Mike wants to create. :param color_ratios: A list of tuples, each containing three integers that re...
import math def gcd(x, y): while y: x, y = y, x % y return x def normalize_color(r, g, b): g_value = gcd(gcd(r, g), b) return (r // g_value, g // g_value, b // g_value) def count_unique_colors(n, color_ratios): unique_colors = set() for r, g, b in color_ratios: normalized = no...
from solution import count_unique_colors def test_basic_examples(): assert count_unique_colors(5, [(2, 4, 6), (1, 2, 3), (3, 3, 9), (2, 2, 6), (5, 6, 7)]) == 3 assert count_unique_colors(4, [(1, 1, 1), (10, 10, 10), (2, 2, 2), (1, 1, 1)]) == 1 assert count_unique_colors(3, [(1, 2, 3), (2, 4, 6), (3, 5, 9)]...
[ { "docstring": null, "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def normalize_color(r, g, b):", "function_name": "normalize_color", "parameter_list": "(r, g, b)" }, { "docst...
[ 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 normalize_ratio(r, g, b):\n \"\"\"\n Normalize the color ratios by dividing each by their g...
trial_gpt4o_2
{ "original_instruction": "Mike loves playing with colors. He has an unlimited supply of three primary colors: red, green, and blue. He wants to mix these primary colors to form various new colors. Each new color Mike wants to create requires a specific quantity of red, green, and blue. Given a list of ratios for eac...
0.621489
Code_Contests_42535
C
[ "gcd", "normalize_color", "count_unique_colors" ]
3
[ [ "count_unique_colors", "normalize_color" ], [ "normalize_color", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
454b2d039fccedac9d689143557cb958ad212a57
28205b2a0d219c5d4f77cc037099d2320bfee5ef
v1.0
complete
Code_Contests
Code_Contests_41007_C
def max_deliveries(n: int, k: int, edges: List[Tuple[int, int]], couriers: List[int], pairs: List[Tuple[int, int]]) -> int: """ Determine the maximum number of deliveries that can be successfully made. Parameters: n (int): Number of cities. k (int): Number of couriers. edges (List[Tuple[int, in...
from collections import defaultdict, deque def bfs_distances(n, edges): """ Calculate distances between all pairs of cities using BFS with the distances stored for each root node. """ def bfs(start): dist = {i: float('inf') for i in range(1, n+1)} dist[start] = 0 queue = deque([...
from solution import max_deliveries def test_example_case(): n = 5 k = 3 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] couriers = [3, 2, 4] pairs = [(1, 2), (2, 4), (1, 5), (4, 5)] assert max_deliveries(n, k, edges, couriers, pairs) == 3 def test_case_deliveries_less_than_couriers(): n = 4...
[ { "docstring": "Calculate distances between all pairs of cities using BFS with the distances stored for each root node.", "function_declaration": "def bfs_distances(n, edges):", "function_name": "bfs_distances", "parameter_list": "(n, edges)" }, { "docstring": "Returns the maximum number of ...
[ 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 max_message_deliveries(n, k, roads, couriers, requests):\n from collections import defaultdict, deque\n\n # Create adjacency list for the cities\...
trial_gpt4o_7
{ "original_instruction": "In the land of PixelLand, there are n cities connected by n-1 bidirectional roads such that there is exactly one path between any two cities. The cities are labeled from 1 to n. Quantum, who is a lover of puzzles, wants to send messages between pairs of cities using special couriers.\n\nHow...
0.618467
Code_Contests_41007
C
[ "bfs_distances", "max_deliveries" ]
2
[ [ "max_deliveries", "bfs_distances" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98458ca3b0b7f6679d3bd5197b094600caee2c08
e1ec6aa31c75657cec136514a620a9bc8fec5bc4
v1.0
complete
Code_Contests
Code_Contests_42207_C
def minimum_spanning_tree(n: int, edges: List[Tuple[int, int, int]]) -> int: """ Compute the length of the minimum spanning tree of the graph. >>> minimum_spanning_tree(4, [(0, 1, 3), (0, 2, 1), (3, 1, 2), (2, 1, 4), (3, 2, 5)]) 6 >>> minimum_spanning_tree(3, [(0, 1, 1), (1, 2, 2), (2, 0, 3)]) 3 ...
import heapq def find(parent, u): if parent[u] == u: return u parent[u] = find(parent, parent[u]) return parent[u] def union(parent, rank, u, v): root_u = find(parent, u) root_v = find(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[root_...
def test_example_case(): n = 4 edges = [ (0, 1, 3), (0, 2, 1), (3, 1, 2), (2, 1, 4), (3, 2, 5) ] assert minimum_spanning_tree(n, edges) == 6 def test_case_all_nodes_connected(): n = 3 edges = [ (0, 1, 1), (1, 2, 2), (2, 0, 3) ]...
[ { "docstring": null, "function_declaration": "def find(parent, u):", "function_name": "find", "parameter_list": "(parent, u)" }, { "docstring": null, "function_declaration": "def union(parent, rank, u, v):", "function_name": "union", "parameter_list": "(parent, rank, u, v)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni...
trial_gpt4o_2
{ "original_instruction": "In a certain kingdom, the roads can be represented as an undirected, connected graph with `n` towns and `m` bidirectional roads between them. Each road has a certain positive length associated with it. The towns are numbered from 1 to n. The townspeople have recently decided to conduct a ma...
0.698709
Code_Contests_42207
C
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
ef1c426d0df903da505378e8c5a2217db6959949
b7b840f084436c2fd88df84edafcd2ee7f97384f
v1.0
complete
Code_Contests
Code_Contests_41764_C
def is_winning_position(x, y): """ Determines if (x, y) is a winning position. A winning position (x, y) is when x == y. """ def count_winning_positions(X1, X2, Y1, Y2): """ Counts the number of winning positions (X, Y) within the given bounds. """ def process_test_cases(T, cases): ...
import math def is_winning_position(x, y): """ Determines if (x, y) is a winning position. A winning position (x, y) is when x == y. """ return x == y def count_winning_positions(X1, X2, Y1, Y2): """ Counts the number of winning positions (X, Y) within the given bounds. """ count =...
from solution import is_winning_position, count_winning_positions, process_test_cases def test_is_winning_position(): assert is_winning_position(1, 1) == True assert is_winning_position(1, 2) == False assert is_winning_position(2, 2) == True assert is_winning_position(3, 4) == False def test_count_win...
[ { "docstring": "Determines if (x, y) is a winning position.\nA winning position (x, y) is when x == y.", "function_declaration": "def is_winning_position(x, y):", "function_name": "is_winning_position", "parameter_list": "(x, y)" }, { "docstring": "Counts the number of winning positions (X, ...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "import math\n\ndef is_winning_position(x, y):\n # If gcd of x and y is greater than 1, then it's not a winning position\n re...
trial_gpt4o_2
{ "original_instruction": "Alice and Bob are playing a number game. They start with two positive integers, X and Y, written on a whiteboard. In each move, a player can choose any positive integer d such that d divides both X and Y, and subtract d from either X or Y. The player who cannot make a move because one of th...
0.66399
Code_Contests_41764
C
[ "is_winning_position", "count_winning_positions", "process_test_cases" ]
3
[ [ "count_winning_positions", "is_winning_position" ], [ "process_test_cases", "count_winning_positions" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
67e89814379bc80ab208f4c2dcc420c7cd69bcac
01873b0cd897921a57bc2c8c565980d8a93fdfa6
v1.0
complete
Code_Contests
Code_Contests_42128_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def insert_into_bst(root, val): if root is None: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def insert_into_bst(root, val): if root is None: return TreeNode(val) if val < root.val: root.left = insert_into_bst(root.left, val) else: ...
from solution import find_kth_smallest def test_example1(): N = 7 values = [5, 3, 8, 1, 4, 7, 10] k = 3 assert find_kth_smallest(N, values, k) == 4 def test_example2(): N = 3 values = [2, 1, 3] k = 1 assert find_kth_smallest(N, values, k) == 1 def test_example3(): N = 5 values...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_0
{ "original_instruction": "Juno is fascinated by how binary search trees (BSTs) work. He decides to write a program that determines the kth smallest element in a BST. However, he needs your help to get it right.\n\nYour task is to write a function that, given a binary search tree and an integer k, returns the kth sma...
0.551984
Code_Contests_42128
C
[ "insert_into_bst", "kth_smallest_element", "find_kth_smallest" ]
3
[ [ "find_kth_smallest", "insert_into_bst" ], [ "find_kth_smallest", "kth_smallest_element" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b8d60b697baa5b064ea0a3545b4c81c86b81866b
5ae4d5bf97bdc73545aa279425d006e8cfce6446
v1.0
complete
Code_Contests
Code_Contests_42094_C
def count_hubs(n: int, edges: List[Tuple[int, int]]) -> int: """ Determines the number of hubs in the graph. A hub is a vertex such that every other vertex has a directed path to it. :param n: Number of vertices in the graph. :param edges: List of directed edges in the graph. :return: ...
def floyd_warshall(n, edges): """ Uses the Floyd-Warshall algorithm to find all pairs shortest paths. """ dist = [[float('inf')] * n for _ in range(n)] for i in range(n): dist[i][i] = 0 for u, v in edges: dist[u - 1][v - 1] = 1 for k in range(n): for i ...
def test_count_hubs_example_1(): n = 4 m = 4 edges = [(1, 2), (2, 3), (3, 4), (4, 1)] assert count_hubs(n, edges) == 4 def test_count_hubs_example_2(): n = 4 m = 3 edges = [(1, 2), (2, 3), (3, 1)] assert count_hubs(n, edges) == 0 def test_count_hubs_single_vertex(): n = 1 m = 0...
[ { "docstring": "Uses the Floyd-Warshall algorithm to find all pairs shortest paths.", "function_declaration": "def floyd_warshall(n, edges):", "function_name": "floyd_warshall", "parameter_list": "(n, edges)" }, { "docstring": "Returns the number of hub vertices in the graph.", "function...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def floyd_warshall(n, edges):\n \"\"\"\n Uses the Floyd-Warshall algorithm to find all pairs shortest paths.\n \"\"\"\n dist = [[float('inf')] ...
trial_gpt4o_0
{ "original_instruction": "You are given a directed graph with n vertices and m edges. Each vertex is numbered from 1 to n. An edge from vertex u to vertex v is represented as (u -> v).\n\nA vertex i is said to be a hub if every other vertex in the graph has a directed path to it.\n\nYour task is to determine the num...
0.553322
Code_Contests_42094
C
[ "floyd_warshall", "count_hubs" ]
2
[ [ "count_hubs", "floyd_warshall" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8482e4d339d9938dfd76db057eeca4c3e0ba6769
5d704984559a9b33b09f0403a9d06daf60797540
v1.0
complete
Code_Contests
Code_Contests_42702_C
def rotate_90(matrix): """ Rotates the given nxn matrix 90 degrees clockwise. """ n = len(matrix) return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)] def check_rotations(matrix1, matrix2): """ Checks if matrix1 can be transformed into matrix2 via rotations of 0°, 90°, 180°, ...
def rotate_90(matrix): """ Rotates the given nxn matrix 90 degrees clockwise. """ n = len(matrix) return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)] def check_rotations(matrix1, matrix2): """ Checks if matrix1 can be transformed into matrix2 via rotations of 0°, 90°, 180°, ...
from solution import matching_tiles def test_matching_tiles(): test_cases = [ ( [["0", "1", "0"], ["1", "0", "1"], ["0", "1", "0"]], [["1", "1", "1"], ["1", "0", "1"], ["1", "1", "1"]] ), ( [["0", "...
[ { "docstring": "Rotates the given nxn matrix 90 degrees clockwise.", "function_declaration": "def rotate_90(matrix):", "function_name": "rotate_90", "parameter_list": "(matrix)" }, { "docstring": "Checks if matrix1 can be transformed into matrix2 via rotations of 0°, 90°, 180°, or 270°.", ...
[ 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 rotate_matrix_90_degrees(matrix):\n \"\"\"Rotates a given matrix 90 degrees clockwise.\"\"\"\n return [''.join(row[i] for row in matrix[::-1]) fo...
trial_gpt4o_2
{ "original_instruction": "Matching Tiles\n\nTwo artists have created unique wall tile patterns represented by binary matrices of the same size. These patterns consist of two characters, '0' and '1', where '0' represents a blank tile and '1' represents a filled tile. The patterns are aesthetically different due to th...
0.571954
Code_Contests_42702
C
[ "rotate_90", "check_rotations", "matching_tiles" ]
3
[ [ "check_rotations", "rotate_90" ], [ "matching_tiles", "check_rotations" ] ]
2
[]
false
[]
false
pytest
true
[]
true
005daf7c985fe22333eb2fe53a97d7a1032f4a9c
d1fc05a6699ad3de8001353b6a1ebabd9163602d
v1.0
complete
Code_Contests
Code_Contests_42156_C
import collections from typing import List, Tuple, DefaultDict def bfs(start_node: int, graph: DefaultDict[int, List[Tuple[int, int]]], num_nodes: int) -> Tuple[int, int]: """ Perform BFS to find the farthest node and its distance from the start_node. """ pass def parse_input(input_str: str) -> List...
from collections import defaultdict, deque def bfs(start_node, graph, num_nodes): queue = deque([(start_node, 0)]) visited = [False] * (num_nodes + 1) visited[start_node] = True farthest_node = start_node max_distance = 0 while queue: current_node, current_distance = queue.pop...
def test_parse_input(): input_str = "4\n1 2 10\n2 3 4\n3 4 7\n3\n1 2 5\n2 3 6\n0" expected = [ [4, (1, 2, 10), (2, 3, 4), (3, 4, 7)], [3, (1, 2, 5), (2, 3, 6)] ] assert parse_input(input_str) == expected def test_find_most_powerful_route(): island_list = [ [4, (1, 2, 10), (2...
[ { "docstring": null, "function_declaration": "def bfs(start_node, graph, num_nodes):", "function_name": "bfs", "parameter_list": "(start_node, graph, num_nodes)" }, { "docstring": null, "function_declaration": "def find_most_powerful_route(island_list):", "function_name": "find_most_...
[ 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 most_powerful_route(n, edges):\n import collections\n \n # Adjacency list representation of the graph\n graph = collections.defaultdict(lis...
trial_gpt4o_1
{ "original_instruction": "A kingdom is organizing a grand festival and constructing a series of magical bridges to connect several islands. Each island is represented by a node and each bridge by an edge. The islands are connected in such a way that there is exactly one path between any two islands, hence forming a ...
0.626861
Code_Contests_42156
C
[ "bfs", "find_most_powerful_route", "parse_input" ]
3
[ [ "find_most_powerful_route", "bfs" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
ae9cdf0c789e3813f058af72e996a61d3aef9a9d
ab2ff16aff80ad6f15189f4a1be3c077014e3a66
v1.0
complete
Code_Contests
Code_Contests_43224_C
def nth_super_primes(n: int) -> List[int]: """Find the first 'n' super primes. A super prime is a prime number whose index in the sequence of prime numbers is also a prime number. Args: n (int): The number of super primes to find. Returns: List[int]: A list containing the first 'n...
def is_prime(num): if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def nth_super_primes(n): primes = [] super_primes = [] i = 2 while len(super_primes) < n: if is_prime(i): primes...
from solution import nth_super_primes def test_nth_super_primes_5(): assert nth_super_primes(5) == [3, 5, 11, 17, 31] def test_nth_super_primes_10(): assert nth_super_primes(10) == [3, 5, 11, 17, 31, 41, 59, 67, 83, 109] def test_nth_super_primes_1(): assert nth_super_primes(1) == [3] def test_nth_super...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def nth_super_primes(n):", "function_name": "nth_super_primes", "parameter_list": "(n)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sympy\n\ndef first_n_super_primes(n):\n \"\"\"\n Returns the first n super primes.\n \"\"\"\n primes = list(sympy.primerange(1, 100000))...
trial_gpt4o_2
{ "original_instruction": "Henry enjoys solving mathematical puzzles. He recently stumbled upon an interesting sequence of numbers called “super primes.” A super prime is a prime number whose index in the sequence of prime numbers is also a prime number. For instance, the number 3 is prime and it is the second prime ...
0.677605
Code_Contests_43224
C
[ "is_prime", "nth_super_primes" ]
2
[ [ "nth_super_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd7137986622247ec6d9abbaa8c9ecbc7dadf841
22da48cc016fca3b811192b212d85b823c9a3091
v1.0
complete
Code_Contests
Code_Contests_43180_C
def is_prime(num: int) -> bool: """ Helper function to check if a number is prime. """ pass def max_length_interesting_subarray(arr: List[int]) -> int: """ Given an array of integers, return the maximum length of interesting subarray which contains only prime numbers. >>> max_length_int...
def is_prime(num): """ Helper function to check if a number is prime. """ if num < 2: return False if num in (2, 3): return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: retu...
from solution import max_length_interesting_subarray def test_example_1(): arr = [2, 3, 5, 4, 11, 13, 6] assert max_length_interesting_subarray(arr) == 3 def test_example_2(): arr = [10, 12, 15, 8, 9] assert max_length_interesting_subarray(arr) == 0 def test_example_3(): arr = [13, 17, 19, 20, 23...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Given an array of integers, return the maximum length of interesting subarray\nwhich contains only prime nu...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "Given an array of n integers, we refer to a subarray as \"interesting\" if it contains only prime numbers. Your task is to find the maximum length of such an \"interesting\" subarray.\n\nInput\n\nThe first line contains a single integer n (1 ≤ n ≤ 105), which is the number of elements in th...
0.734695
Code_Contests_43180
C
[ "is_prime", "max_length_interesting_subarray" ]
2
[ [ "max_length_interesting_subarray", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9256056fb732da1c9f9381c08491c725d942a4db
f022967dc5c6e225d24b5d8626428cc85107cf9a
v1.0
complete
Code_Contests
Code_Contests_41999_C
def is_strong_password(password: str) -> str: """ Returns 'YES' if the given password is strong according to the criteria, else 'NO'. - The password must be at least 8 characters long. - It must contain at least one lowercase letter. - It must contain at least one uppercase letter. - It must con...
import re def is_strong_password(password): """ Returns 'YES' if the given password is strong according to the criteria, else 'NO'. """ if len(password) < 8: return "NO" if not re.search(r'[a-z]', password): return "NO" if not re.search(r'[A-Z]', password): return "NO" ...
from solution import is_strong_password, check_passwords def test_is_strong_password(): assert is_strong_password("Passw0rd!") == "YES" assert is_strong_password("weakpass") == "NO" assert is_strong_password("Str0ngPass@") == "YES" assert is_strong_password("Short1!") == "NO" assert is_strong_passw...
[ { "docstring": "Returns 'YES' if the given password is strong according to the criteria, else 'NO'.", "function_declaration": "def is_strong_password(password):", "function_name": "is_strong_password", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def ch...
[ 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\n\ndef is_strong_password(password):\n \"\"\"\n Checks whether a given password is strong.\n \n A password is considered strong if it...
trial_gpt4o_1
{ "original_instruction": "A password strength checker is a function that determines the strength of a given password. A password is considered strong if it satisfies all the following criteria:\n1. It has at least 8 characters.\n2. It contains at least one lowercase letter.\n3. It contains at least one uppercase let...
0.592242
Code_Contests_41999
C
[ "is_strong_password", "check_passwords" ]
2
[ [ "check_passwords", "is_strong_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aa3938c8c455a2e3d9f691cb7cc9bed0f5aa2a8
fe2cddb46d6c4d6454d06bdf2efb7094a1371e04
v1.0
complete
Code_Contests
Code_Contests_40926_C
from typing import List, Tuple def solve(n: int, m: int, edges: List[Tuple[int, int]]) -> List[int]: """ A treasure hunter is exploring the mysterious island of Zogar! This island has n cities connected by m one-way paths. To reach the treasure, the hunter needs to collect clues from exactly five differe...
from heapq import heappop, heappush from collections import defaultdict def dijkstra(graph, start, n): distances = [float('inf')] * (n + 1) distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heappop(priority_queue) if ...
from solution import solve def test_example_case(): n = 8 m = 10 edges = [ (1, 2), (2, 3), (3, 4), (4, 1), (1, 5), (5, 6), (6, 7), (7, 8), (8, 1), (5, 7) ] result = solve(n, m, edges) assert len(result) == 5 def te...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, n):", "function_name": "dijkstra", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def find_best_path(n, m, edges):", "function_name": "find_best_path", "parameter_list...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappop, heappush\nfrom collections import defaultdict\n\ndef dijkstra(graph, start, n):\n distances = [float('inf')] * (n + 1)\n d...
trial_gpt4o_0
{ "original_instruction": "A treasure hunter is exploring the mysterious island of Zogar!\n\nThis island has n cities connected by m one-way paths. To reach the treasure, the hunter needs to collect clues from exactly five different cities. The hunter wants to maximize the total collection of clues. However, due to t...
0.681712
Code_Contests_40926
C
[ "dijkstra", "find_best_path", "solve" ]
3
[ [ "find_best_path", "dijkstra" ], [ "solve", "find_best_path" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9367a89296f7e417da708400ba3b91d319dd6f4d
46e4bc1a6de5d8a5de9243fc92978eaecfa24318
v1.0
complete
Code_Contests
Code_Contests_43211_C
def primes_up_to_n(n: int, numbers: List[int]) -> List[int]: """ Write a function that takes an integer n and a list of integers. The function should return a list containing only the prime numbers from the given list, up to the integer n. >>> primes_up_to_n(50, [11, 2, 3, 15, 22, 29, 31, 40, 47, 51]) [11, ...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def primes_up_to_n(n, numbers): """ Returns a list of prime numbers from 'n...
from solution import primes_up_to_n def test_primes_up_to_50(): assert primes_up_to_n(50, [11, 2, 3, 15, 22, 29, 31, 40, 47, 51]) == [11, 2, 3, 29, 31, 47] def test_primes_up_to_20(): assert primes_up_to_n(20, [19, 12, 17, 4, 5, 6]) == [19, 17, 5] def test_primes_up_to_30(): assert primes_up_to_n(30, [30...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers from 'numbers' that are <= n.", "function_declaration": "def primes...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num...
trial_gpt4o_1
{ "original_instruction": "Write a function that takes an integer n and a list of integers. The function should return a list containing only the prime numbers from the given list, up to the integer n.\n\nInput\n\nThe first line of input contains an integer n (2 ≤ n ≤ 103). The second line contains a list of integers...
0.83025
Code_Contests_43211
C
[ "is_prime", "primes_up_to_n" ]
2
[ [ "primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f359ec4530840c65ae86023a01199cd88f768a9
07b8a265744613a710011e20237ed3d220c432d5
v1.0
complete
Code_Contests
Code_Contests_43610_C
def split_array(inputs): """ Determine if it is possible to split the array into two non-empty parts such that the sum of the elements in both parts is equal. >>> inputs = ["3", "5", "10 -5 2 5 -2", "4", "1 1 1 1", "3", "2 1 2"] >>> split_array(inputs) ["YES", "YES", "NO"] """
def can_partition_equal_sum(arr): total_sum = sum(arr) # If the total sum is odd, it can't be divided into two equal parts if total_sum % 2 != 0: return "NO" target = total_sum // 2 current_sum = 0 for num in arr: current_sum += num if current_sum == target...
import pytest from solution import split_array def test_example_case(): inputs = ["3", "5", "10 -5 2 5 -2", "4", "1 1 1 1", "3", "2 1 2"] expected = ["YES", "YES", "NO"] assert split_array(inputs) == expected def test_single_case_yes(): inputs = ["1", "4", "3 1 1 1"] expected = ["YES"] assert ...
[ { "docstring": null, "function_declaration": "def can_partition_equal_sum(arr):", "function_name": "can_partition_equal_sum", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def equal_sum_partitions(test_cases):", "function_name": "equal_sum_partitions", ...
[ 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 can_partition(array):\n \"\"\"\n Determines if it's possible to split the array into two non-empty parts with equal sums.\n \"\"\"\n total_...
trial_gpt4o_1
{ "original_instruction": "You are given an array of integers. Your task is to determine if it is possible to split the array into two non-empty parts such that the sum of the elements in both parts is equal.\n\nInput\nThe first line of the input contains an integer T denoting the number of test cases. The descriptio...
0.603829
Code_Contests_43610
C
[ "can_partition_equal_sum", "equal_sum_partitions", "split_array" ]
3
[ [ "equal_sum_partitions", "can_partition_equal_sum" ], [ "split_array", "equal_sum_partitions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2d4a405a72a3f7762ebf316e017927028dd80135
305a8a5e0412eb90a8f9a9c70534b774d7dbf47c
v1.0
complete
Code_Contests
Code_Contests_42840_C
def minimum_repair_needed(n: int, m: int, edges: List[Tuple[int, int, int]], k: int, damaged: List[Tuple[int, int]]) -> int: """Determine the minimum number of pathways to be repaired to ensure the kingdom is united. Args: n: Number of castles. m: Number of pathways. edges: List of ...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, u, v): root_u = find(parent, u) root_v = find(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[r...
from solution import minimum_repair_needed def test_case_1(): n = 6 m = 7 edges = [ (1, 2, 5), (2, 3, 10), (3, 4, 3), (4, 5, 4), (5, 6, 2), (6, 1, 8), (3, 6, 7) ] k = 2 damaged = [ (3, 4), (5, 6) ] assert minimum_re...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, u, v):", "function_name": "union", "parameter_list": "(parent, rank, u, v)" }, ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n \"\"\"\n A helper function to find the root of the node i with path compression.\n \"\"\"\n if parent[i] != i:\n ...
trial_gpt4o_5
{ "original_instruction": "In a kingdom far away, there are N beautiful castles connected by M pathways. Each pathway directly connects two castles and has a positive integer length associated with it. However, due to a recent war, some of the pathways may have become impassable.\n\nThe king wants to ensure that the ...
0.583434
Code_Contests_42840
C
[ "find", "union", "minimum_repair_needed" ]
3
[ [ "minimum_repair_needed", "find" ], [ "minimum_repair_needed", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
89375093b7d7b8c09ebc283d647d7be1094ea9fe
96ec10f83000d5d0c57f0ed2ac38e769f24b85d5
v1.0
complete
Code_Contests
Code_Contests_43770_C
def min_tables_requirement(guests, capacity): """Determine the minimum number of tables required to seat all the guests given their capacities.""" def process_datasets(datasets): """Process multiple datasets to find the minimum number of tables required for each dataset.""" def parse_inputs(inputs): """Pa...
def min_tables_requirement(guests, capacity): guests.sort(reverse=True) tables = 0 available = [capacity] * len(guests) for guest in guests: for idx in range(tables): if available[idx] >= guest: available[idx] -= guest break else: ...
from solution import min_tables_requirement, process_datasets, parse_inputs, produce_outputs def test_min_tables_requirement(): assert min_tables_requirement([1, 2, 1, 2, 1, 2], 3) == 3 assert min_tables_requirement([3, 3, 3, 3, 3], 1) == 5 assert min_tables_requirement([1, 1, 1, 1], 2) == 2 assert min...
[ { "docstring": null, "function_declaration": "def min_tables_requirement(guests, capacity):", "function_name": "min_tables_requirement", "parameter_list": "(guests, capacity)" }, { "docstring": null, "function_declaration": "def process_datasets(datasets):", "function_name": "process...
[ 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 min_tables_required(guests, capacity):\n \"\"\"\n Returns the minimum number of tables required to seat all guests given their seating requiremen...
trial_gpt4o_7
{ "original_instruction": "You are organizing a party and need to arrange seating for your guests.\n\nGiven a list of guests, you need to assign them to tables such that no guest is left without a seat. Each table has a capacity limit for the number of guests. The goal is to minimize the number of tables used while e...
0.429867
Code_Contests_43770
C
[ "min_tables_requirement", "process_datasets", "parse_inputs", "produce_outputs" ]
4
[ [ "process_datasets", "min_tables_requirement" ] ]
1
[ "process_datasets", "parse_inputs" ]
false
[]
false
pytest
true
[]
true
7c6a7f70d69b5b57e8415f738412ca1ffafb67b1
97f9beaf0fcd3eef2c2d71f69016e4c4cd31e6e4
v1.0
complete
Code_Contests
Code_Contests_43550_C
from typing import List def length_of_LIS(purchases: List[int]) -> int: """ Finds the length of the longest increasing subsequence in the given list of purchases. """ def longest_increasing_subsequences(purchases_data: List[List[int]]) -> List[int]: """ Given the purchases data for multiple users,...
def length_of_LIS(purchases): """ Finds the length of the longest increasing subsequence in the given list of purchases. """ if not purchases: return 0 # Initialize dp array, where dp[i] indicates the length of LIS ending at index i dp = [1] * len(purchases) for i in range(...
from solution import length_of_LIS, longest_increasing_subsequences def test_length_of_LIS(): assert length_of_LIS([2, 1, 3, 5, 2, 6]) == 4 assert length_of_LIS([7, 4, 8, 3, 9]) == 3 assert length_of_LIS([1, 2, 3, 4, 5]) == 5 # strictly increasing sequence assert length_of_LIS([5, 4, 3, 2, 1]) ==...
[ { "docstring": "Finds the length of the longest increasing subsequence in the given list of purchases.", "function_declaration": "def length_of_LIS(purchases):", "function_name": "length_of_LIS", "parameter_list": "(purchases)" }, { "docstring": "Given the purchases data for multiple users, ...
[ 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 length_of_LIS(purchases):\n \"\"\"\n Finds the length of the longest increasing subsequence in the given list of purchases.\n \"\"\"\n if n...
trial_gpt4o_0
{ "original_instruction": "An e-commerce website tracks the number of purchases made by users over consecutive days. Each day, the number of purchases each user makes is recorded. The website wants to identify trends in user activity to improve their service. For this purpose, it needs a program that determines the l...
0.642729
Code_Contests_43550
C
[ "length_of_LIS", "longest_increasing_subsequences" ]
2
[ [ "longest_increasing_subsequences", "length_of_LIS" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7f7b53f006c7cc895325c7992ac4717debcca5cd
27a6958fbb351bc588d5dd195d4404e05027e42b
v1.0
complete
Code_Contests
Code_Contests_43062_C
def minimal_spanning_tree(N: int, M: int, edges: List[Tuple[int, int, int]]) -> List[Tuple[int, int]]: """ In the enchanted forest of Eldoria, each tree is connected to other trees via magical vines. The forest guardians want to ensure that the network of vine connections forms a looplessly connected struc...
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]: ...
def test_minimal_spanning_tree(): edges = [ (1, 2, 2), (1, 3, 3), (2, 3, 1), ] N, M = 3, 3 result = minimal_spanning_tree(N, M, edges) expected = [(2, 3), (1, 2)] for edge in result: assert edge in expected assert len(result) == N-1 def test_minimal_span...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_spanning_tree(N, M, edges):\n \"\"\"\n This function takes the number of trees (N), the number of vines (M), and a list of edges where each ...
trial_gpt4o_2
{ "original_instruction": "In the enchanted forest of Eldoria, each tree is connected to other trees via magical vines. The forest guardians want to ensure that the network of vine connections forms a looplessly connected structure, which means there should be exactly one path connecting any pair of trees. If there a...
0.669868
Code_Contests_43062
C
[ "find", "union", "kruskal", "minimal_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimal_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
b0f2b66de2e64bd0960d5fffc9e54606fc077e84
6f78e95dacc3e2fba8e90381b566dac68154dc39
v1.0
complete
Code_Contests
Code_Contests_43375_C
def minimize_longest_distance(C: int, R: int, roads: List[Tuple[int, int, int]]) -> int: """ Determine the minimum possible value of the longest distance between any two cities after adding the minimum number of required roads. >>> minimize_longest_distance(5, 5, [(1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 4, 4)...
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...
from solution import minimize_longest_distance def test_minimize_longest_distance_case_1(): C = 5 R = 5 roads = [ (1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 4, 4), (4, 5, 5) ] assert minimize_longest_distance(C, R, roads) == 5 def test_minimize_longest_distance_ca...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 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 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\n\ndef u...
trial_gpt4o_7
{ "original_instruction": "You are given an issue of resource allocation among a network of cities. There are `C` cities connected by `R` bidirectional roads. Each road connects two cities and has a length associated with it. \n\nTo facilitate travel and connectivity, the government has decided to build additional ro...
0.726298
Code_Contests_43375
C
[ "find", "union", "kruskal_mst", "minimize_longest_distance" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimize_longest_distance", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0bbdfe43580d2f478e5e1c90b647cbc4f9644d3d
81ae226a13d8a27a2768eba256cc266b74dec63f
v1.0
complete
Code_Contests
Code_Contests_43881_C
from typing import List def is_prime(x: int) -> bool: """Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(4) False """ def smallest_prime(arr: List[int]) -> int: """Find the smallest prime number in the array. >>> smallest_prime([4, 6, 7, 11, 15]) 7 >>...
def is_prime(x): """ Returns True if x is a prime number, otherwise False. """ if x <= 1: return False if x == 2: return True if x % 2 == 0: return False for i in range(3, int(x**0.5) + 1, 2): if x % i == 0: return False return True def smalle...
from solution import is_prime, smallest_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-7) == Fa...
[ { "docstring": "Returns True if x is a prime number, otherwise False.", "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": "Returns the smallest prime number in the array.", "function_declaration": "def smallest_prime(arr):"...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "def is_prime(x):\n \"\"\"\n Returns True if x is a prime number, otherwise False.\n \"\"\"\n if x <= 1:\n retur...
trial_gpt4o_1
{ "original_instruction": "Given an array a1, a2, ..., an of n integers, find the smallest number in the array that is a prime number.\n\nA number x is said to be a prime number if it is greater than 1 and has no divisors other than 1 and itself.\n\nInput\n\nThe first line contains a single integer n (1 ≤ n ≤ 1000) —...
0.725409
Code_Contests_43881
C
[ "is_prime", "smallest_prime" ]
2
[ [ "smallest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d347ae26ebad58bccff06daeb7db8f963929337e
155eecc3ac870d267b0bb77d509fb87890d9e80d
v1.0
complete
Code_Contests
Code_Contests_42173_C
from typing import List def fire_simulation(H: int, W: int, grid: List[str], Sy: int, Sx: int, Ty: int, Tx: int) -> str: """ Determine if fire can reach the target cell on a grid. Args: H (int): The height of the grid. W (int): The width of the grid. grid (List[str]): The grid itself repr...
def can_fire_reach_target(grid, start, target): H, W = len(grid), len(grid[0]) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right def is_valid(r, c): return 0 <= r < H and 0 <= c < W and grid[r][c] == '.' from collections import deque queue = deque([start]) ...
def test_example_1(): H = 4 W = 5 grid = [ ".....", ".T...", ".R...", "....T" ] Sy, Sx = 1, 1 Ty, Tx = 4, 4 assert fire_simulation(H, W, grid, Sy, Sx, Ty, Tx) == "yes" def test_example_2(): H = 4 W = 5 grid = [ ".....", ".T...", ...
[ { "docstring": null, "function_declaration": "def can_fire_reach_target(grid, start, target):", "function_name": "can_fire_reach_target", "parameter_list": "(grid, start, target)" }, { "docstring": null, "function_declaration": "def fire_simulation(H, W, grid, Sy, Sx, Ty, Tx):", "fun...
[ 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 can_fire_reach_target(grid, start, target):\n from collections import deque\n \n H, W = len(grid), len(grid[0])\n Sy, Sx = start\n Ty, T...
trial_gpt4o_3
{ "original_instruction": "Problem\n\nYou have been given a rectangular grid of cells with some cells containing trees, some containing rocks, and some empty cells. Your objective is to create a fire spread simulation where a fire starts from one specific cell and spreads to adjacent cells. The fire can move to the l...
0.569919
Code_Contests_42173
C
[ "can_fire_reach_target", "fire_simulation" ]
2
[ [ "fire_simulation", "can_fire_reach_target" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a0ff18ad539889baf41b621d8e1cd642598921a7
d4aafd45d30dc094cf9eea4cb445e45f84f7c9b8
v1.0
complete
Code_Contests
Code_Contests_43485_C
from typing import List, Tuple from collections import defaultdict, deque def compute_longest_path(n: int, m: int, edge_list: List[Tuple[int, int]]) -> int: """ Computes the length of the longest path in a Directed Acyclic Graph (DAG). Args: n (int): The number of nodes in the graph. m (int): The numb...
from collections import defaultdict, deque def longest_path_in_dag(n, m, edges): def topological_sort(): in_degree = {i: 0 for i in range(1, n + 1)} for u, v in edges: in_degree[v] += 1 zero_in_degree_queue = deque([i for i in range(1, n + 1) if in_degree[i] == 0]) ...
from solution import compute_longest_path def test_sample1(): assert compute_longest_path(5, 6, [(1, 2), (2, 3), (1, 3), (1, 4), (4, 5), (3, 5)]) == 3 def test_sample2(): assert compute_longest_path(4, 3, [(1, 2), (2, 3), (3, 4)]) == 3 def test_no_edges(): assert compute_longest_path(3, 0, []) == 0 def ...
[ { "docstring": null, "function_declaration": "def longest_path_in_dag(n, m, edges):", "function_name": "longest_path_in_dag", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def compute_longest_path(n, m, edge_list):", "function_name": "compute_long...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef longest_path_in_dag(n, m, edges):\n def topological_sort():\n in_degree = [0] * (n + 1)\n ...
trial_gpt4o_4
{ "original_instruction": "**Problem: Longest Path in a Directed Acyclic Graph (DAG)**\n\nAlex is analyzing a network represented as a Directed Acyclic Graph (DAG). Each node in the network represents a task and each directed edge represents a dependency between tasks. To optimize the network, Alex wants to find the ...
0.588878
Code_Contests_43485
C
[ "longest_path_in_dag", "compute_longest_path" ]
2
[ [ "compute_longest_path", "longest_path_in_dag" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7058a5dcf68c256267290c39cf2bab88122d5d96
d68f591a284f08e83be9dded40ad045fb34c3cfb
v1.0
complete
Code_Contests
Code_Contests_43892_C
def max_collinear_points(points: List[Tuple[int, int, int]]) -> int: """ Given a set of n triplets where each triplet contains three numbers representing the XYZ coordinates, determine the number of collinear points among these triplets. Two or more points are collinear if they lie on a single straight line. >>...
def gcd(a, b): while b: a, b = b, a % b return a def are_collinear(p1, p2, p3): x1, y1, z1 = p1 x2, y2, z2 = p2 x3, y3, z3 = p3 return (x2 - x1)*(y3 - y1) == (y2 - y1)*(x3 - x1) and (x2 - x1)*(z3 - z1) == (z2 - z1)*(x3 - x1) and (y2 - y1)*(z3 - z1) == (z2 - z1)*(y3 - y1) def max_collin...
def test_max_collinear_points_case1(): points = [(1, 2, 3), (2, 4, 6), (3, 6, 9), (4, 8, 10)] assert max_collinear_points(points) == 3 def test_max_collinear_points_case2(): points = [(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 6, 7)] assert max_collinear_points(points) == 4 def test_max_collinear...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def are_collinear(p1, p2, p3):", "function_name": "are_collinear", "parameter_list": "(p1, p2, p3)" }, { "doc...
[ 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_collinear_points(triplets):\n from itertools import combinations\n from collections import defaultdict\n\n def are_collinear(p1, p2, p3):\...
trial_gpt4o_2
{ "original_instruction": "Given a set of n triplets, where each triplet contains three numbers representing the XYZ coordinates. Your task is to determine the number of collinear points among these triplets. Two or more points are collinear if they lie on a single straight line.\n\nInput\n\nThe first line of the inp...
0.649121
Code_Contests_43892
C
[ "gcd", "are_collinear", "max_collinear_points" ]
3
[ [ "max_collinear_points", "are_collinear" ] ]
1
[]
false
[]
false
pytest
false
[]
true
27d3a278cd355d40f870bb8e9eebc2d133c04b6a
d1f7500b7bc251d81c8b94a31a0879854746957a
v1.0
complete
Code_Contests
Code_Contests_44250_C
def longest_palindromic_substring_len(s: str) -> int: """ Determine the length of the longest palindromic substring that can be obtained from the given string by deleting at most one character. >>> longest_palindromic_substring_len("abca") 3 >>> longest_palindromic_substring_len("racecarr") 7 >>...
def is_palindrome(s): return s == s[::-1] def longest_palindromic_substring_len(s): n = len(s) if is_palindrome(s): return n max_len = 0 for i in range(n): temp = s[:i] + s[i+1:] if is_palindrome(temp): max_len = max(max_len, n - 1) if ...
from solution import longest_palindromic_substring_len def test_palindromic_without_removing_anything(): assert longest_palindromic_substring_len("aaaa") == 4 def test_palindromic_by_removing_one(): assert longest_palindromic_substring_len("abca") == 3 def test_palindromic_with_no_good_scenario(): assert...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def longest_palindromic_substring_len(s):", "function_name": "longest_palindromic_substring_len", "para...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring_with_one_deletion(s):\n \"\"\"\n Returns the length of the longest palindromic substring that can be obtained by de...
trial_gpt4o_2
{ "original_instruction": "You are given a string S consisting of lowercase English letters. Your task is to determine the length of the longest palindromic substring that can be obtained from S by deleting at most one character. \n\nA string is called a palindrome if it reads the same forward and backward.\n\nConstr...
0.795816
Code_Contests_44250
C
[ "is_palindrome", "longest_palindromic_substring_len" ]
2
[ [ "longest_palindromic_substring_len", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b81e15043f764fbeeb9adf70a042ddbdd43e89f
100452ae89cab81988da2d9bd0c2b53de5565979
v1.0
complete
Code_Contests
Code_Contests_43727_C
def longest_distinct_substring(s): """ This function returns the longest substring of distinct characters for the given string s. >>> longest_distinct_substring("abcdef") "abcdef" >>> longest_distinct_substring("bbbbb") "b" >>> longest_distinct_substring("pwwkew") "wke" >>> longest_distinct_substrin...
def longest_distinct_substring(s): """ This function returns the longest substring of distinct characters for the given string s. """ n = len(s) longest_substr = "" start = 0 seen = {} for end in range(n): if s[end] in seen: start = max(start, seen[s[end]] + 1) ...
from solution import longest_distinct_substring, process_strings def test_longest_distinct_substring_all_unique(): assert longest_distinct_substring("abcdef") == "abcdef" def test_longest_distinct_substring_repeated_characters(): assert longest_distinct_substring("bbbbb") == "b" def test_longest_distinct_sub...
[ { "docstring": "This function returns the longest substring of distinct characters for the given string s.", "function_declaration": "def longest_distinct_substring(s):", "function_name": "longest_distinct_substring", "parameter_list": "(s)" }, { "docstring": "Given a list of strings, return...
[ 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 longest_distinct_substring(s):\n \"\"\"\n Given a string s, returns the longest substring with all distinct characters.\n \"\"\"\n n = len(...
trial_gpt4o_2
{ "original_instruction": "You are given a list of strings, where each string represents a sequence of characters. Your task is to determine the longest substring of distinct characters for each string in the list. If there are multiple substrings with the same length, return the first occurring one.\n\nInput\n\nThe ...
0.73299
Code_Contests_43727
C
[ "longest_distinct_substring", "process_strings" ]
2
[ [ "process_strings", "longest_distinct_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8efb450f7639d966a1e81b2787372a95b492f39
f8f8efa82b076a30750694df9478710a6d1ba83f
v1.0
complete
Code_Contests
Code_Contests_43885_C
def next_prime(x: int) -> int: """Find the smallest prime number `p` that is greater than a given number `x`. >>> next_prime(10) 11 >>> next_prime(100) 101 >>> next_prime(20) 23 >>> next_prime(1) 2 """
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +...
from solution import next_prime def test_next_prime(): assert next_prime(10) == 11 assert next_prime(100) == 101 assert next_prime(20) == 23 assert next_prime(1) == 2 assert next_prime(2) == 3 assert next_prime(13) == 17 assert next_prime(29) == 31 assert next_prime(998) == 1009 def te...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds the smallest prime number greater than x.", "function_declaration": "def next_prime(x):", "functi...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "A prime number is a number greater than 1 with no divisors other than 1 and itself. Your task is to find the smallest prime number `p` that is greater than a given number `x`.\n\nInput\n\nA single integer `x` (1 ≤ x ≤ 10^9).\n\nOutput\n\nA single integer `p`, the smallest prime number that ...
0.714748
Code_Contests_43885
C
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1620d1312e38b6849ee2da86d974fadc8475b907
629f07d1760e54232783f7631dcfe9a3a34d367e
v1.0
complete
Code_Contests
Code_Contests_44240_C
def is_subsequence(target, word): """ Check if the word is a subsequence of target. """ def longest_word_from_target(target, words): """ Find the longest word in the list that can be formed by deleting some characters of the target string without reordering the remaining characters. """ def pr...
def is_subsequence(target, word): """ Check if the word is a subsequence of target. """ it = iter(target) return all(char in it for char in word) def longest_word_from_target(target, words): """ Find the longest word in the list that can be formed by deleting some characters of the target s...
def test_is_subsequence(): assert is_subsequence("abpcplea", "apple") == True assert is_subsequence("abpcplea", "plea") == True assert is_subsequence("abpcplea", "monkey") == False assert is_subsequence("abpcplea", "applz") == False def test_longest_word_from_target(): assert longest_word_from_targ...
[ { "docstring": "Check if the word is a subsequence of target.", "function_declaration": "def is_subsequence(target, word):", "function_name": "is_subsequence", "parameter_list": "(target, word)" }, { "docstring": "Find the longest word in the list that can be formed by deleting some characte...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(target, word):\n it = iter(target)\n return all(char in it for char in word)\n\ndef find_longest_word(target, words):\n longest...
trial_gpt4o_2
{ "original_instruction": "Alice has a list of words and needs to find the longest word that can be formed by deleting some characters of another given string without reordering the remaining characters. She reached out to you for help in writing a program to accomplish this task.\n\nGiven a list of words and a targe...
0.712126
Code_Contests_44240
C
[ "is_subsequence", "longest_word_from_target", "process_test_cases", "handle_input_output" ]
4
[ [ "handle_input_output", "process_test_cases" ], [ "longest_word_from_target", "is_subsequence" ], [ "process_test_cases", "longest_word_from_target" ] ]
3
[ "process_test_cases", "handle_input_output" ]
false
[]
false
pytest
true
[]
true
9443e97e41fb581eae829d6015c9abe35ce98273
4bc4d4fdb17a64f01426e94ba73c5322e7dd6848
v1.0
complete
Code_Contests
Code_Contests_44543_C
def count_prime_factors(num: int) -> int: """Helper function to count distinct prime factors of a number""" factors = set() i = 2 while i * i <= num: while (num % i) == 0: factors.add(i) num //= i i += 1 if num > 1: factors.add(num) return len(fact...
def count_prime_factors(num): """Helper function to count distinct prime factors of a number""" factors = set() i = 2 while i * i <= num: while (num % i) == 0: factors.add(i) num //= i i += 1 if num > 1: factors.add(num) return len(factors) def ca...
from solution import count_prime_factors, calculate_beauty_of_sequence def test_single_prime(): # Test single prime numbers which should have 1 distinct prime factor assert count_prime_factors(2) == 1 assert count_prime_factors(3) == 1 assert count_prime_factors(5) == 1 def test_composite_numbers(): ...
[ { "docstring": "Helper function to count distinct prime factors of a number", "function_declaration": "def count_prime_factors(num):", "function_name": "count_prime_factors", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def calculate_beauty_of_sequence(n, se...
[ 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 count_prime_factors(n):\n \"\"\"\n Returns the number of distinct prime factors of n.\n \"\"\"\n count = 0\n factor = 2\n while facto...
trial_gpt4o_7
{ "original_instruction": "You are given a sequence of positive integers. We define the \"Beauty\" of a sequence as the number of distinct integers in the sequence that has an even number of distinct prime factors. Your task is to determine the Beauty of the given sequence.\n\nInput\n\nThe first line of input contain...
0.675099
Code_Contests_44543
C
[ "count_prime_factors", "calculate_beauty_of_sequence" ]
2
[ [ "calculate_beauty_of_sequence", "count_prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0376a2e6f68c469cf4b1ad5c29b56493f9f6df25
c259568a2f1e514b198b0474ea740ab861a4214f
v1.0
complete
Code_Contests
Code_Contests_43676_C
def min_pipes_to_water_plants(T: int, cases: List[Dict[str, Any]]) -> List[int]: """Determine the minimum number of pipes required to water all plants in each test case. >>> min_pipes_to_water_plants(3, [{'P': 5, 'L': 3, 'pipes': [(1, 2), (2, 5), (1, 3)]}, {'P': 5, 'L': 4,...
def min_pipes_to_water_plants(T, cases): results = [] for case in cases: P, L, pipes = case['P'], case['L'], case['pipes'] # Sort pipes based on starting index, then by ending index pipes.sort() num_pipes = 0 current_end = 0 idx = 0 ...
def test_min_pipes_to_water_plants(): data = """3 5 3 1 2 2 5 1 3 5 4 1 2 3 4 5 5 2 3 7 2 1 3 4 5""" expected = [2, 5, -1] assert solve(data) == expected data = """1 6 3 1 4 2 6 5 6""" expected = [1] assert solve(data) == expected data = """1 6 4 1 2 2 3 3 4 4 6""" expected = [3] a...
[ { "docstring": null, "function_declaration": "def min_pipes_to_water_plants(T, cases):", "function_name": "min_pipes_to_water_plants", "parameter_list": "(T, cases)" }, { "docstring": null, "function_declaration": "def parse_input_input(data):", "function_name": "parse_input_input", ...
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_pipes_to_water_plants(test_cases):\n results = []\n\n for plants, pipes, ranges in test_cases:\n ranges.sort()\n required_end =...
trial_gpt4o_8
{ "original_instruction": "Bob owns a farm with several plants arranged in a straight line. He wants to water his plants using an automatic watering system that utilizes pipes. The pipes are fixed in place and each pipe can water only a specific range of plants. The coverage of each pipe is given in terms of the star...
0.556056
Code_Contests_43676
C
[ "min_pipes_to_water_plants", "parse_input_input", "solve" ]
3
[ [ "solve", "min_pipes_to_water_plants" ], [ "solve", "parse_input_input" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ecd390517af4160848b44689e325ef5f730d38d3
fdee254fcfa0be0f6d0181e8c440bf660b05c951
v1.0
complete
Code_Contests
Code_Contests_44057_C
from typing import List, Tuple def min_diameter_spanning_tree(M: int, N: int, edges: List[Tuple[int, int, int]]) -> int: """ Find the minimum possible diameter of a spanning tree of the graph. Parameters: M : int - Number of rooms (nodes) N : int - Number of bidirectional paths (edges) edg...
import heapq from collections import defaultdict, deque def find(parent, i): if parent[i] == i: return i else: root = find(parent, parent[i]) parent[i] = root return root def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x...
def test_min_diameter_spanning_tree(): M = 5 N = 6 edges = [ (0, 1, 3), (0, 2, 2), (1, 2, 4), (1, 3, 7), (2, 4, 1), (3, 4, 6) ] assert min_diameter_spanning_tree(M, N, edges) == 6 def test_single_edge(): M = 2 N = 1 edges = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.143
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport itertools\n\nclass UnionFind:\n def __init__(self, size):\n self.root = list(range(size))\n self.rank = [1] * size\n\...
trial_gpt4o_7
{ "original_instruction": "A large research laboratory is trying to optimize the workflow in one of its core departments. Each department in the lab consists of several interconnected rooms, which can be represented as nodes in a graph. The connections between rooms represent possible paths for scientists to move fro...
0.629945
Code_Contests_44057
C
[ "find", "union", "kruskal", "bfs", "min_diameter_spanning_tree", "main" ]
6
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_diameter_spanning_tree", "bfs" ], [ "min_diameter_spanning_tree", "kruskal" ], [ "union", "find" ] ]
5
[]
false
[]
false
pytest
false
[]
true
5b0dd736d4a9f22f88668f7cc11ba30d6125c8ad
cccd1ef81bbe1e7645f589b0f6a606be9e774c02
v1.0
complete
Code_Contests
Code_Contests_44063_C
def find_path(grid, n, m): """ Determines if it is possible for a robot to reach the bottom-right corner of a grid without revisiting any cell. If possible, returns "Yes" and a string representing the path, otherwise returns "No". >>> grid_1 = [ ... ['.', '.', '.', '.'], ...
def find_path(grid, n, m): directions = [(0, 1, 'R'), (1, 0, 'D'), (0, -1, 'L'), (-1, 0, 'U')] def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' def dfs(x, y, path): if not is_valid(x, y): return False if (x, y) == (n-1, m-1): re...
def test_robot_grid_example_1(): n, m = 4, 4 grid = [ ['.', '.', '.', '.'], ['.', '#', '.', '.'], ['.', '.', '#', '.'], ['.', '.', '.', '.'] ] result = find_path(grid, n, m) assert result[0] == "Yes" def test_robot_grid_example_2(): n, m = 3, 3 grid = [ ...
[ { "docstring": null, "function_declaration": "def find_path(grid, n, m):", "function_name": "find_path", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def robot_grid(n, m, grid):", "function_name": "robot_grid", "parameter_list": "(n, m, grid)"...
[ 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_path(grid, n, m):\n directions = [(0, 1, 'R'), (1, 0, 'D'), (0, -1, 'L'), (-1, 0, 'U')]\n \n def is_valid(x, y):\n return 0 <= x <...
trial_gpt4o_0
{ "original_instruction": "You are given a robot that is situated inside a rectangular grid of size n x m. The robot can move left, right, up, or down, but it is unable to visit the same cell more than once. The robot starts at the top-left corner of the grid (cell (1, 1)) and its goal is to reach the bottom-right co...
0.679525
Code_Contests_44063
C
[ "find_path", "robot_grid" ]
2
[ [ "robot_grid", "find_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ce33decb12d276b83665201fae2ca34516ebda0e
f63d9f81991703a3635bea7d8d3fed39069148ce
v1.0
complete
Code_Contests
Code_Contests_44296_C
def solve(test_cases): """ Find the length of the longest subsequence such that all elements of the subsequence are coprime. Args: test_cases (List[List[int]]): List of test cases, each test case is a list of integers. Returns: List[int]: List of integers representing the length of the...
import math from collections import Counter def gcd(a, b): while b: a, b = b, a % b return a def longest_coprime_subsequence(nums): # If the array contains at least one prime number, then that is coprime with all other primes max_num = max(nums) # Sieve of Eratosthenes to find all pri...
import pytest from solution import solve def test_case_1(): assert solve([[10, 15, 20, 25]]) == [1] def test_case_2(): assert solve([[7, 11, 13, 17, 19]]) == [5] def test_case_3(): assert solve([[6, 10, 15]]) == [1] def test_case_4(): assert solve([ [10, 15, 20, 25], [7, 11, 13, 17, ...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def longest_coprime_subsequence(nums):", "function_name": "longest_coprime_subsequence", "parameter_list": "(nums)" ...
[ 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 math import gcd\nfrom collections import defaultdict\n\ndef longest_coprime_subsequence(t, test_cases):\n # Check if two numbers are coprime\n d...
trial_gpt4o_9
{ "original_instruction": "You are given an integer array nums consisting of positive integers.\n\nYou need to find the length of the longest subsequence such that all elements of the subsequence are coprime. Two integers are coprime if their greatest common divisor (gcd) is 1.\n\nIn one move, you can select any non-...
0.63022
Code_Contests_44296
C
[ "gcd", "longest_coprime_subsequence", "solve" ]
3
[ [ "solve", "longest_coprime_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
899b2b4a63afa3cb5fdce87ac582dae18d05a3fc
231b6e9dd8502eba0f6ef7feba3d62733740bf29
v1.0
complete
Code_Contests
Code_Contests_42815_C
import heapq import sys from typing import List, Tuple def dijkstra(n: int, graph: List[List[Tuple[int, int]]], start: int) -> List[int]: """ Run Dijkstra's algorithm on a graph from a starting node and return the shortest distance to all nodes. """ distances = [sys.maxsize] * n distances[start] = ...
import heapq import sys def dijkstra(n, graph, start): distances = [sys.maxsize] * n distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, u = heapq.heappop(priority_queue) if current_distance > distances[u]: continue ...
def test_dijkstra(): n = 3 graph = [ [(1, 1), (2, 4)], [(0, 1), (2, 2)], [(0, 4), (1, 2)] ] assert dijkstra(n, graph, 0) == [0, 1, 3] assert dijkstra(n, graph, 1) == [1, 0, 2] assert dijkstra(n, graph, 2) == [3, 2, 0] def test_find_main_hub(): n = 3 m = 3 ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def find_main_hub(n, m, portals):", "function_name": "find_main_hub", "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": "import heapq\n\ndef find_hub_planet(n, m, edges):\n def dijkstra(source):\n dist = [float('inf')] * n\n dist[source] = 0\n min_heap...
trial_gpt4o_2
{ "original_instruction": "In a distant galaxy, there are several planets. Each planet is connected to some number of other planets through teleportation portals. Each portal has a certain cost associated with it.\n\nThe government of the galaxy wants to establish a main hub on one of these planets such that the sum ...
0.581406
Code_Contests_42815
C
[ "dijkstra", "find_main_hub", "solve", "main" ]
4
[ [ "find_main_hub", "dijkstra" ], [ "solve", "find_main_hub" ] ]
2
[]
false
[]
false
pytest
false
[]
true
5d912e52c8502bf605a76f7340e9e8c5c3a5945d
7a4b8ca2b0643836128163647740ed1be05dc559
v1.0
complete
Code_Contests
Code_Contests_44525_C
def is_happy_number(n: int) -> bool: """ Returns True if n is a happy number, else False. >>> is_happy_number(1) True >>> is_happy_number(7) True >>> is_happy_number(10) True >>> is_happy_number(4) False >>> is_happy_number(20) False """ def find_next_happy_number(n: int...
def is_happy_number(n): """ Returns True if n is a happy number, else False. """ def get_next(number): return sum(int(char) ** 2 for char in str(number)) slow = n fast = get_next(n) while fast != 1 and slow != fast: slow = get_next(slow) fast = get_next(get_next(...
from solution import find_next_happy_number, is_happy_number def test_find_next_happy_number(): assert find_next_happy_number(100) == 103 assert find_next_happy_number(10) == 13 assert find_next_happy_number(95) == 97 assert find_next_happy_number(1) == 7 assert find_next_happy_number(7) == 10 def...
[ { "docstring": "Returns True if n is a happy number, else False.", "function_declaration": "def is_happy_number(n):", "function_name": "is_happy_number", "parameter_list": "(n)" }, { "docstring": "Finds the smallest happy number greater than n.", "function_declaration": "def find_next_ha...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_happy_number(n: int) -> bool:\n \"\"\"\n Returns True if n is a happy number, else False.\n \"\"\"\n seen = set()\n while n != 1 and ...
trial_gpt4o_1
{ "original_instruction": "Write a function `find_next_happy_number` that takes an integer input `n` and returns the smallest happy number greater than `n`. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat th...
0.620993
Code_Contests_44525
C
[ "is_happy_number", "find_next_happy_number" ]
2
[ [ "find_next_happy_number", "is_happy_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
beafb7e7b9ed35d4576846d4e2dd297f66bfecfc
ca48b0ad86c937b661c96fb92c0994765787094c
v1.0
complete
Code_Contests
Code_Contests_43184_C
def solve(n: int, m: int, s: int, edges: List[Tuple[int, int, int]]) -> List[int]: """ Returns the minimum latency to communicate from source node s to all other nodes in an undirected weighted graph. Parameters: n (int): The number of nodes in the graph. m (int): The number of edges in the graph. ...
import heapq def dijkstra(n, m, s, edges): """ Returns the minimum latency to communicate from source node s to all other nodes in an undirected weighted graph. """ graph = [[] for _ in range(n + 1)] for v, u, l in edges: graph[v].append((u, l)) graph[u].append((v, l)) dist = [...
from solution import solve def test_example1(): n = 6 m = 7 s = 1 edges = [ (1, 2, 10), (1, 3, 5), (2, 3, 2), (2, 4, 1), (3, 4, 9), (3, 5, 2), (4, 6, 6) ] result = solve(n, m, s, edges) assert result == [0, 7, 5, 8, 7, 14] def test_ex...
[ { "docstring": "Returns the minimum latency to communicate from source node s to all other nodes in an undirected weighted graph.", "function_declaration": "def dijkstra(n, m, s, edges):", "function_name": "dijkstra", "parameter_list": "(n, m, s, edges)" }, { "docstring": null, "function...
[ 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": "import heapq\nimport sys\n\ndef dijkstra(n, edges, s):\n \"\"\"\n Apply Dijkstra's algorithm to find the shortest path from source `s` to all nodes i...
trial_gpt4o_4
{ "original_instruction": "You are given an undirected weighted graph with n nodes and m edges. The graph represents a network where each node is a computing device, and each edge represents a direct communication link between two devices with a certain weight indicating the latency of the link. You need to determine...
0.650964
Code_Contests_43184
C
[ "dijkstra", "solve" ]
2
[ [ "solve", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ed6c61d2aee1852e448e9c84e750580c05436e9
b5e146d036378824fcacb92a807572e396c3429f
v1.0
complete
Code_Contests
Code_Contests_44228_C
from typing import List, Tuple def is_prime(n: int) -> bool: """ Check if a number is a prime number >>> is_prime(2) True >>> is_prime(4) False >>> is_prime(11) True """ def preprocess_primes(arr: List[int]) -> List[int]: """ Preprocess the array to create a prime count array >>> prepr...
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 preprocess_primes(arr): prime_count = ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False def test_preprocess_primes(): arr = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] prime_count = preprocess_primes(arr) assert prime_count == ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def preprocess_primes(arr):", "function_name": "preprocess_primes", "parameter_list": "(arr)" }, { "docst...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "Karan is fascinated by prime numbers and their arrangement in arrays. He gives you an array of size N and asks you to perform certain operations on it based on the provided queries to help him understand prime positions better.\n\nThe array of size N contains positive integers. Each query c...
0.725209
Code_Contests_44228
C
[ "is_prime", "preprocess_primes", "answer_queries", "prime_numbers_in_ranges" ]
4
[ [ "preprocess_primes", "is_prime" ], [ "prime_numbers_in_ranges", "answer_queries" ], [ "prime_numbers_in_ranges", "preprocess_primes" ] ]
3
[]
false
[]
false
pytest
false
[]
true
c9407ed8e6f1a00e2405e9449d63301a258c01fa
7391bb007a991066506a23583b5c5ec11ea61060
v1.0
complete
Code_Contests
Code_Contests_44637_C
def min_path_weight(n: int, m: int, edges: List[Tuple[int, int, int]]) -> int: """ Find the minimum weight path from vertex 1 to vertex n in a graph with n vertices and m edges. Args: n (int): number of vertices in the graph m (int): number of edges in the graph edges (List[Tuple[int, int, int]...
import heapq def dijkstra(n, edges, start_vertex): # adjacency list representation of the graph graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) # distances array, start with infinity distances = [float('inf')] * (n + 1) d...
from solution import min_path_weight def test_case_1(): n = 4 m = 4 edges = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 10)] assert min_path_weight(n, m, edges) == 6 def test_case_2(): n = 3 m = 2 edges = [(1, 2, 4), (2, 3, 6)] assert min_path_weight(n, m, edges) == 10 def test_case_3():...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, start_vertex):", "function_name": "dijkstra", "parameter_list": "(n, edges, start_vertex)" }, { "docstring": null, "function_declaration": "def min_path_weight(n, m, edges):", "function_name": "min_path_weight", ...
[ 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": "import heapq\n\ndef find_min_weight_path(n, m, edges):\n \"\"\"\n Finds the minimum weight path from vertex 1 to vertex n.\n \n Parameters:\n ...
trial_gpt4o_8
{ "original_instruction": "Alex is preparing for a programming contest and came across a graph problem that he finds quite interesting. He has a graph with `n` vertices and `m` edges. The vertices are numbered from 1 to `n`. Each edge has a positive weight associated with it.\n\nAlex wants to know if there exists a p...
0.781082
Code_Contests_44637
C
[ "dijkstra", "min_path_weight" ]
2
[ [ "min_path_weight", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c31b0132f52a724493e4763593e7006f1afb91a8
84f73c54522bf626515dd399d8e5e14027cc8857
v1.0
complete
Code_Contests
Code_Contests_44158_C
def is_valid_hex_color(code: str) -> str: """ Determines if a given string is a valid hexadecimal color code. Parameters: code (str): The string to validate. Returns: str: "VALID" if the string is a valid hex color code, "INVALID" otherwise. """ # Write your code here def chec...
def is_valid_hex_color(code: str) -> str: """ Determines if a given string is a valid hexadecimal color code. Parameters: code (str): The string to validate. Returns: str: "VALID" if the string is a valid hex color code, "INVALID" otherwise. """ if len(code) != 7 or code[0] != ...
def test_is_valid_hex_color(): assert is_valid_hex_color("#1f1f1F") == "VALID" assert is_valid_hex_color("#Z12ZZZ") == "INVALID" assert is_valid_hex_color("#ABC123") == "VALID" assert is_valid_hex_color("#12abCK") == "INVALID" assert is_valid_hex_color("#aBcDeF") == "VALID" assert is_valid_hex_c...
[ { "docstring": "Determines if a given string is a valid hexadecimal color code.\n\nParameters:\ncode (str): The string to validate.\n\nReturns:\nstr: \"VALID\" if the string is a valid hex color code, \"INVALID\" otherwise.", "function_declaration": "def is_valid_hex_color(code):", "function_name": "is_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef validate_hex_color_codes(n, color_codes):\n \"\"\"\n Checks if the given strings are valid hexadecimal color codes.\n\n Parameter...
trial_gpt4o_2
{ "original_instruction": "Given a number n and n strings, determine if the given strings are valid hexadecimal color codes.\n\nA valid hexadecimal color code starts with a \"#\" followed by exactly 6 characters that can be digits (0-9) or letters (a-f, A-F).\n\nInput:\n\n- First line contains an integer n (1 ≤ n ≤ 1...
0.54002
Code_Contests_44158
C
[ "is_valid_hex_color", "check_hex_codes" ]
2
[ [ "check_hex_codes", "is_valid_hex_color" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3ad67a0dd06634025c95483bea39d1f61320c73b
e978acc13c94efc6c8fc0e9ccf2b7ef7ea03b7e9
v1.0
complete
Code_Contests
Code_Contests_44399_C
MOD = 10**9 + 7 def fibonacci_sum_up_to(n): """ Returns the sum of all Fibonacci numbers up to and including F(n), modulo 10^9 + 7. """ pass def fibonacci_sequence_sum(n, a): """ Determines the sequence b from the given sequence a, where each b_i is the sum of all Fibonacci numbers up to t...
MOD = 10**9 + 7 def fibonacci_sum_up_to(n): """ Returns the sum of all Fibonacci numbers up to and including F(n), modulo 10^9 + 7. """ if n == 0: return 0 elif n == 1: return 1 fib = [0] * (n + 1) fib[1] = 1 for i in range(2, n + 1): fib[i] = fib[i-1] + fib...
from solution import fibonacci_sequence_sum, fibonacci_sum_up_to def test_fibonacci_sum_up_to(): assert fibonacci_sum_up_to(0) == 0 assert fibonacci_sum_up_to(1) == 1 assert fibonacci_sum_up_to(2) == 2 # 0, 1, 1 -> 0+1+1 assert fibonacci_sum_up_to(3) == 4 # 0, 1, 1, 2 -> 0+1+1+2 assert fibonacci_...
[ { "docstring": "Returns the sum of all Fibonacci numbers up to and including F(n), modulo 10^9 + 7.", "function_declaration": "def fibonacci_sum_up_to(n):", "function_name": "fibonacci_sum_up_to", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def fibonacci_sequ...
[ 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 fib_sequence_sum(n, a):\n MOD = 10**9 + 7\n \n # Generate the Fibonacci sequence up to the maximum value in a\n max_a = max(a)\n fibs = ...
trial_gpt4o_1
{ "original_instruction": "In a distant galaxy, there exists a planet called Fibbonis where the Fibonacci sequence governs all aspects of life. The residents of Fibbonis have a unique tradition regarding their sequences and they have come up with an intriguing problem:\n\nGiven a sequence of n integers a_0, a_1, ...,...
0.694859
Code_Contests_44399
C
[ "fibonacci_sum_up_to", "fibonacci_sequence_sum", "main" ]
3
[ [ "fibonacci_sequence_sum", "fibonacci_sum_up_to" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f42b9a402d57424a4078153b0d64d2afadaea711
32c8f600e4174bb299c8eae0b9f0a8870ca3908b
v1.0
complete
Code_Contests
Code_Contests_43995_C
import re from typing import List def process_palindromes(t: int, strings: List[str]) -> List[str]: """ Process a list of strings to determine if each is a valid palindrome. t - number of test cases strings - list of strings to be checked Returns a list of "Yes" or "No" based on the palin...
import re def is_valid_palindrome(s): """ Check if a given string s is a valid palindrome by considering only alphanumeric characters and ignoring cases. """ # Remove non-alphanumeric characters and convert to lowercase filtered_s = re.sub(r'[^a-zA-Z0-9]', '', s).lower() # Check if the filt...
import pytest from solution import process_palindromes def test_process_palindromes_basic(): t = 4 strings = [ "A man, a plan, a canal, Panama", "race a car", "Madam In Eden, I'm Adam", "No lemon, no melon" ] expected = ["Yes", "No", "Yes", "Yes"] assert process_pali...
[ { "docstring": "Check if a given string s is a valid palindrome by considering only\nalphanumeric characters and ignoring cases.", "function_declaration": "def is_valid_palindrome(s):", "function_name": "is_valid_palindrome", "parameter_list": "(s)" }, { "docstring": "Process a list of strin...
[ 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_valid_palindrome(s):\n \"\"\"\n Returns 'Yes' if the given string s is a valid palindrome, otherwise returns 'No'.\n \"\"\"\n # Remove n...
trial_gpt4o_2
{ "original_instruction": "A palindrome is a word, number, phrase, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). For this coding task, you need to determine whether the given string is a valid palindrome by considering only alphanumeric ch...
0.779691
Code_Contests_43995
C
[ "is_valid_palindrome", "process_palindromes" ]
2
[ [ "process_palindromes", "is_valid_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bf057f63242ec3a584ee3f4c5431ea098d8b643c
509db9e4afe8c44cf2f593eef188ad5cb9e805af
v1.0
complete
Code_Contests
Code_Contests_45025_C
def can_form_palindrome(s: str) -> bool: """ Determines if the input string s can be rearranged to form a palindrome. >>> can_form_palindrome('level') True >>> can_form_palindrome('abc') False """ pass def logistics_palindrome(n: int, s: str) -> str: """ Determines if it is possible for...
def can_form_palindrome(s): """ Determines if the input string s 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 logistics_palindrome(n, s): ...
from solution import can_form_palindrome, logistics_palindrome def test_can_form_palindrome(): assert can_form_palindrome('level') == True assert can_form_palindrome('abc') == False assert can_form_palindrome('a') == True assert can_form_palindrome('racecar') == True assert can_form_palindrome('aab...
[ { "docstring": "Determines if the input string s can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Determines if it is possible for the sequence of delivered pack...
[ 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 can_form_palindrome(n, s):\n \"\"\"\n Determines if the sequence of delivered packages can be rearranged to form a palindrome.\n \"\"\"\n f...
trial_gpt4o_2
{ "original_instruction": "The city of Florapack is filled with delivery trucks that need to deliver packages to different sectors. Each package has a specific target sector assigned to it. The truck drivers are very busy and sometimes make mistakes—they might deliver a package to the wrong sector. There is a curious...
0.670774
Code_Contests_45025
C
[ "can_form_palindrome", "logistics_palindrome" ]
2
[ [ "logistics_palindrome", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1545e2d69dcfaa8b1b20f91c96c4f882ff773e74
0955071bef6e08e9932f698ba057037a3dd497cb
v1.0
complete
Code_Contests
Code_Contests_44970_C
def is_prime(num: int) -> bool: """Determine if a number is a prime number. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(5) == True >>> is_prime(1) == False """ def count_primes(n: int, numbers: List[int]) -> int: """Count the number of prime...
def is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def count_primes(n, numbers): prime_count = 0 for number in numbers: if is_prime(number): prime_count += 1 return prime_co...
from solution import is_prime, count_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(1) == False assert is_prime(0) == False assert is_prime(29) == True assert is_prime(30) == False ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def count_primes(n, numbers):", "function_name": "count_primes", "parameter_list": "(n, numbers)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return T...
trial_gpt4o_2
{ "original_instruction": "Alice is learning about prime numbers and their applications. She found an interesting problem to solve: given a list of integers, determine how many of them are prime numbers. A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. Help Alice by w...
0.783899
Code_Contests_44970
C
[ "is_prime", "count_primes" ]
2
[ [ "count_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
136afa90e50e1536078e795b9beefcddf831fa26
d41470175bafef486742d1930c3480e569a77c70
v1.0
complete
Code_Contests
Code_Contests_44882_C
from typing import List def perform_operations(N: int, M: int, armor_values: List[int], operations: List[List[int]]) -> List[int]: """ Perform a series of operations on the armor values of knights. Args: N (int): Number of knights. M (int): Number of operations. armor_values (List[int]): List of i...
def update_armor(arr, l, r, k): for i in range(l, r + 1): arr[i] += k def calculate_sum(arr, l, r): return sum(arr[l:r + 1]) def perform_operations(N, M, armor_values, operations): results = [] for operation in operations: if operation[0] == 1: _, l, r, k = operatio...
from solution import perform_operations def test_operations_example_case(): N = 6 M = 5 armor_values = [10, 20, 30, 40, 50, 60] operations = [ [2, 1, 3], [1, 2, 4, 10], [2, 2, 5], [1, 3, 6, 5], [2, 1, 6] ] results = perform_operations(N, M, armor_val...
[ { "docstring": null, "function_declaration": "def update_armor(arr, l, r, k):", "function_name": "update_armor", "parameter_list": "(arr, l, r, k)" }, { "docstring": null, "function_declaration": "def calculate_sum(arr, l, r):", "function_name": "calculate_sum", "parameter_list":...
[ 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 update_knight_armor(N, M, armor_values, operations):\n \"\"\"\n Function to handle operations on knight armors\n \n Parameters:\n N (int...
trial_gpt4o_1
{ "original_instruction": "In a kingdom far away, there are N knights standing in a row, numbered 1 through N. Each knight has a certain amount of armor represented by an integer array A of length N, where Ai denotes the armor value of the ith knight. The king has planned some operations to improve their armor or che...
0.578692
Code_Contests_44882
C
[ "update_armor", "calculate_sum", "perform_operations" ]
3
[ [ "perform_operations", "calculate_sum" ], [ "perform_operations", "update_armor" ] ]
2
[]
false
[]
false
pytest
true
[]
true
70a80053941ae1bda23e370113aa7c68df2a6a49
08f4324cc673f16bdb3912820ad937269ee1df83
v1.0
complete
Code_Contests
Code_Contests_44718_C
def sort_recyclables(n: int, objects: List[Tuple[int, int]]) -> Dict[int, List[int]]: """ Sorts recyclable objects by their material type. Args: n (int): The number of objects. objects (List[Tuple[int, int]]): A list of tuples where each tuple contains an object ID and a material type identifier. ...
def sort_recyclables(n, objects): from collections import defaultdict, OrderedDict material_bins = OrderedDict() for obj_id, material_type in objects: if material_type not in material_bins: material_bins[material_type] = [] material_bins[material_type].append(obj_id) ...
def test_sort_recyclables(): objects = [ (4, 7), (6, 3), (1, 7), (8, 2), (2, 3), (5, 2), (7, 3), (3, 2) ] expected_output = { 7: [1, 4], 3: [2, 6, 7], 2: [3, 5, 8] } assert sort_recyclables(8, objects) == expecte...
[ { "docstring": null, "function_declaration": "def sort_recyclables(n, objects):", "function_name": "sort_recyclables", "parameter_list": "(n, objects)" }, { "docstring": null, "function_declaration": "def process_input_and_output(n, objects):", "function_name": "process_input_and_out...
[ 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_recyclables(N, objects):\n from collections import defaultdict, OrderedDict\n \n material_dict = OrderedDict()\n \n for obj_id, mat...
trial_gpt4o_2
{ "original_instruction": "You are the manager of a recycling plant and are tasked with optimizing the waste sorting process. The plant receives a collection of mixed recyclable materials which need to be sorted based on their type. Each type of material is associated with a specific identifier, and every object in t...
0.558506
Code_Contests_44718
C
[ "sort_recyclables", "process_input_and_output" ]
2
[ [ "process_input_and_output", "sort_recyclables" ] ]
1
[]
false
[]
false
pytest
false
[]
true
2590e72cd3d353f11890d3ae363f4d92dfc4ac4b
66c7807b349484cc2ec645d3cc4d172481e2bf47
v1.0
complete
Code_Contests
Code_Contests_44835_C
def find_kth_smallest_element(n: int, k: int, arr: List[int]) -> int: """ Given a list of n integers, find the k-th smallest element in the list without sorting the entire list using the Quickselect algorithm. >>> find_kth_smallest_element(6, 2, [7, 10, 4, 3, 20, 15]) 4 >>> find_kth_smallest_element(5, 3, [...
def quickselect(arr, k): """ Returns the k-th smallest element in the array using Quickselect algorithm. """ def partition(left, right, pivot_index): pivot = arr[pivot_index] # Move pivot to end arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = le...
from solution import find_kth_smallest_element def test_example1(): n = 6 k = 2 arr = [7, 10, 4, 3, 20, 15] assert find_kth_smallest_element(n, k, arr) == 4 def test_example2(): n = 5 k = 3 arr = [7, 10, 4, 20, 15] assert find_kth_smallest_element(n, k, arr) == 10 def test_single_elem...
[ { "docstring": "Returns the k-th smallest element in the array using Quickselect algorithm.", "function_declaration": "def quickselect(arr, k):", "function_name": "quickselect", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def find_kth_smallest_element(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 quickselect(arr, low, high, k):\n if low == high: # If the list contains only one element,\n return arr[low] # return that element\n\n p...
trial_gpt4o_2
{ "original_instruction": "Given a list of `n` integers, you need to find the k-th smallest element in the list without sorting the entire list. Implement this using the Quickselect algorithm.\n\n### Input\n- The first line contains two integers, `n` and `k` (1 ≤ k ≤ n ≤ 100,000), where `n` is the number of elements ...
0.698677
Code_Contests_44835
C
[ "quickselect", "find_kth_smallest_element" ]
2
[ [ "find_kth_smallest_element", "quickselect" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb9abd68379c8eba42a9972fdbd04e43b919f074
951249fda80eda6c186e6aaa5997e65774378e5a
v1.0
complete
Code_Contests
Code_Contests_45029_C
from typing import List, Tuple def check_alignment(rows: List[List[Tuple[int, int]]]) -> List[str]: """ For each row, determines if all the cards are aligned vertically or horizontally. Parameters: rows (list): A list of rows, where each row is a list of (x, y) tuples representing card positions. ...
def check_alignment(rows): """ For each row, determines if all the cards are aligned vertically or horizontally. Parameters: rows (list): A list of rows, where each row is a list of (x, y) tuples representing card positions. Returns: List[str]: A list of "YES" or "NO" indicating if the res...
import pytest from solution import parse_input, check_alignment, solve from io import StringIO import sys def test_check_alignment_all_vertical(): rows = [[(1, 2), (1, 3), (1, 4)], [(2, 2), (2, 3)]] assert check_alignment(rows) == ['YES', 'YES'] def test_check_alignment_all_horizontal(): rows = [[(1, 1), ...
[ { "docstring": "For each row, determines if all the cards are aligned vertically or horizontally.\n\nParameters:\nrows (list): A list of rows, where each row is a list of (x, y) tuples representing card positions.\n\nReturns:\nList[str]: A list of \"YES\" or \"NO\" indicating if the respective row is aligned or...
[ 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 check_alignment(rows):\n results = []\n for row in rows:\n if all(x == row[0][0] for x, y in row) or all(y == row[0][1] for x, y in row):\...
trial_gpt4o_2
{ "original_instruction": "AtCoDeer the deer found N rows of matching cards on the table, each row containing a number of cards visible at varying positions. Each position is represented as an integer coordinate (x, y) on a two-dimensional plane, where 1 ≤ x, y ≤ 10^9.\n\nFor each row, if two or more cards form a str...
0.646504
Code_Contests_45029
C
[ "check_alignment", "parse_input", "solve" ]
3
[ [ "solve", "check_alignment" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
bdde228eeed77537b9a5d0361cbb4469d5efadd8
d13b4db8382eef459d215b0dd6da1810782b4951
v1.0
complete
Code_Contests
Code_Contests_45149_C
def shortest_supersequence_length(s1: str, s2: str) -> int: """ Find the length of the shortest string that can be formed which contains both s1 and s2 as subsequences. >>> shortest_supersequence_length("abc", "ac") 3 >>> shortest_supersequence_length("abc", "def") 6 """
def lcs_length(s1, s2): """ Helper function to find the length of the longest common subsequence between s1 and s2. """ m, n = len(s1), len(s2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if s1[i - 1] == s2[j - 1]: ...
from solution import shortest_supersequence_length def test_sample1(): assert shortest_supersequence_length("abc", "ac") == 3 def test_sample2(): assert shortest_supersequence_length("abc", "def") == 6 def test_overlap(): assert shortest_supersequence_length("abcd", "abef") == 6 def test_identical(): ...
[ { "docstring": "Helper function to find the length of the longest common subsequence between s1 and s2.", "function_declaration": "def lcs_length(s1, s2):", "function_name": "lcs_length", "parameter_list": "(s1, s2)" }, { "docstring": "Returns the length of the shortest string that contains ...
[ 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 lcs(s1, s2):\n \"\"\"\n Returns the length of the longest common subsequence between s1 and s2.\n \"\"\"\n m, n = len(s1), len(s2)\n dp ...
trial_gpt4o_2
{ "original_instruction": "You are given two strings, `s1` and `s2`, both consisting of lowercase English letters. You are tasked with finding the length of the shortest string that can be formed which contains both `s1` and `s2` as subsequences.\n\nInput\n\nThe first line contains the string `s1` (1 ≤ |s1| ≤ 100). T...
0.628821
Code_Contests_45149
C
[ "lcs_length", "shortest_supersequence_length" ]
2
[ [ "shortest_supersequence_length", "lcs_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a8874f6e5484634ef32e0165b7f92f8e90abfe9f
ac5fd5290b27d8bb6a597653cd12c457d80d0e82
v1.0
complete
Code_Contests
Code_Contests_44753_C
def sum_of_digits(n: int) -> int: """ Returns the sum of the digits of a number. >>> sum_of_digits(34) == 7 >>> sum_of_digits(56) == 11 >>> sum_of_digits(12) == 3 >>> sum_of_digits(23) == 5 >>> sum_of_digits(45) == 9 """ def johns_travel_order(distances: List[int]) -> List[int]: """...
def sum_of_digits(n): """ Returns the sum of the digits of a number. """ return sum(int(d) for d in str(n)) def johns_travel_order(distances): """ Given a list of distances, returns a list of distances in the order that John will visit the cities. """ order = sorted(distances, key=l...
from solution import johns_travel_order def test_basic_case(): distances = [34, 56, 12, 23, 45] assert johns_travel_order(distances) == [12, 23, 34, 45, 56] def test_single_city(): distances = [5] assert johns_travel_order(distances) == [5] def test_same_sum_digits(): distances = [19, 28, 37] ...
[ { "docstring": "Returns the sum of the digits of a number.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Given a list of distances, returns a list of distances in the order that\nJohn will visit the cities.", ...
[ 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 travel_order(n, distances):\n \"\"\"\n Returns the order in which John will visit the cities based on the sum of digits of the distances.\n \"...
trial_gpt4o_3
{ "original_instruction": "**Problem:**\n\nJohn is a passionate traveler who loves to visit various cities. However, John has a unique way of traveling. He always starts his journey from his home city and chooses the next city to visit based on the sum of the digits of the distance between the current city he is in a...
0.602764
Code_Contests_44753
C
[ "sum_of_digits", "johns_travel_order" ]
2
[ [ "johns_travel_order", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c216403f16880cf58a18ab4e3f4de4a34b39685d
62c82b934f2256103c9b4c7cbe1836eef8ffa7e5
v1.0
complete
Code_Contests
Code_Contests_45028_C
def maximalRectangle(board: List[str]) -> int: """ Find the largest rectangular subarray consisting entirely of 1s. >>> maximalRectangle(["10110", "10111", "11111", "10010"]) 6 >>> maximalRectangle(["1" * 100] * 100) 10000 >>> maximalRectangle(["0" * 5] * 4) 0 >>> maximalRectangle([...
def maximalRectangle(board): if not board: return 0 n = len(board) m = len(board[0]) max_area = 0 heights = [0] * m for i in range(n): for j in range(m): if board[i][j] == '1': heights[j] += 1 else: heights[j] = 0 ...
from solution import maximalRectangle def test_maximal_rectangle_example(): board = ["10110", "10111", "11111", "10010"] assert maximalRectangle(board) == 6 def test_maximal_rectangle_large(): board = ["1" * 100] * 100 assert maximalRectangle(board) == 10000 def test_maximal_rectangle_no_ones(): ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(board):", "function_name": "maximalRectangle", "parameter_list": "(board)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_...
[ 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(n, m, board):\n \"\"\"\n Returns the area of the largest rectangular subarray consisting entirely of 1s in a board of size n x m...
trial_gpt4o_2
{ "original_instruction": "You are given a board of size n x m where each cell contains a number which is either 0 or 1. Your task is to find the largest rectangular subarray consisting entirely of 1s. The size of the board (n x m) and the contents of the board are provided as input.\n\n### Input\n- The first line co...
0.639362
Code_Contests_45028
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5de7d2ce1ae812a7cee93087c4b00e7b690676f9
b59239ec45e71024b50e9b8d5a4af34dbefa5feb
v1.0
complete
Code_Contests
Code_Contests_45130_C
def longest_path_from_input(input_str: str) -> int: """ Given a directed acyclic graph (DAG) with N nodes and M edges, find the length of the longest path in the graph. The input is given from a string in the following format: N M u_1 v_1 u_2 v_2 : u_M v_M Each pair (u...
def longest_path_in_dag(n, m, edges): from collections import defaultdict, deque # Build the graph graph = defaultdict(list) in_degree = [0] * (n + 1) for u, v in edges: graph[u].append(v) in_degree[v] += 1 # Topological Sort (Kahn's Algorithm) topo_order = [] queue = ...
import pytest from solution import longest_path_from_input def test_longest_path_example_1(): input_str = "4 4\n1 2\n2 3\n3 4\n1 3" assert longest_path_from_input(input_str) == 3 def test_longest_path_example_2(): input_str = "6 7\n1 2\n1 3\n2 5\n3 4\n4 5\n5 6\n3 5" assert longest_path_from_input(inpu...
[ { "docstring": null, "function_declaration": "def longest_path_in_dag(n, m, edges):", "function_name": "longest_path_in_dag", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "paramete...
[ 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_longest_path(N, M, edges):\n from collections import defaultdict, deque\n\n # Initialize the graph and in-degrees\n graph = defaultdict(l...
trial_gpt4o_2
{ "original_instruction": "Given a directed acyclic graph (DAG) with N nodes and M edges, you need to find the length of the longest path in the graph. A path is defined as a sequence of nodes where there is a direct edge from each node to the next in the sequence.\n\nNodes are numbered from 1 to N.\n\nConstraints:\n...
0.574432
Code_Contests_45130
C
[ "longest_path_in_dag", "parse_input", "longest_path_from_input" ]
3
[ [ "longest_path_from_input", "longest_path_in_dag" ], [ "longest_path_from_input", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
3799ede554e4dab746b0aea4d74ad0c9ff8d4640
82cd2c0ea09b68ddf9802e748ff5c4c6ff8a15a4
v1.0
complete
Code_Contests
Code_Contests_44941_C
def is_circularly_increasing(arr): """ Determine if the array can be considered circularly increasing. >>> is_circularly_increasing([3, 4, 1, 2]) "YES" >>> is_circularly_increasing([2, 3, 4, 5, 1]) "YES" >>> is_circularly_increasing([1, 3, 5, 2, 4]) "NO" >>> is_circularly_increasing([10,...
def is_circularly_increasing(arr): n = len(arr) increase_points = sum(arr[i] < arr[(i + 1) % n] for i in range(n)) return increase_points == n - 1 def solve(test_cases): results = [] for arr in test_cases: if is_circularly_increasing(arr): results.append("YES") else: ...
from solution import main def test_example_case(): raw_input = "4\n4\n3 4 1 2\n5\n2 3 4 5 1\n5\n1 3 5 2 4\n3\n10 20 30\n" expected_output = "YES\nYES\nNO\nYES" assert main(raw_input) == expected_output def test_all_same_elements(): raw_input = "1\n5\n5 5 5 5 5\n" expected_output = "NO" assert ...
[ { "docstring": null, "function_declaration": "def is_circularly_increasing(arr):", "function_name": "is_circularly_increasing", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", "parameter_list": "(test_c...
[ 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_circularly_increasing(arr):\n n = len(arr)\n for i in range(n):\n if all(arr[(i + k) % n] < arr[(i + k + 1) % n] for k in range(n - 1))...
trial_gpt4o_4
{ "original_instruction": "You are given an array `arr` of size `n`. Your task is to determine whether the array can be considered \"circularly increasing\". An array is called circularly increasing if it can be rotated in such a way that each element is smaller than the next element, except for the largest element w...
0.60662
Code_Contests_44941
C
[ "is_circularly_increasing", "solve", "process_input", "format_output", "main" ]
5
[ [ "solve", "is_circularly_increasing" ] ]
1
[ "process_input", "format_output" ]
false
[]
false
pytest
true
[]
true
00864324915bc330ef10d8f4457f5a8540a268e3
b6a7d1c563e8eae999da2718c3b3ff437ffbba2e
v1.0
complete
Code_Contests
Code_Contests_44536_C
def shortest_subarray_with_sum(nums: List[int], s: int) -> int: """ Given an array of positive integers and a target sum, determine the length of the shortest subarray with a sum that is greater than or equal to the target sum. >>> shortest_subarray_with_sum([2, 3, 1, 2, 4, 3], 7) 2 >>> shortest_subarr...
def shortest_subarray_with_sum(nums, s): n = len(nums) left = 0 current_sum = 0 min_length = float('inf') for right in range(n): current_sum += nums[right] while current_sum >= s: min_length = min(min_length, right - left + 1) current_sum -= nums...
def test_shortest_subarray_with_sum(): # Test case 1: Example 1 input_data = "6 7\n2 3 1 2 4 3" assert get_shortest_subarray_length(input_data) == 2 # Test case 2: Example 2 input_data = "5 11\n1 2 3 4 5" assert get_shortest_subarray_length(input_data) == 3 # Test case 3: Example 3...
[ { "docstring": null, "function_declaration": "def shortest_subarray_with_sum(nums, s):", "function_name": "shortest_subarray_with_sum", "parameter_list": "(nums, s)" }, { "docstring": null, "function_declaration": "def get_shortest_subarray_length(input_data):", "function_name": "get...
[ 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 shortest_subarray_length(nums, target):\n \"\"\"\n Returns the length of the shortest subarray with sum >= target, or -1 if no such subarray exis...
trial_gpt4o_2
{ "original_instruction": "Given an array of positive integers and a target sum, determine the length of the shortest subarray with a sum that is greater than or equal to the target sum. A subarray is a contiguous part of an array.\n\nInput\n\nThe first line contains two integers n and s (1 ≤ n ≤ 10^5, 1 ≤ s ≤ 10^9),...
0.736373
Code_Contests_44536
C
[ "shortest_subarray_with_sum", "get_shortest_subarray_length" ]
2
[ [ "get_shortest_subarray_length", "shortest_subarray_with_sum" ] ]
1
[]
false
[]
false
pytest
false
[]
true
0abc7d6b0512312bc6792e86e762dd7fdffffc0b
3957381cce3770a6e2a3cd27d843c52dc458b9a5