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_17473_C | def is_prime(n):
""" Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def longest_non_prime_produ... | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def longest_non_prime_p... | from solution import longest_non_prime_product_subseq_length
def test_example_cases():
assert longest_non_prime_product_subseq_length(7, [1, 2, 3, 4, 5, 6, 7]) == 7
assert longest_non_prime_product_subseq_length(6, [2, 3, 5, 7, 11, 13]) == 1
def test_single_element():
assert longest_non_prime_product_subs... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the length of the longest contiguous sub-sequence whose product is not a prime number.",
"function_declaratio... | [
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 Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return Tr... | trial_gpt4o_0 | {
"original_instruction": "Daniel loves challenges involving sequences, especially when it involves prime numbers. He recently stumbled upon a problem and needs your help to solve it.\n\nGiven a sequence of n integers, he wants to know the length of the longest contiguous sub-sequence in which the product of its elem... | 0.743466 | Code_Contests_17473 | C | [
"is_prime",
"longest_non_prime_product_subseq_length"
] | 2 | [
[
"longest_non_prime_product_subseq_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2b7f663b791165bbbfb00d4e04c3358f4d1ef0c8 | d39167402f78639375961404f20d3576dddc028a | |||
v1.0 | complete | Code_Contests | Code_Contests_17495_C | def preprocess_prefix_sums(arr):
prefix_sums = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1]
return prefix_sums
def range_sum(arr, queries):
""" Compute the sum of elements in the specified range for each query.
>>> range_sum([1, 2, 3... | def preprocess_prefix_sums(arr):
prefix_sums = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1]
return prefix_sums
def range_sum(arr, queries):
prefix_sums = preprocess_prefix_sums(arr)
result = []
for l, r in queries:
sum_ra... | from solution import range_sum
def test_small_range():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 4), (1, 5)]
expected_output = [6, 9, 15]
assert range_sum(arr, queries) == expected_output
def test_full_range():
arr = [1, -2, 3, -4, 5]
queries = [(1, 5)]
expected_output = [3]
assert ... | [
{
"docstring": null,
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def range_sum(arr, queries):",
"function_name": "range_sum",
"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 range_sums(n, arr, queries):\n \"\"\"\n Computes the sum of the elements in a specified range for each query.\n\n Parameters:\n n (int): Nu... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of n integers. You need to process q queries, each of which asks you to compute the sum of the elements in a specified range of the array. Formally, each query is represented by two integers l and r, you are to find the sum of elements from al to ar (both inclusive).\... | 0.641216 | Code_Contests_17495 | C | [
"preprocess_prefix_sums",
"range_sum"
] | 2 | [
[
"range_sum",
"preprocess_prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0f05bd7396286004fbcb37815b6ff32fa9d65627 | 2faddcd35e86db9f198c046c6829823011496653 | |||
v1.0 | complete | Code_Contests | Code_Contests_17615_C | def minimal_new_cables_to_connect(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
""" Calculate the minimal number of cables that need to be added to make the network connected.
Args:
n: int - number of servers (nodes)
m: int - number of cables (edges)
edges: List[Tuple[int, int]] - list ... | def find_root(roots, i):
if roots[i] != i:
roots[i] = find_root(roots, roots[i])
return roots[i]
def union(roots, rank, x, y):
rootX = find_root(roots, x)
rootY = find_root(roots, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
roots[rootY] = rootX
elif ... | from solution import minimal_new_cables_to_connect
def test_example_1():
n, m = 6, 3
edges = [(1, 2), (4, 5), (2, 3)]
assert minimal_new_cables_to_connect(n, m, edges) == 2
def test_example_2():
n, m = 5, 0
edges = []
assert minimal_new_cables_to_connect(n, m, edges) == 4
def test_example_3()... | [
{
"docstring": null,
"function_declaration": "def find_root(roots, i):",
"function_name": "find_root",
"parameter_list": "(roots, i)"
},
{
"docstring": null,
"function_declaration": "def union(roots, rank, x, y):",
"function_name": "union",
"parameter_list": "(roots, rank, x, y)"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, 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_1 | {
"original_instruction": "Violet is creating a new network for her startup company. This consists of several servers connected via network cables. Each server is represented by a node, and each cable by an edge in an undirected graph. Unfortunately, some of the network cables are already broken.\n\nViolet needs a wa... | 0.636419 | Code_Contests_17615 | C | [
"find_root",
"union",
"minimal_new_cables_to_connect"
] | 3 | [
[
"minimal_new_cables_to_connect",
"find_root"
],
[
"minimal_new_cables_to_connect",
"union"
],
[
"union",
"find_root"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 75d78ccbea6479e79acd333efc451d10598d7683 | 0f199592f8538d293442d56398613d5daff35139 | |||
v1.0 | complete | Code_Contests | Code_Contests_17573_C | def min_max_bridge(n: int, m: int, edges: List[tuple[int, int, int]]) -> int:
"""
You are given a list of buildings in a city and the distances between some of these buildings.
The city council wants to build a sky bridge network that connects all buildings directly or indirectly.
However, the bridges... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > ... | from solution import min_max_bridge
def test_example_1():
n = 4
m = 5
edges = [
(1, 2, 4),
(1, 3, 2),
(2, 4, 6),
(3, 4, 8),
(3, 2, 3)
]
assert min_max_bridge(n, m, edges) == 6
def test_example_2():
n = 4
m = 2
edges = [
(1, 2, 7),
... | [
{
"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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of buildings in a city and the distances between some of these buildings. The city council wants to build a sky bridge network that connects all buildings directly or indirectly. However, the bridges need to be designed in such a way that the longest bridge is as short ... | 0.651717 | Code_Contests_17573 | C | [
"find",
"union",
"min_max_bridge",
"main"
] | 4 | [
[
"min_max_bridge",
"find"
],
[
"min_max_bridge",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 10af1d0e16388670b5a933806d029b31ba34da73 | f39555a03722c9aa1f02291c1d047aca964a3bb6 | |||
v1.0 | complete | Code_Contests | Code_Contests_17610_C | def generate_password(n: int, v: int) -> str:
"""
Generates a valid password that satisfies the conditions:
- length of the password must be exactly n
- must contain only lowercase letters from 'a' to 'z'
- must have at least one vowel ('a', 'e', 'i', 'o', 'u')
- number of vowels in the passwor... | def generate_password(n, v):
"""
Generates a valid password that satisfies the conditions:
- length of the password must be exactly n
- must contain only lowercase letters from 'a' to 'z'
- must have at least one vowel ('a', 'e', 'i', 'o', 'u')
- number of vowels in the password must not exceed ... | def test_generate_password():
assert generate_password(5, 2) == 'aeiou'[:2] + 'bcdfghjklmnpqrstvwxyz'[:3]
assert generate_password(4, 1) == 'aeiou'[:1] + 'bcdfghjklmnpqrstvwxyz'[:3]
assert generate_password(6, 3) == 'aeiou'[:3] + 'bcdfghjklmnpqrstvwxyz'[:3]
def test_generate_passwords():
test_cases = ... | [
{
"docstring": "Generates a valid password that satisfies the conditions:\n- length of the password must be exactly n\n- must contain only lowercase letters from 'a' to 'z'\n- must have at least one vowel ('a', 'e', 'i', 'o', 'u')\n- number of vowels in the password must not exceed v",
"function_declaration... | [
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 random\n\ndef generate_password(n, v):\n # Generate a password with exactly n characters and at least one vowel, not exceeding v vowels\n vowe... | trial_gpt4o_2 | {
"original_instruction": "Alice is organizing a fun programming contest for her friends. She wants one of the tasks to involve generating a valid password that follows specific rules. The rules are:\n\n* The password must contain only lowercase letters from 'a' to 'z'.\n* The length of the password must be exactly n... | 0.663144 | Code_Contests_17610 | C | [
"generate_password",
"generate_passwords",
"solve"
] | 3 | [
[
"generate_passwords",
"generate_password"
],
[
"solve",
"generate_passwords"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f79019af4e212ba2d3ef650c7afd894d5207ca36 | 3cb0ebfa3aa7ac34b00f8f54931b5778cbe53856 | |||
v1.0 | complete | Code_Contests | Code_Contests_16937_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(nodes):
tree_dict = {val: TreeNode(val) for val, left, right in nodes}
root = tree_dict[nodes[0][0]]
for val, left, right in nodes:
i... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(nodes):
tree_dict = {val: TreeNode(val) for val, left, right in nodes}
root = tree_dict[nodes[0][0]]
for val, left, right in nodes:
i... | def test_single_node():
input_data = "5 -1 -1"
assert max_sum_from_input(input_data) == 5
def test_tree_with_left_child():
input_data = "10 7 -1\n7 -1 -1"
assert max_sum_from_input(input_data) == 17
def test_complete_binary_tree():
input_data = "1 2 3\n2 4 5\n3 -1 6\n4 -1 -1\n5 -1 -1\n6 -1 -1"
... | [] | [
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, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\... | trial_gpt4o_1 | {
"original_instruction": "In a given binary tree, each node has a value associated with it. We need to find the maximum sum of values from the root to any leaf. The root is defined as the topmost node, and a leaf is any node that does not have any children.\n\nInput\n\nThe input consists of multiple lines where each... | 0.603105 | Code_Contests_16937 | C | [
"build_tree",
"max_sum_root_to_leaf",
"max_sum_from_input"
] | 3 | [
[
"max_sum_from_input",
"build_tree"
],
[
"max_sum_from_input",
"max_sum_root_to_leaf"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 11e7cdf67d35266b84cd2d7d0fc2f4c8a4cdc6ff | 4550ad387e8ec28e67f1a6dcf43bc8f74b64e9a3 | |||
v1.0 | complete | Code_Contests | Code_Contests_17995_C | def min_total_distance(n: int, m: int, routes: List[Tuple[int, int, int]]) -> int:
"""
Manao needs to design train routes to connect cities with minimal total distance and no cycles.
This function calculates the minimum possible total distance required to connect all cities following the specified rule... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank... | from solution import min_total_distance
def test_example_case():
n = 4
m = 5
routes = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 1),
(2, 4, 5),
(3, 4, 3)
]
assert min_total_distance(n, m, routes) == 6
def test_minimal_case():
n = 2
m = 1
routes = [
(... | [
{
"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,
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 find_minimum_total_distance(n, m, routes):\n \"\"\"\n Finds minimum possible total distance required to connect all cities without cycles.\n \... | trial_gpt4o_8 | {
"original_instruction": "Manao is also tasked with designing the routes for a network of high-speed trains. The train routes will connect various cities in such a way that every city is connected to at least one other city, and there are no cycles in the network. Additionally, the distances between the cities have ... | 0.726761 | Code_Contests_17995 | C | [
"find",
"union",
"kruskal",
"min_total_distance"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_total_distance",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 20b22f5e8428ed75b303e0e0fb538ef287019763 | 01b9ca63306adc0c329b59e77b372e58eb24636f | |||
v1.0 | complete | Code_Contests | Code_Contests_17426_C | def find_min_max_pages(n: int, k: int, books: List[int]) -> int:
""" Determine the optimal way to allocate n books to k students so that the maximum number of pages assigned to a student is minimized.
Args:
n (int): The number of books.
k (int): The number of students.
books (List[int]): An arr... | def is_possible(books, n, k, max_pages):
student_count = 1
current_pages = 0
for i in range(n):
if books[i] > max_pages:
return False
if current_pages + books[i] > max_pages:
student_count += 1
current_pages = books[i]
if student_count > k... | from solution import find_min_max_pages
def test_example_case_1():
n, k = 4, 2
books = [12, 34, 67, 90]
assert find_min_max_pages(n, k, books) == 113
def test_example_case_2():
n, k = 5, 3
books = [10, 20, 30, 40, 50]
assert find_min_max_pages(n, k, books) == 60
def test_single_book():
n,... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_pages(n, k, books):",
"function_name": "find_min_max... | [
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_distribution(books, n, k, max_pages_per_student):\n required_students = 1\n current_pages_sum = 0\n \n for pages in books:\n ... | trial_gpt4o_2 | {
"original_instruction": "Julia has a collection of n books, each with a number of pages. She wants to allocate these books to k students such that each student gets at least one book and the maximum number of pages assigned to a student is minimized. Help Julia determine the optimal way to allocate the books to the... | 0.686687 | Code_Contests_17426 | C | [
"is_possible",
"find_min_max_pages"
] | 2 | [
[
"find_min_max_pages",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b749ea81056019dbdf46763feb7e4a90f370221a | 217930529982d430f044eac5610253fdc95cc129 | |||
v1.0 | complete | Code_Contests | Code_Contests_18073_C | def is_prime(n):
""" Determines if n is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
"""
pass
def find_kth_prime(N, K, array):
""" Finds the K-th prime number in the array if it exists. Otherwise, returns -1.
>>> find_kth_prime(10, 3, [10, ... | def is_prime(n):
"""
Determines if n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
retu... | from solution import is_prime, find_kth_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(23) == True
def test_find_kth_prime():
assert find_kth_prime(10, 3, ... | [
{
"docstring": "Determines if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds the K-th prime number in the array if it exists.\nOtherwise, returns -1.",
"function_declaration": "def find_kth_... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal... | trial_gpt4o_4 | {
"original_instruction": "Mr. Anderson is fascinated by prime numbers. He wants to test your ability to recognize and work with prime numbers. Here is what he asks you to solve:\n\nGiven an array of integers, determine the K-th prime number that appears in the array. If the K-th prime does not exist, return -1.\n\nI... | 0.845254 | Code_Contests_18073 | C | [
"is_prime",
"find_kth_prime"
] | 2 | [
[
"find_kth_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c9aaccd5a3c2a98afb05ef6bbae055c859fba55a | 70c89ef00a1387ae2b6650a927db68bcd1d9db78 | |||
v1.0 | complete | Code_Contests | Code_Contests_18274_C | def calculate_final_price(base_price, demand_score):
"""
Calculates the final price based on the base price and demand score.
>>> calculate_final_price(100, 2) == 90.00
>>> calculate_final_price(150, 5) == 150.00
>>> calculate_final_price(200, 8) == 240.00
"""
def adjust_prices(products):
... | def calculate_final_price(base_price, demand_score):
"""
Calculates the final price based on the base price and demand score.
:param base_price: float, the base price of the product
:param demand_score: float, the demand score of the product
:return: float, the final price of the product
""... | from solution import calculate_final_price, adjust_prices
def test_calculate_final_price():
assert calculate_final_price(100, 2) == 90.00
assert calculate_final_price(150, 5) == 150.00
assert calculate_final_price(200, 8) == 240.00
assert calculate_final_price(75, 1) == 67.50
assert calculate_final... | [
{
"docstring": "Calculates the final price based on the base price and demand score.\n\n:param base_price: float, the base price of the product\n:param demand_score: float, the demand score of the product\n:return: float, the final price of the product",
"function_declaration": "def calculate_final_price(ba... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_prices(n, products):\n final_prices = []\n\n for p, d in products:\n if d < 3:\n factor = 0.9\n elif 3 <... | trial_gpt4o_1 | {
"original_instruction": "An online retailer is setting up a new system to dynamically adjust the prices of their products based on a demand score. Each product has a set base price and a demand score, which can change over time. The price of a product is adjusted by multiplying the base price by a factor based on t... | 0.600338 | Code_Contests_18274 | C | [
"calculate_final_price",
"adjust_prices"
] | 2 | [
[
"adjust_prices",
"calculate_final_price"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2453357971410e3eee671fdadccdc30e3338942 | d10dadd9394dbeffdd53a83d5b8134f5a91df496 | |||
v1.0 | complete | Code_Contests | Code_Contests_18058_C | def first_k_primes(k: int) -> List[int]:
"""Identify the first k prime numbers in a sequence.
>>> first_k_primes(5)
[2, 3, 5, 7, 11]
>>> first_k_primes(10)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
""" | 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 first_k_primes(k):
primes = []
num... | from solution import first_k_primes
def test_first_five_primes():
assert first_k_primes(5) == [2, 3, 5, 7, 11]
def test_first_ten_primes():
assert first_k_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_single_prime():
assert first_k_primes(1) == [2]
def test_large_input_primes():
assert... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def first_k_primes(k):",
"function_name": "first_k_primes",
"parameter_list": "(k)"
}
] | [
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 <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_0 | {
"original_instruction": "Alex is part of a volunteer group that assists the elderly with computer literacy. One of their projects is to help seniors with basic math exercises using a simple software application. The application generates sequences of numbers and asks the user to identify a certain property of the s... | 0.737761 | Code_Contests_18058 | C | [
"is_prime",
"first_k_primes"
] | 2 | [
[
"first_k_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba40a095414cce579b890fbf45b8070e3f28164d | 16889388c6e9e6c54aaeaa4a7bf67da4dc467838 | |||
v1.0 | complete | Code_Contests | Code_Contests_17696_C | def is_capicua(code: int) -> bool:
"""Returns True if the code is a capicua (reads the same forwards and backwards), else False.
>>> is_capicua(12321)
True
>>> is_capicua(23432)
True
>>> is_capicua(12345)
False
>>> is_capicua(1)
True
>>> is_capicua(22)
True
>>> is_capicua... | def is_capicua(code):
"""
Returns True if the code is a capicua (reads the same forwards and backwards), else False.
"""
return str(code) == str(code)[::-1]
def find_capicuas(codes):
"""
Given a list of integer codes, returns a list of capicuas (codes that read the same forwards and backwards).... | from solution import is_capicua, find_capicuas
def test_is_capicua():
assert is_capicua(12321) == True
assert is_capicua(23432) == True
assert is_capicua(12345) == False
assert is_capicua(1) == True
assert is_capicua(22) == True
assert is_capicua(123) == False
def test_find_capicuas():
ass... | [
{
"docstring": "Returns True if the code is a capicua (reads the same forwards and backwards), else False.",
"function_declaration": "def is_capicua(code):",
"function_name": "is_capicua",
"parameter_list": "(code)"
},
{
"docstring": "Given a list of integer codes, returns a list of capicuas... | [
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_capicua(code):\n \"\"\"\n Check if a given numeric code is a capicua (reads the same forwards and backwards)\n \"\"\"\n code_str = str(c... | trial_gpt4o_2 | {
"original_instruction": "Problem Description\n\nThe citizens of a small town have a unique way of organizing their local library. Each book has a unique numeric code and they want to organize the bookshelfs such that books with capicua codes (which read the same forwards and backwards) are placed in a special secti... | 0.558814 | Code_Contests_17696 | C | [
"is_capicua",
"find_capicuas"
] | 2 | [
[
"find_capicuas",
"is_capicua"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 81013579bfc573702c96d205cc40dbbe53a7b8ea | 68fe065f45d8dc35d698682a711c38af1ac6d344 | |||
v1.0 | complete | Code_Contests | Code_Contests_17980_C | def manhattan_distance(x1, y1, x2, y2):
"""
Returns the Manhattan distance between two points (x1, y1) and (x2, y2).
>>> manhattan_distance(1, 1, 5, 5)
8
>>> manhattan_distance(2, 3, 4, 1)
4
"""
pass
def shortest_paths(N: int, P: int, parcels: List[Tuple[int, int, int, int]]) -> List[in... | def manhattan_distance(x1, y1, x2, y2):
"""
Returns the Manhattan distance between two points (x1, y1) and (x2, y2).
"""
return abs(x1 - x2) + abs(y1 - y2)
def shortest_paths(N, P, parcels):
"""
Returns a list of the shortest paths for delivering each parcel as per the Manhattan distance metric... | from solution import manhattan_distance, shortest_paths
def test_manhattan_distance():
assert manhattan_distance(1, 1, 5, 5) == 8
assert manhattan_distance(2, 3, 4, 1) == 4
assert manhattan_distance(0, 0, 0, 0) == 0
assert manhattan_distance(0, 0, 1, 1) == 2
assert manhattan_distance(3, 5, -3, -5) ... | [
{
"docstring": "Returns the Manhattan distance between two points (x1, y1) and (x2, y2).",
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Returns a list of the shortest paths fo... | [
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 manhattan_distance(N, P, parcels):\n \"\"\"\n Returns the Manhattan distances for a list of parcels.\n \n Parameters:\n N (int): the... | trial_gpt4o_1 | {
"original_instruction": "You are part of a delivery system in a city which is represented by a grid of size NxN. There are P parcels that need to be delivered to their respective destinations. The city has many crosswalks where delivery personnel can change their walking direction. The aim is to determine the short... | 0.64886 | Code_Contests_17980 | C | [
"manhattan_distance",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b42582855ca9db0115303b7b8dea6a2d79e8e0e5 | 2c9e3a943af51ae16351758793dd5070a33ac455 | |||
v1.0 | complete | Code_Contests | Code_Contests_17300_C | from typing import List, Tuple
def min_steps_to_reach_target(n: int, m: int, k: int, grid: List[List[str]], sx: int, sy: int, tx: int, ty: int, bombs: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum number of steps required to reach the target cell, avoiding all obstacles and bomb-affected cells.
... | from collections import deque
def bfs_shortest_path(grid, start, target, n, m):
sx, sy = start
tx, ty = target
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(sx, sy, 0)])
visited = set([(sx, sy)])
while queue:
x, y, d = queue.popleft()
if (x, ... | def test_min_steps_to_reach_target_1():
n = 6
m = 7
k = 1
grid = [
list("......."),
list("...#..."),
list("......."),
list(".#....."),
list("......."),
list("......."),
]
sx, sy, tx, ty = 1, 1, 6, 7
bombs = [(3, 3, 2)]
result = min_steps_to... | [
{
"docstring": null,
"function_declaration": "def bfs_shortest_path(grid, start, target, n, m):",
"function_name": "bfs_shortest_path",
"parameter_list": "(grid, start, target, n, m)"
},
{
"docstring": null,
"function_declaration": "def apply_bombs(grid, bombs, n, m):",
"function_nam... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_target(n, m, k, grid, sx, sy, tx, ty, bombs):\n def in_bounds(x, y):\n return 0 <= x < n and 0 ... | trial_gpt4o_8 | {
"original_instruction": "Imagine a vast battlefield represented as a grid of size n x m, where each cell is either an empty cell ('.') or a cell with an obstacle ('#'). You are a general in charge of leading a squad of soldiers, and your task is to move the entire squad from a given starting cell (sx, sy) to a targ... | 0.645556 | Code_Contests_17300 | C | [
"bfs_shortest_path",
"apply_bombs",
"min_steps_to_reach_target",
"main"
] | 4 | [
[
"min_steps_to_reach_target",
"apply_bombs"
],
[
"min_steps_to_reach_target",
"bfs_shortest_path"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | cee98ba8a7275298958d34758a8154dd1b8f1e98 | 60b2a4d2d30d902a4173563b7c2c1b1d178d63ff | |||
v1.0 | complete | Code_Contests | Code_Contests_17523_C | def is_palindrome(word):
"""
Checks if a given word is a palindrome.
Parameters
----------
word : str
The word to check.
Returns
-------
str
"YES" if the word is a palindrome, "NO" otherwise.
"""
def check_palindromes(words):
"""
Checks each word in the... | def is_palindrome(word):
"""
Checks if a given word is a palindrome.
Parameters
----------
word : str
The word to check.
Returns
-------
str
"YES" if the word is a palindrome, "NO" otherwise.
"""
if word == word[::-1]:
return "YES"
else:
... | from solution import check_palindromes
def test_check_palindromes():
assert check_palindromes(["madam", "test", "level", "world"]) == ["YES", "NO", "YES", "NO"]
assert check_palindromes(["abba", "racecar", "apple"]) == ["YES", "YES", "NO"]
assert check_palindromes(["", "a", "radar", "refer", "step on no pe... | [
{
"docstring": "Checks if a given word is a palindrome.\n\nParameters\n----------\nword : str\n The word to check.\n\nReturns\n-------\nstr\n \"YES\" if the word is a palindrome, \"NO\" otherwise.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"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 is_palindrome(word):\n \"\"\"\n Returns 'YES' if the word is a palindrome, otherwise 'NO'.\n \"\"\"\n return \"YES\" if word == word[::-1] ... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nYou are given a list of words, and your task is to identify if each word is a palindrome. \n\nA palindrome is a word that reads the same forwards as backwards (e.g., \"madam\", \"racecar\").\n\nConstraints\n\nThe input satisfies the following conditions:\n\n* $ 1 \\le N \\lt 10^3... | 0.815992 | Code_Contests_17523 | C | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f540bc794792d3d077b124bc72423716ab2921f4 | 021d3a135013d82496d2111ddde5c3b02919f3c1 | |||
v1.0 | complete | Code_Contests | Code_Contests_17698_C | def mirror_matrix(n: int) -> list:
"""
Creates an n x n Mirror Matrix with specified properties.
Parameters:
n (int): Size of the matrix (1 ≤ n ≤ 100)
Returns:
list: 2D list representing the n x n Mirror Matrix
>>> mirror_matrix(3)
[[1, 1, 1], [1, 2, 1], [1, 1, 1]]
>>> mirror_matr... | def mirror_matrix(n):
"""
Creates an n x n Mirror Matrix with specified properties.
Parameters:
n (int): Size of the matrix (1 ≤ n ≤ 100)
Returns:
list: 2D list representing the n x n Mirror Matrix
"""
matrix = [[0]*n for _ in range(n)]
num = 1
for layer in range((n + 1) /... | from solution import mirror_matrix, mirror_matrix_str
def test_mirror_matrix_1():
assert mirror_matrix(1) == [
[1]
]
def test_mirror_matrix_2():
assert mirror_matrix(2) == [
[1, 1],
[1, 1]
]
def test_mirror_matrix_3():
result = mirror_matrix(3)
expected = [
[1,... | [
{
"docstring": "Creates an n x n Mirror Matrix with specified properties.\n\nParameters:\nn (int): Size of the matrix (1 ≤ n ≤ 100)\n\nReturns:\nlist: 2D list representing the n x n Mirror Matrix",
"function_declaration": "def mirror_matrix(n):",
"function_name": "mirror_matrix",
"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 generate_mirror_matrix(n):\n \"\"\"\n Generates an n x n Mirror Matrix with given properties.\n \n Args:\n n: int: the size of the matri... | trial_gpt4o_1 | {
"original_instruction": "Charlotte is working on a project involving a unique type of matrix called a \"Mirror Matrix\". A Mirror Matrix has an interesting property that it contains mirrored submatrices. Given an integer n, your task is to create an n x n matrix in such a way that the diagonals from the top-left to... | 0.538771 | Code_Contests_17698 | C | [
"mirror_matrix",
"mirror_matrix_str"
] | 2 | [
[
"mirror_matrix_str",
"mirror_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f148d77af4f25c35da99984c8b6ac08ba2b4903d | 915c38b330b939e6726d47c7cb6385599d2c858c | |||
v1.0 | complete | Code_Contests | Code_Contests_18461_C | def max_depth_sum(N: int, parents: List[int]) -> int:
""" Determine the sum of the values of nodes that are at the maximum depth of the tree.
>>> max_depth_sum(5, [1, 1, 2, 2])
9
>>> max_depth_sum(8, [1, 2, 2, 4, 4, 5, 5])
15
>>> max_depth_sum(1, [])
1
""" | def max_depth_sum(N, parents):
if N == 1:
return 1
from collections import defaultdict, deque
# Build the tree
tree = defaultdict(list)
for child_index, parent in enumerate(parents, start=2):
tree[parent].append(child_index)
# BFS to find the maximum depth and the sum
queu... | def test_max_depth_sum_single_node():
assert max_depth_sum(1, []) == 1
def test_max_depth_sum_case1():
assert max_depth_sum(5, [1, 1, 2, 2]) == 9
def test_max_depth_sum_case2():
assert max_depth_sum(8, [1, 2, 2, 4, 4, 5, 5]) == 15
def test_max_depth_sum_balanced_tree():
assert max_depth_sum(7, [1, 1,... | [
{
"docstring": null,
"function_declaration": "def max_depth_sum(N, parents):",
"function_name": "max_depth_sum",
"parameter_list": "(N, parents)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_find_max_depth_sum():",
"function_name": "process_input_and_find_ma... | [
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 sum_of_deepest_nodes(N, parents):\n if N == 1:\n return 1\n\n from collections import defaultdict, deque\n\n tree = defaultdict(list)\n... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree rooted at node 1. Each node has a unique integer value between 1 and N (inclusive). The parent of each node is provided, except for the root, which has no parent.\n\nYour task is to determine the sum of the values of nodes that are at the maximum depth of the tre... | 0.551344 | Code_Contests_18461 | C | [
"max_depth_sum",
"process_input_and_find_max_depth_sum"
] | 2 | [
[
"process_input_and_find_max_depth_sum",
"max_depth_sum"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a17bb76bfab289e2c3f1eb37fa6265274c35d8bf | e3c343ee23ba62e2163f14c33e286df67be2ecc1 | |||
v1.0 | complete | Code_Contests | Code_Contests_17659_C | def find_max_rectangle_area(n: int, heights: List[int]) -> int:
"""
You are given an array of integers representing heights of different buildings in a cityscape.
The cityscape can be viewed as a histogram where the width of each bar is 1. You need to find
the maximum rectangular area that can be forme... | def max_histogram_area(heights):
"""
This function returns the maximum rectangular area in a histogram represented
by heights (an array of integers).
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
... | from solution import find_max_rectangle_area
def test_example_1():
assert find_max_rectangle_area(6, [2, 1, 5, 6, 2, 3]) == 10
def test_example_2():
assert find_max_rectangle_area(4, [6, 2, 5, 4]) == 8
def test_example_3():
assert find_max_rectangle_area(5, [5, 4, 3, 2, 1]) == 9
def test_single_building... | [
{
"docstring": "This function returns the maximum rectangular area in a histogram represented\nby heights (an array of integers).",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"fu... | [
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 max_histogram_area(heights):\n \"\"\"\n Find the maximum rectangular area that can be formed in the histogram.\n \n Arguments:\n heights... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of integers representing heights of different buildings in a cityscape. The cityscape can be viewed as a histogram where the width of each bar is 1. You need to find the maximum rectangular area that can be formed in the histogram.\n\nInput\nThe first line contains an... | 0.758383 | Code_Contests_17659 | C | [
"max_histogram_area",
"find_max_rectangle_area"
] | 2 | [
[
"find_max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9cdfcf5d38fdc7f7d58bd919a09cc8c6188d810d | 74656c4293f9337854e1dea532470ca07b7b171e | |||
v1.0 | complete | Code_Contests | Code_Contests_18479_C | def is_prime(num: int) -> bool:
"""
Determine if num is a prime number.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(13) True
>>> is_prime(22) False
"""
def sort_primes_composites(n: int, numbers: List[int]) -> List[int]:
"""
Sort the numbers... | def is_prime(num):
"""
Returns True if num is a prime number, False otherwise.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return Tr... | from solution import is_prime, sort_primes_composites
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(22) == False
def test_sort_primes_composites():
assert sort_primes_composites(8, [3, 5, 8, 13... | [
{
"docstring": "Returns True if num is a prime number, False otherwise.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Sorts the numbers such that all primes come before all composite numbers.\nPrimes and composites a... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return ... | trial_gpt4o_1 | {
"original_instruction": "Given a list of integers, your task is to sort the numbers in such a way that all primes in the list appear before all composite numbers. Within the primes, the numbers should be sorted in increasing order. Within the composite numbers, the numbers should also be sorted in increasing order.... | 0.740508 | Code_Contests_18479 | C | [
"is_prime",
"sort_primes_composites"
] | 2 | [
[
"sort_primes_composites",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 58f982e82df37a56fb68d06fe38b1ab36858fde0 | 3a1f44d7fe0199fb52458f4759a39b8714c8d180 | |||
v1.0 | complete | Code_Contests | Code_Contests_18373_C | def sieve_of_eratosthenes(max_num):
"""
Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.
"""
# Implementation needed
def count_primes_in_range(a, b, primes):
"""
Counts the number of primes within the range [a, b].
"""
# Implementation needed
d... | def sieve_of_eratosthenes(max_num):
"""
Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not primes
p = 2
while (p * p <= max_num):
if (is_prime[p] == True... | import pytest
from solution import num_of_primes_in_ranges
def test_single_range_with_primes():
assert num_of_primes_in_ranges(1, [(1, 10)]) == [4]
def test_single_range_without_primes():
assert num_of_primes_in_ranges(1, [(0, 1)]) == [0]
def test_multiple_ranges():
assert num_of_primes_in_ranges(5, [(1,... | [
{
"docstring": "Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Counts the number of primes w... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.\n \"\"\"... | trial_gpt4o_0 | {
"original_instruction": "Sasha is a passionate coder who loves solving mathematical puzzles. Recently, she came across a fascinating problem involving prime numbers and she needs your help to solve it.\n\nA number is considered to be prime if it is greater than 1 and has no divisors other than 1 and itself. Sasha d... | 0.673372 | Code_Contests_18373 | C | [
"sieve_of_eratosthenes",
"count_primes_in_range",
"num_of_primes_in_ranges"
] | 3 | [
[
"num_of_primes_in_ranges",
"count_primes_in_range"
],
[
"num_of_primes_in_ranges",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 97814ce0c122b155fe5052b1de26ee569c42dfa3 | f83e7a9687b2f551856a2b475ef5f06de243d365 | |||
v1.0 | complete | Code_Contests | Code_Contests_18386_C | from typing import List
def determine_rank(total_score: int) -> str:
""" Determine the performance rank based on the total score.
>>> determine_rank(1000)
'Novice'
>>> determine_rank(500)
'Novice'
>>> determine_rank(1500)
'Intermediate'
>>> determine_rank(5000)
'Intermediate'
>>... | def determine_rank(total_score):
"""
Determine the performance rank based on the total score.
"""
if total_score <= 1000:
return "Novice"
elif total_score <= 5000:
return "Intermediate"
elif total_score <= 10000:
return "Expert"
else:
return "Master"
def eval... | from solution import determine_rank, evaluate_performance
def test_determine_rank():
assert determine_rank(1000) == "Novice"
assert determine_rank(500) == "Novice"
assert determine_rank(1500) == "Intermediate"
assert determine_rank(5000) == "Intermediate"
assert determine_rank(7000) == "Expert"
... | [
{
"docstring": "Determine the performance rank based on the total score.",
"function_declaration": "def determine_rank(total_score):",
"function_name": "determine_rank",
"parameter_list": "(total_score)"
},
{
"docstring": "Evaluate the performance rank for each player based on their inventor... | [
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 calculate_ranks(T, Q, item_scores, players_inventories):\n \"\"\"\n Given the number of different item types T and number of players Q,\n this... | trial_gpt4o_4 | {
"original_instruction": "In a fantasy role-playing game, players collect various types of items during their adventures. Each item has an assigned score value, and these scores can be used to determine the player's overall strength in the game. Players can collect multiple items of the same type, and the total scor... | 0.643032 | Code_Contests_18386 | C | [
"determine_rank",
"evaluate_performance"
] | 2 | [
[
"evaluate_performance",
"determine_rank"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1c58729ff5df368a2697012df253d6fc5f5148fb | fb198e071a85f894a7472581f93ac218fbb0e590 | |||
v1.0 | complete | Code_Contests | Code_Contests_18465_C | def has_pair_with_perfect_square_product(n: int, elements: List[int]) -> str:
""" Check if there are at least two integers in the list such that their product is a perfect square.
Args:
n (int): The number of elements in the list (1 ≤ n ≤ 1000)
elements (List[int]): List of integers (1 ≤ ai ≤ 1000)
... | import math
from collections import Counter
def has_pair_with_perfect_square_product(n, elements):
def get_prime_factors(num):
""" Returns the prime factorization of a number as a Counter """
factors = Counter()
d = 2
while d**2 <= num:
while (num % d) == 0:
... | from solution import has_pair_with_perfect_square_product
def test_example_1():
assert has_pair_with_perfect_square_product(5, [1, 2, 3, 4, 6]) == "YES"
def test_example_2():
assert has_pair_with_perfect_square_product(4, [2, 3, 5, 7]) == "NO"
def test_single_element():
assert has_pair_with_perfect_squar... | [
{
"docstring": null,
"function_declaration": "def has_pair_with_perfect_square_product(n, elements):",
"function_name": "has_pair_with_perfect_square_product",
"parameter_list": "(n, elements)"
},
{
"docstring": null,
"function_declaration": "def input_handling():",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(x, y):\n while y:\n x, y = y, x % y\n return x\n\ndef is_perfect_square(n):\n root = int(n**0.5)\n return n == root * root\n\nde... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers. Your task is to check if there are at least two integers in the list such that their product is a perfect square. If such a pair exists, print \"YES\"; otherwise, print \"NO\".\n\nInput\n\nThe first line contains a single integer n (1 ≤ n ≤ 1000) — the numb... | 0.656037 | Code_Contests_18465 | C | [
"has_pair_with_perfect_square_product",
"input_handling"
] | 2 | [
[
"input_handling",
"has_pair_with_perfect_square_product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2f834ffb10a6c4f9f7a37e69b94f823125942ee | ac40281122ff7184a98507bdff06a225e829d8dd | |||
v1.0 | complete | Code_Contests | Code_Contests_18111_C | class TreeNode:
def __init__(self, val=0):
self.val = val
self.children = []
def build_tree(n, edges):
nodes = {i: TreeNode() for i in range(1, n+1)}
for u, v in edges:
nodes[u].children.append(nodes[v])
nodes[v].children.append(nodes[u])
return nodes
def balance_tree(r... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.children = []
def build_tree(n, edges):
nodes = {i: TreeNode() for i in range(1, n+1)}
for u, v in edges:
nodes[u].children.append(nodes[v])
nodes[v].children.append(nodes[u])
return nodes
def balance_tree(r... | from solution import min_changes
def test_sample_case_1():
n = 3
edges = [(1, 2), (1, 3)]
colors = [1, 0, 1]
assert min_changes(n, edges, colors) == 1
def test_sample_case_2():
n = 4
edges = [(1, 2), (1, 3), (3, 4)]
colors = [0, 1, 0, 1]
assert min_changes(n, edges, colors) == 1
d... | [] | [
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": "class TreeNode:\n def __init__(self):\n self.black = 0 # Number of black nodes in the subtree\n self.white = 0 # Number of whi... | trial_gpt4o_5 | {
"original_instruction": "You are given a binary tree with n nodes, where each node has a value of either 0 or 1. The two types of nodes represent black (1) or white (0) colors respectively. Your task is to calculate the smallest number of changes required to make the binary tree fully balanced in color distribution... | 0.562779 | Code_Contests_18111 | C | [
"build_tree",
"balance_tree",
"min_changes",
"solve",
"main"
] | 5 | [
[
"min_changes",
"balance_tree"
],
[
"min_changes",
"build_tree"
],
[
"solve",
"min_changes"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 9a408a944ccdd700a3a5c9eca7a66ebccb6626dd | 05aa012e0f758c9e71a2969fdbf66c3317e4fe20 | |||
v1.0 | complete | Code_Contests | Code_Contests_18155_C | def number_with_highest_digit_sum(lst: List[int]) -> int:
""" Given a list of integers, find the number with the highest sum of its digits.
In case of a tie, return the largest number among those with the highest sum of digits.
>>> number_with_highest_digit_sum([123, 456, 789, 987])
987
... | def sum_of_digits(num):
return sum(int(digit) for digit in str(num))
def number_with_highest_digit_sum(lst):
max_digit_sum = -1
result = -1
for num in lst:
current_digit_sum = sum_of_digits(num)
if current_digit_sum > max_digit_sum or (current_digit_sum == max_digit_sum and num > result... | from solution import number_with_highest_digit_sum
def test_example1():
assert number_with_highest_digit_sum([123, 456, 789, 987]) == 987
def test_example2():
assert number_with_highest_digit_sum([111, 333, 222, 444, 555]) == 555
def test_single_element():
assert number_with_highest_digit_sum([100]) == 1... | [
{
"docstring": null,
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def number_with_highest_digit_sum(lst):",
"function_name": "number_with_highest_digit_sum",
"parame... | [
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 sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of the number n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\n\ndef ... | trial_gpt4o_1 | {
"original_instruction": "Given a list of integers, you are required to find the sum of the digits of each number in the list and return the number whose sum of digits is the highest. In case of a tie, return the largest number among those with the highest sum of digits.\n\nConstraints\n\n1 ≤ N ≤ 5000\n\n100 ≤ an el... | 0.654484 | Code_Contests_18155 | C | [
"sum_of_digits",
"number_with_highest_digit_sum"
] | 2 | [
[
"number_with_highest_digit_sum",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f82d54c54c4217a0f00bef3bca997b66c65c6079 | 636a1781e55e0bfb840676c3898524235dfffac5 | |||
v1.0 | complete | Code_Contests | Code_Contests_18877_C | def min_roads_to_connect(n: int, m: int, connections: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of roads to be added to make the delivery network connected.
>>> min_roads_to_connect(3, 1, [(1, 2)])
1
>>> min_roads_to_connect(4, 2, [(1, 2), (2, 3)])
1
>>> min_roads_to_connec... | 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 xroot != yroot:
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > ... | from solution import min_roads_to_connect
def test_min_roads_to_connect_3_1():
assert min_roads_to_connect(3, 1, [(1, 2)]) == 1
def test_min_roads_to_connect_4_2():
assert min_roads_to_connect(4, 2, [(1, 2), (2, 3)]) == 1
def test_min_roads_to_connect_1_0():
assert min_roads_to_connect(1, 0, []) == 0
de... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] != i:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(parent, rank, x, y):\n root... | trial_gpt4o_1 | {
"original_instruction": "A logistics company is tasked with optimizing the delivery routes for its fleet of trucks. The company has a main warehouse and several delivery locations. Each delivery location can be connected to other delivery locations and the main warehouse through direct roads. The company wants to e... | 0.686861 | Code_Contests_18877 | C | [
"find",
"union",
"min_roads_to_connect"
] | 3 | [
[
"min_roads_to_connect",
"find"
],
[
"min_roads_to_connect",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 973bf2b07bbc3b54973a250250346166cbe33906 | 34240fb458778fe9384b12c526f1fb7de1bc96cc | |||
v1.0 | complete | Code_Contests | Code_Contests_18636_C | def element_value(i: int) -> int:
"""
Returns the value of the element at position i based on
whether i is odd or even.
>>> element_value(1) == 1
>>> element_value(2) == -4
>>> element_value(3) == 9
>>> element_value(4) == -16
>>> element_value(5) == 25
"""
pass
def query_sum(l:... | def element_value(i):
"""
Returns the value of the element at position i based on
whether i is odd or even.
"""
if i % 2 == 0:
return -i * i
else:
return i * i
def query_sum(l, r):
"""
Returns the sum of the elements from index l to index r inclusive.
"""
sum = 0... | def test_element_value():
assert element_value(1) == 1
assert element_value(2) == -4
assert element_value(3) == 9
assert element_value(4) == -16
assert element_value(5) == 25
def test_query_sum_single_element():
assert query_sum(1, 1) == 1
assert query_sum(2, 2) == -4
def test_query_sum_mu... | [
{
"docstring": "Returns the value of the element at position i based on\nwhether i is odd or even.",
"function_declaration": "def element_value(i):",
"function_name": "element_value",
"parameter_list": "(i)"
},
{
"docstring": "Returns the sum of the elements from index l to index r inclusive... | [
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 calculate_b_i_sum(l, r):\n \"\"\"\n This function takes two integers l and r,\n and returns the sum of elements in the array defined as:\n ... | trial_gpt4o_7 | {
"original_instruction": "Jessica is working with a large array of size up to 10^9 elements where each element at position i is defined as follows:\n\n- b_i = i^2 if i is odd\n- b_i = -i^2 if i is even\n\nShe has come up with several queries to determine the sum of elements within a specified subarray. Each query co... | 0.691775 | Code_Contests_18636 | C | [
"element_value",
"query_sum",
"solve"
] | 3 | [
[
"query_sum",
"element_value"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | e532a95836a1d0781f87bc409c17ebfb3b9d90b3 | cceec4b73163768faa790f2094d56fa3b58d34b8 | |||
v1.0 | complete | Code_Contests | Code_Contests_18445_C | import pytest
from typing import List, Dict, Tuple
def calculate_accuracy(purchased: List[int], recommended: List[int]) -> float:
"""
Calculates the accuracy of the recommended products against the purchased products.
Accuracy is the ratio of correctly recommended products to the total number of purchased ... | def calculate_accuracy(purchased, recommended):
"""
Calculates the accuracy of the recommended products against the purchased products.
Accuracy is the ratio of correctly recommended products to the total number of purchased products.
"""
purchased_set = set(purchased)
recommended_set = set(reco... | import pytest
def test_calculate_accuracy():
assert calculate_accuracy([2, 3], [2]) == 0.5
assert calculate_accuracy([3, 5], [3, 4]) == 0.5
assert calculate_accuracy([4], [4, 5]) == 1.0
assert calculate_accuracy([1, 3, 5], [1, 3]) == 2 / 3
assert calculate_accuracy([], []) == 1.0
def test_overall_... | [
{
"docstring": "Calculates the accuracy of the recommended products against the purchased products.\nAccuracy is the ratio of correctly recommended products to the total number of purchased products.",
"function_declaration": "def calculate_accuracy(purchased, recommended):",
"function_name": "calculate... | [
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 calculate_accuracy(test_cases):\n results = []\n for t in range(len(test_cases)):\n N, M, K, purchases, recommendations = test_cases[t]\n ... | trial_gpt4o_2 | {
"original_instruction": "You are working on an e-commerce website, and you have been assigned to optimize the new recommendation algorithm. The algorithm suggests products based on purchase history and browsing data. To measure its performance, you will run a series of tests to see how well the algorithm predicts p... | 0.618134 | Code_Contests_18445 | C | [
"calculate_accuracy",
"overall_accuracy"
] | 2 | [
[
"overall_accuracy",
"calculate_accuracy"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b240dc0f8db3aa98619f8511bc62c984f7e51de7 | cc89f89c9de1563f4f2fbc6633e6849f7c96b41d | |||
v1.0 | complete | Code_Contests | Code_Contests_17605_C | from typing import List, Tuple
def find(parent, u):
"""Helper function to find the root of the component containing u, with path compression."""
pass
def union(parent, rank, u, v):
"""Union by rank of the components containing u and v."""
pass
def min_operations_to_connect_servers(t: int, test_cases:... | def find(parent, u):
"""Find the root of the component containing u with path compression."""
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
"""Union by rank of the components containing u and v."""
root_u = find(parent, u)
root_v ... | from solution import min_operations_to_connect_servers, parse_input
def test_no_operations_needed():
t, test_cases = parse_input("1\n4 3\n1 2\n2 3\n3 4")
results = min_operations_to_connect_servers(t, test_cases)
assert results == [(0, [])]
def test_add_operations_needed():
t, test_cases = parse_input... | [
{
"docstring": "Find the root of the component containing u with path compression.",
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": "Union by rank of the components containing u and v.",
"function_declaration": "... | [
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 minimum_operations(t, test_cases):\n \"\"\"\n Determines the minimum number of operations to achieve optimal connectivity for given test cases.\n... | trial_gpt4o_3 | {
"original_instruction": "Polycarpus is working on optimizing the performance of his network of servers. He has constructed a data center consisting of n servers, identified by unique integers from 1 to n. Each server has multiple connections to other servers, allowing data to flow between them. However, Polycarpus ... | 0.587614 | Code_Contests_17605 | C | [
"find",
"union",
"min_operations_to_connect_servers",
"parse_input"
] | 4 | [
[
"min_operations_to_connect_servers",
"find"
],
[
"min_operations_to_connect_servers",
"union"
],
[
"union",
"find"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 458948f9e741552ff5cfd10438b13ea2141eaa8d | 185ee3422a75a03a2669d9f95501b1a162b6948c | |||
v1.0 | complete | Code_Contests | Code_Contests_18770_C | def max_area_of_equal_height(grid):
"""
You are given a grid of size n x m where each cell contains a non-negative integer representing the height of that cell. You need to find the maximum area of a rectangle that can be formed with cells of equal height.
Input
The first line contains two integers... | def max_area_of_equal_height(grid):
if not grid:
return 0
n = len(grid)
m = len(grid[0])
max_area = 0
for height in range(101):
heights = [[0] * m for _ in range(n)]
for i in range(n):
for j in range(m):
if grid[i][j] == height:
... | from solution import max_area_of_equal_height
def test_max_area_example1():
grid = [
[1, 1, 1, 2],
[2, 1, 1, 1],
[1, 1, 1, 1]
]
assert max_area_of_equal_height(grid) == 6
def test_max_area_example2():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
as... | [
{
"docstring": null,
"function_declaration": "def max_area_of_equal_height(grid):",
"function_name": "max_area_of_equal_height",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_equal_height_area(grid):\n if not grid or not grid[0]:\n return 0\n \n n = len(grid)\n m = len(grid[0])\n \n max_area = 0\... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid of size n x m where each cell contains a non-negative integer representing the height of that cell. You need to find the maximum area of a rectangle that can be formed with cells of equal height.\n\nInput\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 100) ... | 0.731456 | Code_Contests_18770 | C | [
"max_area_of_equal_height",
"largest_rectangle_area"
] | 2 | [
[
"max_area_of_equal_height",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01a0376daec9db4734fa932ebc595e0183b0ff5c | 7496b91fe58dfb5d408eec4bb45f744b56cc663b | |||
v1.0 | complete | Code_Contests | Code_Contests_18580_C | from typing import List
def optimal_meeting_time(m: int, n: int, attendees_schedules: List[str]) -> str:
"""
Determines the optimal start time for a meeting to minimize the number of conflicting meetings.
Args:
m (int): Duration of the meeting in minutes.
n (int): Number of attendees.
atte... | from datetime import datetime, timedelta
def parse_time_interval(interval):
"""
Parses a single time interval string into a tuple of datetime objects.
"""
start_str, end_str = interval.split('-')
start_time = datetime.strptime(start_str, "%H:%M")
end_time = datetime.strptime(end_str, "%H:%M")
... | from solution import optimal_meeting_time
def test_example_1():
m = 60
n = 3
schedules = [
"09:00-10:00 14:00-15:30",
"11:00-12:00 13:00-14:00",
"10:00-11:00 15:00-16:00"
]
assert optimal_meeting_time(m, n, schedules) == "12:00"
def test_example_2():
m = 30
n = 2
... | [
{
"docstring": "Parses a single time interval string into a tuple of datetime objects.",
"function_declaration": "def parse_time_interval(interval):",
"function_name": "parse_time_interval",
"parameter_list": "(interval)"
},
{
"docstring": "Parses a schedule string into a list of time interv... | [
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": "from datetime import datetime, timedelta\n\ndef parse_time_interval(interval):\n \"\"\"\n Helper function to parse a time in... | trial_gpt4o_2 | {
"original_instruction": "A company organizes a daily meeting for its employees. The meeting can start at any time between 9:00 AM and 5:00 PM, and the duration of the meeting is fixed. The meeting organizer prefers a time slot when a minimum number of attendees are already in other meetings to maximize participatio... | 0.587318 | Code_Contests_18580 | C | [
"parse_time_interval",
"parse_schedule",
"find_optimal_meeting_time",
"optimal_meeting_time"
] | 4 | [
[
"find_optimal_meeting_time",
"parse_schedule"
],
[
"optimal_meeting_time",
"find_optimal_meeting_time"
],
[
"parse_schedule",
"parse_time_interval"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 76a199e6ca7557f45ccdc91d046c29e5efa6128d | f7bde5cea09d9ca3825006eba65aef32d947daac | |||
v1.0 | complete | Code_Contests | Code_Contests_19290_C | def kth_almost_prime(k: int) -> int:
"""
Find the k-th almost prime number.
An almost prime number is defined as a number that has exactly two distinct prime factors.
>>> kth_almost_prime(1)
6
>>> kth_almost_prime(3)
15
""" | def sieve_of_eratosthenes(limit):
primes = []
is_prime = [True] * (limit + 1)
is_prime[0], is_prime[1] = False, False
for num in range(2, limit + 1):
if is_prime[num]:
primes.append(num)
for multiple in range(num * num, limit + 1, num):
is_prime[multiple]... | from solution import kth_almost_prime
def test_kth_almost_prime():
assert kth_almost_prime(1) == 6
assert kth_almost_prime(2) == 10
assert kth_almost_prime(3) == 14
assert kth_almost_prime(4) == 15
assert kth_almost_prime(5) == 21
assert kth_almost_prime(6) == 22
assert kth_almost_prime(7) ... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Generate almost prime numbers until the k-th almost prime number is found.",
"function_declaration": "def generate_al... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import count\nfrom math import isqrt\n\ndef is_almost_prime(n):\n prime_factors = 0\n for i in range(2, isqrt(n) + 1):\n if n %... | trial_gpt4o_6 | {
"original_instruction": "Lisa and Bob both have an interest in studying number theory. One day, they stumbled upon a fascinating topic called \"Almost Prime Numbers.\" An almost prime number is defined as a number that has exactly two distinct prime factors. For example, 6=2*3 and 10=2*5 are almost prime numbers.\n... | 0.572102 | Code_Contests_19290 | C | [
"sieve_of_eratosthenes",
"generate_almost_prime_numbers",
"kth_almost_prime"
] | 3 | [
[
"generate_almost_prime_numbers",
"sieve_of_eratosthenes"
],
[
"kth_almost_prime",
"generate_almost_prime_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9ebc09b552de8509117bab735a8d18874fc590d3 | 5fe73bc294742f243db453e144166a71a1af8d71 | |||
v1.0 | complete | Code_Contests | Code_Contests_17405_C | from typing import List, Union
def sum_level_query(tree: List[int], level: int) -> int:
"""
Calculates the sum of the values of all nodes at the specified level.
"""
pass
def change_value(tree: List[int], index: int, value: int) -> None:
"""
Changes the value of the specified node in the tree.... | def sum_level_query(tree, level):
"""
Calculates the sum of the values of all nodes at the specified level.
"""
level_sum = 0
current_level = 1
start_index = 0
while start_index < len(tree):
end_index = start_index + 2**(current_level - 1)
if current_level == level:
... | import pytest
from solution import sum_level_query, change_value, process_queries
def test_sum_level_query():
assert sum_level_query([3, 5, -1, 6, -1, -1, 9], 1) == 3
assert sum_level_query([3, 5, -1, 6, -1, -1, 9], 2) == 5
assert sum_level_query([3, 5, -1, 6, -1, -1, 9], 3) == 15
def test_change_value():... | [
{
"docstring": "Calculates the sum of the values of all nodes at the specified level.",
"function_declaration": "def sum_level_query(tree, level):",
"function_name": "sum_level_query",
"parameter_list": "(tree, level)"
},
{
"docstring": "Changes the value of the specified node in the tree.",... | [
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 parse_tree_and_queries(input_list):\n \"\"\"\n Parse the input list and extract tree values and queries.\n \"\"\"\n t = int(input_list[0])\... | trial_gpt4o_3 | {
"original_instruction": "You are given a binary tree with n nodes, where each node has a value and a level. The root node has level 1, its children have level 2, and so on. You need to answer queries about the sum of values at different levels and changing the values of nodes.\n\nThe binary tree is represented as a... | 0.495032 | Code_Contests_17405 | C | [
"sum_level_query",
"change_value",
"process_queries"
] | 3 | [
[
"process_queries",
"change_value"
],
[
"process_queries",
"sum_level_query"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | c9465267cf1b6ec00a1b2021166ba099e6676dd7 | 6ccb6fed43f4a51a5af93083e78b8f4a2cc380cc | |||
v1.0 | complete | Code_Contests | Code_Contests_17820_C | def is_palindrome(word: str) -> bool:
"""
Returns True if word is a palindrome, otherwise False.
>>> is_palindrome("level") True
>>> is_palindrome("racecar") True
>>> is_palindrome("hello") False
>>> is_palindrome("") True
>>> is_palindrome("a") True
>>> is_palindrome("ab") False
>>>... | def is_palindrome(word):
"""
Returns True if word is a palindrome, otherwise False.
"""
return word == word[::-1]
def has_palindrome_sentence(sentence):
"""
Checks if the sentence has at least one word that is a palindrome.
Returns "Yes" if there's at least one palindrome word, otherwise "N... | from solution import is_palindrome, has_palindrome_sentence, check_palindromes_in_sentences, main
def test_is_palindrome():
assert is_palindrome("level") == True
assert is_palindrome("racecar") == True
assert is_palindrome("hello") == False
assert is_palindrome("") == True
assert is_palindrome("a")... | [
{
"docstring": "Returns True if word is a palindrome, otherwise False.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Checks if the sentence has at least one word that is a palindrome.\nReturns \"Yes\" if ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_palindrome(sentence):\n \"\"\"\n Determine if any of the individual words within a given sentence is a palindrome.\n \n Parameters:\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of sentences. You need to determine if any of the individual words within a given sentence is a palindrome. A palindrome is a word that reads the same backward as forward.\n\nInput:\nThe first line of the input contains an integer T, the number of sentences. The followi... | 0.808215 | Code_Contests_17820 | C | [
"is_palindrome",
"has_palindrome_sentence",
"check_palindromes_in_sentences",
"main"
] | 4 | [
[
"check_palindromes_in_sentences",
"has_palindrome_sentence"
],
[
"has_palindrome_sentence",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4ae92c32dae78a759516e1b8537a35896d5ea3b0 | f78eb891b20df1ea5c863c6a706a3fd675ca2519 | |||
v1.0 | complete | Code_Contests | Code_Contests_19038_C | def count_distinct_palindromic_substrings(s: str) -> int:
""" Returns the number of distinct palindromic substrings in the string `s`.
>>> count_distinct_palindromic_substrings("abba") == 4
>>> count_distinct_palindromic_substrings("abc") == 3
>>> count_distinct_palindromic_substrings("aaa") == 3
... | def count_distinct_palindromic_substrings(s):
"""
Returns the number of distinct palindromic substrings in the string `s`.
"""
unique_palindromes = set()
for i in range(len(s)):
# Find all odd-length palindromes centered at s[i]
expand_around_center(s, i, i, unique_palindromes)
... | from solution import count_distinct_palindromic_substrings, distinct_palindromic_substrings
def test_single_character_string():
assert count_distinct_palindromic_substrings("a") == 1
def test_distinct_characters():
assert count_distinct_palindromic_substrings("abc") == 3
def test_repetitive_characters():
... | [
{
"docstring": "Returns the number of distinct palindromic substrings in the string `s`.",
"function_declaration": "def count_distinct_palindromic_substrings(s):",
"function_name": "count_distinct_palindromic_substrings",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declarat... | [
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_unique_palindromic_substrings(s):\n \"\"\"\n Returns the number of unique palindromic substrings in the string s.\n \"\"\"\n n = len(... | trial_gpt4o_2 | {
"original_instruction": "### Sally and Her Favorite Substrings\n\nSally loves exploring different properties of strings, and she is currently fascinated by palindromic substrings. A palindromic string is one that reads the same forwards and backwards. Sally's favorite activity is to find all the unique palindromic ... | 0.720341 | Code_Contests_19038 | C | [
"count_distinct_palindromic_substrings",
"expand_around_center",
"distinct_palindromic_substrings"
] | 3 | [
[
"count_distinct_palindromic_substrings",
"expand_around_center"
],
[
"distinct_palindromic_substrings",
"count_distinct_palindromic_substrings"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8d5a1450f1beb4d0af91ae4878051242a872d0c3 | c1560abd14d06a1a363aadc87deee94a2402fc14 | |||
v1.0 | complete | Code_Contests | Code_Contests_18464_C | from typing import List, Tuple
def calculate_grade(average: float) -> str:
""" Determine the letter grade based on the average score.
>>> calculate_grade(95)
'A'
>>> calculate_grade(85)
'B'
>>> calculate_grade(75)
'C'
>>> calculate_grade(65)
'D'
>>> calculate_grade(55)
'F'
... | def calculate_grade(average):
if average >= 90:
return 'A'
elif average >= 80:
return 'B'
elif average >= 70:
return 'C'
elif average >= 60:
return 'D'
else:
return 'F'
def process_student_grades(N, student_info):
results = []
for info in student_info... | from solution import process_student_grades, calculate_grade
def test_calculate_grade():
assert calculate_grade(95) == 'A'
assert calculate_grade(85) == 'B'
assert calculate_grade(75) == 'C'
assert calculate_grade(65) == 'D'
assert calculate_grade(55) == 'F'
def test_process_student_grades():
... | [
{
"docstring": null,
"function_declaration": "def calculate_grade(average):",
"function_name": "calculate_grade",
"parameter_list": "(average)"
},
{
"docstring": null,
"function_declaration": "def process_student_grades(N, student_info):",
"function_name": "process_student_grades",
... | [
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 calculate_grades(num_students, students_info):\n \"\"\"\n Calculate and return each student's average grade and letter grade based on given crite... | trial_gpt4o_1 | {
"original_instruction": "Write a program that reads an integer N, representing the number of students, followed by N sets of student information. Each set consists of a student's name, followed by three floats representing their grades in three subjects. The program should calculate the average grade for each stude... | 0.730135 | Code_Contests_18464 | C | [
"calculate_grade",
"process_student_grades"
] | 2 | [
[
"process_student_grades",
"calculate_grade"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b5993a0f8719f80758bb5d6946760548c5f5d93 | 51752bdb35e1ef324638c74697813ca280f61229 | |||
v1.0 | complete | Code_Contests | Code_Contests_19080_C | def is_palindrome(n: int) -> bool:
""" Returns whether a number n is a palindrome.
>>> is_palindrome(1) == True
>>> is_palindrome(121) == True
>>> is_palindrome(123) == False
>>> is_palindrome(101) == True
>>> is_palindrome(10) == False
"""
def count_palindromic_numbers_in_range(l: int, r: ... | def is_palindrome(n):
"""
Returns whether a number n is a palindrome.
"""
return str(n) == str(n)[::-1]
def count_palindromic_numbers_in_range(l, r):
"""
Returns the count of palindromic numbers in the range [l, r].
"""
count = 0
for number in range(l, r + 1):
if is_palindro... | from solution import is_palindrome, count_palindromic_numbers_in_range, process_palindromic_queries
def test_is_palindrome():
assert is_palindrome(1) == True
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(101) == True
assert is_palindrome(10) == False
def... | [
{
"docstring": "Returns whether a number n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of palindromic numbers in the range [l, r].",
"function_declaration": "def count_p... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic(n):\n \"\"\"\n Check if a number is palindromic.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromic_numbers(L... | trial_gpt4o_7 | {
"original_instruction": "Andria loves palindromic numbers. She gets fascinated when she reads numbers that look the same when read both from left to right and right to left. One day, she decided to find all the palindromic numbers in a given range. \n\nA number is called palindromic if it remains the same when its ... | 0.717478 | Code_Contests_19080 | C | [
"is_palindrome",
"count_palindromic_numbers_in_range",
"process_palindromic_queries"
] | 3 | [
[
"count_palindromic_numbers_in_range",
"is_palindrome"
],
[
"process_palindromic_queries",
"count_palindromic_numbers_in_range"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e05066df03ba1f2893763d63471cd23923157427 | 0ab1997d019e6f22a1f976a15305f5f0379993bf | |||
v1.0 | complete | Code_Contests | Code_Contests_19133_C | def preprocess_array(arr):
"""
Precompute the prefix sums for the given array.
"""
N = len(arr)
prefix_sums = [0] * (N + 1)
for i in range(N):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def query_sum(prefix_sums, L, R):
"""
Calculate the sum of elements ... | def preprocess_array(arr):
"""
Precompute the prefix sums for the given array.
"""
N = len(arr)
prefix_sums = [0] * (N + 1)
for i in range(N):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def query_sum(prefix_sums, L, R):
"""
Calculate the sum of elements ... | from solution import preprocess_array, query_sum, solve
def test_preprocess_array():
arr = [1, 2, 3, 4, 5]
assert preprocess_array(arr) == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert query_sum(prefix_sums, 1, 3) == 6
assert query_sum(prefix_sums, 2, 4) == 9... | [
{
"docstring": "Precompute the prefix sums for the given array.",
"function_declaration": "def preprocess_array(arr):",
"function_name": "preprocess_array",
"parameter_list": "(arr)"
},
{
"docstring": "Calculate the sum of elements from L to R using the prefix sums.",
"function_declarati... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_prefix_sums(arr):\n \"\"\"\n This function calculates the prefix sums for the input array.\n :param arr: List of integers represent... | trial_gpt4o_1 | {
"original_instruction": "You are given an integer array and a set of queries, each query asks you to find the sum of all the integer elements in a specified subarray. Your task is to answer each query efficiently.\n\nInput\nThe first line of the input contains two integers, N and Q, where N is the number of element... | 0.629797 | Code_Contests_19133 | C | [
"preprocess_array",
"query_sum",
"solve"
] | 3 | [
[
"solve",
"preprocess_array"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 42d2f626199f4a71eba9bce251ab03385833dcee | e7886556a4fa2b24be6e9c2731cb4b207f1faa91 | |||
v1.0 | complete | Code_Contests | Code_Contests_18987_C | from typing import List, Tuple
def lcm(a: int, b: int) -> int:
"""
Helper function to find the least common multiple (LCM) of two numbers.
"""
pass
def find_min_time_to_sync(cycle_times: List[int]) -> int:
"""
Given a list of traffic light cycle times, returns the smallest positive time durati... | import math
from functools import reduce
def lcm(a, b):
"""
Helper function to find the least common multiple (LCM) of two numbers.
"""
return abs(a*b) // math.gcd(a, b)
def find_min_time_to_sync(cycle_times):
"""
Given a list of traffic light cycle times, returns the smallest positive time du... | from solution import process_traffic_lights, find_min_time_to_sync
def test_find_min_time_to_sync():
assert find_min_time_to_sync([3, 4, 6]) == 12
assert find_min_time_to_sync([2, 3, 5, 8]) == 120
assert find_min_time_to_sync([1, 1, 1]) == 1
assert find_min_time_to_sync([7, 5, 3]) == 105
def test_proc... | [
{
"docstring": "Helper function to find the least common multiple (LCM) of two numbers.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Given a list of traffic light cycle times, returns the smallest positive time duration\naf... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n return a * b // math.gcd(a, b)\n\ndef find_min_time_to_green_sync(n, cycles):\n return ... | trial_gpt4o_2 | {
"original_instruction": "A city has developed a new system to manage its traffic lights in order to minimize the total waiting time at intersections. Each traffic light has a fixed cycle time, which is the total duration for the light to complete one full cycle of green, yellow, and red lights. The city wants to sy... | 0.528572 | Code_Contests_18987 | C | [
"lcm",
"find_min_time_to_sync",
"process_traffic_lights"
] | 3 | [
[
"find_min_time_to_sync",
"lcm"
],
[
"process_traffic_lights",
"find_min_time_to_sync"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c9f850d09215fcbb8edaf7f96841c33e7d466c72 | 9e8f99804ba7537b60e5ae329107e413b6fe7c26 | |||
v1.0 | complete | Code_Contests | Code_Contests_19347_C | from typing import List
def get_primes_up_to(n: int) -> List[int]:
"""
Utility function that returns a list of prime numbers up to given number n.
Uses the Sieve of Eratosthenes algorithm.
"""
pass
def f(x: int, primes: List[int]) -> int:
"""
Transformation function that returns the smalle... | def get_primes_up_to(n):
"""
Utility function that returns a list of prime numbers up to given number n.
Uses the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if is_prime[p]:
for i in range(p * p, n + 1, p):
is... | from solution import get_primes_up_to, transform_array
def test_primes_up_to_2():
assert get_primes_up_to(2) == [2]
def test_primes_up_to_10():
assert get_primes_up_to(10) == [2, 3, 5, 7]
def test_primes_up_to_30():
assert get_primes_up_to(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_transform_s... | [
{
"docstring": "Utility function that returns a list of prime numbers up to given number n.\nUses the Sieve of Eratosthenes algorithm.",
"function_declaration": "def get_primes_up_to(n):",
"function_name": "get_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": "Transformation function... | [
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(limit):\n sieve = [True] * (limit + 1)\n p = 2\n while (p * p <= limit):\n if (sieve[p] == True):\n fo... | trial_gpt4o_2 | {
"original_instruction": "Background:\nRahul loves prime numbers and he recently found a unique way to transform an array using prime numbers. Rahul takes a list of n integers and applies a transformation function f(x) that takes an integer x and returns the smallest prime number which is greater than or equal to x.... | 0.746859 | Code_Contests_19347 | C | [
"get_primes_up_to",
"f",
"transform_array"
] | 3 | [
[
"transform_array",
"f"
],
[
"transform_array",
"get_primes_up_to"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 680642ce888065cb85bf09f03f59b84dd83b05fd | aa68329bfa6316cc657451840925d4b14079fa6b | |||
v1.0 | complete | Code_Contests | Code_Contests_19383_C | def number_of_articulation_points(n: int, m: int, edges: List[Tuple[int, int]]) -> int:
"""
Determines the number of articulation points in the network.
:param n: Number of computers (nodes).
:param m: Number of direct cables (edges).
:param edges: List of tuples representing the direct cables betw... | def find_articulation_points(n, edges):
from collections import defaultdict
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
disc = [-1] * (n + 1)
low = [-1] * (n + 1)
parent = [-1] * (n + 1)
articulation_points_set = set()
time = [0]
... | from solution import number_of_articulation_points
def test_example_case():
assert number_of_articulation_points(5, 5, [(1, 2), (1, 3), (3, 4), (3, 5), (4, 5)]) == 2
def test_no_articulation_points():
assert number_of_articulation_points(3, 3, [(1, 2), (2, 3), (3, 1)]) == 0
def test_single_articulation_point... | [
{
"docstring": null,
"function_declaration": "def find_articulation_points(n, edges):",
"function_name": "find_articulation_points",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def number_of_articulation_points(n, m, edges):",
"function_name": "num... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_articulation_points(n, m, edges):\n from collections import defaultdict\n\n def dfs(v, visited, disc, low, parent, articulation_points):\n ... | trial_gpt4o_1 | {
"original_instruction": "A company has a network of computers connected by direct cables. Each direct cable connects exactly two computers. The company wants to monitor the network's stability by ensuring there is no single point of failure. To achieve this, they need to find the minimum number of computers that, w... | 0.52076 | Code_Contests_19383 | C | [
"find_articulation_points",
"number_of_articulation_points"
] | 2 | [
[
"number_of_articulation_points",
"find_articulation_points"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7d1e1edf7e1a57f59de3ff0d38c90c0a65a35922 | 054029074e68c4f73c47a3683c7c28d9c86aa82d | |||
v1.0 | complete | Code_Contests | Code_Contests_19222_C | def check_magic_square(N: int, matrix: List[List[int]]) -> str:
"""
Determines whether a given N x N matrix is a magic square.
Parameters:
N (int): Size of the matrix.
matrix (list of lists of int): The N x N matrix.
Returns:
str: "MAGIC" if the matrix is a magic square, "NOT MAGIC... | def is_magic_square(matrix):
N = len(matrix)
sum_diagonal1 = sum([matrix[i][i] for i in range(N)])
sum_diagonal2 = sum([matrix[i][N - i - 1] for i in range(N)])
if sum_diagonal1 != sum_diagonal2:
return "NOT MAGIC"
sum_row = sum(matrix[0])
for i in range(N):
if sum... | from solution import check_magic_square
def test_magic_square_3x3():
matrix = [
[2, 7, 6],
[9, 5, 1],
[4, 3, 8]
]
assert check_magic_square(3, matrix) == "MAGIC"
def test_not_magic_square_3x3():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert... | [
{
"docstring": null,
"function_declaration": "def is_magic_square(matrix):",
"function_name": "is_magic_square",
"parameter_list": "(matrix)"
},
{
"docstring": "Determines whether a given N x N matrix is a magic square.\n\nParameters:\nN (int): Size of the matrix.\nmatrix (list of lists of i... | [
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_magic_square(matrix):\n \"\"\"\n Determines if the given matrix is a magic square.\n :param matrix: List of lists representing the NxN matr... | trial_gpt4o_1 | {
"original_instruction": "Given a matrix of size N x N, determine if it is a magic square. A magic square is a grid of numbers where the sum of numbers in each row, each column, and both main diagonals are the same.\n\n### Constraints\n\n* 1 ≤ N ≤ 50\n* Each element in the matrix is an integer between -100 and 100.\... | 0.706343 | Code_Contests_19222 | C | [
"is_magic_square",
"check_magic_square"
] | 2 | [
[
"check_magic_square",
"is_magic_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 683b07938348dc820adbe74c27d8c0119a8dfab3 | 0844ce419a10fa266740685a5eb53434cc0a1b9c | |||
v1.0 | complete | Code_Contests | Code_Contests_18502_C | from typing import List, Tuple
def reachable_nodes(n: int, m: int, edges: List[Tuple[int, int, int]], q: int, queries: List[Tuple[int, int]], threshold: int) -> List[int]:
"""
You are given a simple undirected graph with n nodes and m edges. Each edge has an associated weight.
You are also given q querie... | def create_adjacency_list(n, edges):
adj = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
adj[u].append((v, w))
adj[v].append((u, w))
return adj
def dfs(adj, u, k, threshold, seen=set()):
if k == 0:
return 1
count = 0
seen.add(u)
for v, w in adj[u]:
if ... | from solution import reachable_nodes
def test_reachable_nodes_example():
n = 4
m = 4
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 6)
]
q = 3
queries = [
(1, 2),
(3, 1),
(4, 0)
]
threshold = 6
assert reachable_nodes(n, m, e... | [
{
"docstring": null,
"function_declaration": "def create_adjacency_list(n, edges):",
"function_name": "create_adjacency_list",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def dfs(adj, u, k, threshold, seen=set()):",
"function_name": "dfs",
"par... | [
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.125 | {
"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 process_graph_input(n, m, edges):\n graph = defaultdict(list)\n for u, v, w in edges:\n grap... | trial_gpt4o_6 | {
"original_instruction": "You are given a simple undirected graph with n nodes and m edges. Each edge has an associated weight. You are also given q queries, where each query consists of two integers u and k. For each query, you need to find the number of nodes that are reachable from node u with a path consisting o... | 0.693654 | Code_Contests_18502 | C | [
"create_adjacency_list",
"dfs",
"reachable_nodes"
] | 3 | [
[
"reachable_nodes",
"create_adjacency_list"
],
[
"reachable_nodes",
"dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7639d2b19c68149e75ab461aeca8cb760b92a52c | 1ceac606c7db5d14f6045a99334580d24f560991 | |||
v1.0 | complete | Code_Contests | Code_Contests_19333_C | def main(input_data):
""" Given a set of points, find the vertices of the convex hull that encloses all the points.
>>> input_data = '''
... 5
... 1.0 1.0
... 2.0 5.0
... 3.0 3.0
... 5.0 3.0
... 3.5 1.0
... 0'''
>>> print(main(input_data))
1.00000 1.00000
3.50000 1.00000
... | def cross_product(o, a, b):
""" Returns the cross product of vectors o->a and o->b.
Positive if b is to the left of a -> o,
negative if b is to the right of a -> o,
0 if they are collinear.
"""
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
def convex_hull(po... | import pytest
from solution import main
def test_case_1():
input_data = """
5
1.0 1.0
2.0 5.0
3.0 3.0
5.0 3.0
3.5 1.0
0
"""
expected_output = """
1.00000 1.00000
3.50000 1.00000
5.00000 3.00000
2.00000 5.00000
"""
assert main(input_data).strip() == expected_output.strip()
def test_case_2():
input_data... | [
{
"docstring": "Returns the cross product of vectors o->a and o->b.\nPositive if b is to the left of a -> o, \nnegative if b is to the right of a -> o, \n0 if they are collinear.",
"function_declaration": "def cross_product(o, a, b):",
"function_name": "cross_product",
"parameter_list": "(o, a, b)"
... | [
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 sys\nfrom functools import cmp_to_key\n\ndef orientation(p, q, r):\n \"\"\"\n Returns the orientation of the triplet (p, q, r).\n 0 -> p, q... | trial_gpt4o_2 | {
"original_instruction": "Design a new **Coding Assessment Question** that matches the style and complexity of the existing questions:\n\nDuring a geological survey, researchers observed that certain mineral deposits form unique polygonal shapes on a Cartesian plane, and they want to study the maximum possible area ... | 0.521605 | Code_Contests_19333 | C | [
"cross_product",
"convex_hull",
"main"
] | 3 | [
[
"convex_hull",
"cross_product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0a8a55439cf48b071b9c29b92eae94769d87d450 | e7ea748aa21a09a4ecb9de3791b4b211fa6211dc | |||
v1.0 | complete | Code_Contests | Code_Contests_18990_C | def reverse_number(n):
"""
Reverses the digits of the given number.
"""
return int(str(n)[::-1])
def is_palindrome(n):
"""
Checks whether the given number is a palindrome.
"""
return str(n) == str(n)[::-1]
def get_palindrome_steps_and_result(n):
"""
Returns the number of steps ... | def reverse_number(n):
"""
Reverses the digits of the given number.
"""
return int(str(n)[::-1])
def is_palindrome(n):
"""
Checks whether the given number is a palindrome.
"""
return str(n) == str(n)[::-1]
def get_palindrome_steps_and_result(n):
"""
Returns the number of steps ... | from solution import solve_palindromes
def test_solve_palindromes():
assert solve_palindromes([195, 265, 34543, 123, 89]) == [
(4, 9339),
(5, 45254),
(0, 34543),
(1, 444),
(24, 8813200023188)
]
def test_single_palindrome():
assert solve_palindromes([1]) == [(0, 1)]
... | [
{
"docstring": "Reverses the digits of the given number.",
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": "Checks whether the given number is a palindrome.",
"function_declaration": "def is_palindrome(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 reverse_number(n):\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef palindrome_steps(n):\n steps = 0... | trial_gpt4o_2 | {
"original_instruction": "A palindrome is a sequence that reads the same backward as forward. For this question, consider only numeric palindromes and their formation by adding the original number to its reverse (complement). For example, starting with 195, reversing the digits to get 591, and adding these two numbe... | 0.708579 | Code_Contests_18990 | C | [
"reverse_number",
"is_palindrome",
"get_palindrome_steps_and_result",
"solve_palindromes"
] | 4 | [
[
"get_palindrome_steps_and_result",
"is_palindrome"
],
[
"get_palindrome_steps_and_result",
"reverse_number"
],
[
"solve_palindromes",
"get_palindrome_steps_and_result"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b663c63098b0013685083429070825488434b072 | a502c80e8f5433092195267dc86092fca5bd23fd | |||
v1.0 | complete | Code_Contests | Code_Contests_18201_C | def largest_island_size(test_cases):
""" Determine the size of the largest island in a 2D grid for each test case.
Arguments:
test_cases: A list of test cases, where each test case is a list of lists representing the grid
Returns:
A list of integers representing the size of the largest isl... | def dfs(grid, visited, x, y):
m, n = len(grid), len(grid[0])
stack = [(x, y)]
visited[x][y] = True
island_size = 0
while stack:
cx, cy = stack.pop()
island_size += 1
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ny = cx + dx, cy + dy
if 0 ... | def test_main():
input_data = "3\n4 5\n1 1 0 0 0\n1 1 0 0 1\n0 0 0 1 1\n0 0 1 1 1\n3 3\n0 0 0\n0 1 0\n0 0 0\n2 2\n0 1\n1 0\n"
output = main(input_data)
assert output == "6\n1\n1"
input_data = "1\n3 3\n1 1 1\n1 0 1\n1 1 1\n"
output = main(input_data)
assert output == "8"
input_data = "1... | [
{
"docstring": null,
"function_declaration": "def dfs(grid, visited, x, y):",
"function_name": "dfs",
"parameter_list": "(grid, visited, x, y)"
},
{
"docstring": null,
"function_declaration": "def largest_island_size(test_cases):",
"function_name": "largest_island_size",
"paramet... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_island(grid):\n if not grid:\n return 0\n \n m = len(grid)\n n = len(grid[0])\n \n def dfs(i, j):\n if i < 0 or... | trial_gpt4o_1 | {
"original_instruction": "Given a 2D grid of size m x n, where each cell in the grid can either be a land cell (represented by 1) or a water cell (represented by 0). An island is defined as a group of connected land cells (connected horizontally or vertically). The grid is surrounded by water, and islands are separa... | 0.568386 | Code_Contests_18201 | C | [
"dfs",
"largest_island_size",
"process_input",
"main"
] | 4 | [
[
"largest_island_size",
"dfs"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 6203f812ba69efa53b6a8aacb72011f4e010a1e9 | 5f23a1c2d53cf395dfa6260df0ba65c116337e9f | |||
v1.0 | complete | Code_Contests | Code_Contests_18641_C | def minimum_maintenance_cost(n: int, m: int, bridges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum maintenance cost required to keep all islands connected to the capital city.
The capital city is always situated on island 1.
Parameters:
n (int): Number of islands.
m (int): Numb... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i]) # Path compression
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
... | from solution import minimum_maintenance_cost
def test_example_case():
n = 5
m = 6
bridges = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 3),
(2, 4, 6),
(3, 4, 2),
(4, 5, 5)
]
assert minimum_maintenance_cost(n, m, bridges) == 11
def test_single_bridge():
n = 2... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
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 UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.... | trial_gpt4o_2 | {
"original_instruction": "In a fantasy land, there are n magical islands connected by m bidirectional bridges. The maintenance of these bridges is crucial for the kingdom’s trade and defense. Each bridge has a maintenance cost associated with it. Your task is to ensure that the capital city remains connected to all ... | 0.719254 | Code_Contests_18641 | C | [
"find",
"union",
"kruskal",
"minimum_maintenance_cost"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_maintenance_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | c466bed66e34ced74a94442562152462cdc4c3c2 | db2a42715edacb0f3d9b5695b3b4fe6c20523aaa | |||
v1.0 | complete | Code_Contests | Code_Contests_19882_C | def next_unique_digit_number(n: int) -> int:
"""
Given an integer n, find the smallest integer greater than n that consists of unique digits only.
>>> next_unique_digit_number(1234)
1235
>>> next_unique_digit_number(1233)
1234
>>> next_unique_digit_number(987)
1023
>>> next_uniq... | def is_unique(n):
"""Helper function to check if all digits in a number are unique."""
digits = str(n)
return len(set(digits)) == len(digits)
def next_unique_digit_number(n: int) -> int:
"""
Given an integer n, find the smallest integer greater than n that consists of unique digits only.
"""
... | from solution import next_unique_digit_number
def test_next_unique_digit_number_case1():
assert next_unique_digit_number(1234) == 1235
def test_next_unique_digit_number_case2():
assert next_unique_digit_number(1233) == 1234
def test_next_unique_digit_number_case3():
assert next_unique_digit_number(987) =... | [
{
"docstring": "Helper function to check if all digits in a number are unique.",
"function_declaration": "def is_unique(n):",
"function_name": "is_unique",
"parameter_list": "(n)"
},
{
"docstring": "Given an integer n, find the smallest integer greater than n that consists of unique digits o... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_unique_digits(number):\n digits = list(str(number))\n return len(digits) == len(set(digits))\n\ndef next_unique_digit_number(n: int) -> int:\... | trial_gpt4o_8 | {
"original_instruction": "Given an integer n, find the smallest integer greater than n that consists of unique digits only. For example, if the input is 1234, the next integer with all unique digits would be 1235, since 1234 already consists of unique digits. However, if the input is 1233, the next such integer woul... | 0.661059 | Code_Contests_19882 | C | [
"is_unique",
"next_unique_digit_number"
] | 2 | [
[
"next_unique_digit_number",
"is_unique"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3cb3d5048e5e287346f8addc8bedd94f528a1567 | 461e97d0bc273f48c9718d616c26468de1533b95 | |||
v1.0 | complete | Code_Contests | Code_Contests_19203_C | def is_palindrome(s: str) -> bool:
""" Check if a string is a palindrome.
>>> is_palindrome("abcba") == True
>>> is_palindrome("abccba") == True
>>> is_palindrome("abcd") == False
>>> is_palindrome("a") == True
>>> is_palindrome("") == True
"""
pass
def count_palindrome_pairs(strings: L... | def is_palindrome(s):
return s == s[::-1]
def count_palindrome_pairs(strings):
count = 0
n = len(strings)
for i in range(n):
for j in range(i + 1, n):
if is_palindrome(strings[i] + strings[j]):
count += 1
return count | from solution import is_palindrome, count_palindrome_pairs
def test_is_palindrome():
assert is_palindrome("abcba") == True
assert is_palindrome("abccba") == True
assert is_palindrome("abcd") == False
assert is_palindrome("a") == True
assert is_palindrome("") == True
def test_count_palindrome_pairs... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def count_palindrome_pairs(strings):",
"function_name": "count_palindrome_pairs",
"parameter_list": "(s... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_palindrome_pairs(n, strings):\n \"\"\"\n This function counts the number of pairs (i, j) such that 1 ≤ i < j ≤ n \n and the concatenatio... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of 'n' strings. Each string consists of lowercase English letters. Your task is to find the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ n and the concatenation of the ith string and the jth string is a palindrome.\n\nA string is called palindrome if it read... | 0.809569 | Code_Contests_19203 | C | [
"is_palindrome",
"count_palindrome_pairs"
] | 2 | [
[
"count_palindrome_pairs",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4578ee536722338fe09f47f6257e9a3ecfaf3bf7 | d4f8c0f9cae9ddb3533e964354f9c8a5907d01fa | |||
v1.0 | complete | Code_Contests | Code_Contests_19277_C | def is_prime(n):
"""
Helper function to check whether 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
... | def is_prime(n):
"""
Helper function to check whether 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
... | from solution import can_form_special_prime
def test_can_form_special_prime_yes_case():
can_form_special_prime(4, [2, 3, 5, 7]) # Expected output: "YES"
def test_can_form_special_prime_no_case():
can_form_special_prime(3, [11, 13, 17]) # Expected output: "NO"
def test_can_form_special_prime_single_pair():
... | [
{
"docstring": "Helper function to check whether a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to determine if there exists at least one pair of prime numbers \nfrom the list that concatenates... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n retur... | trial_gpt4o_6 | {
"original_instruction": "Tanya is a fan of prime numbers and recently she discovered an interesting property of them. She found that given a set of prime numbers, she could generate a \"special prime number\" by concatenating any two prime numbers from the set. If the resulting number is prime, she considers it a s... | 0.733646 | Code_Contests_19277 | C | [
"is_prime",
"can_form_special_prime"
] | 2 | [
[
"can_form_special_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5dda9cdf69da7687eaf2ee1f3d15132ea37a92cf | 20579bf8043f298a29a2cf5b3408955402170983 | |||
v1.0 | complete | Code_Contests | Code_Contests_19548_C | def maximalRectangle(matrix):
"""
Given a binary matrix, find the maximum area of a submatrix with all 1s.
>>> maximalRectangle([
>>> [1, 0, 1, 0, 0],
>>> [1, 0, 1, 1, 1],
>>> [1, 1, 1, 1, 1],
>>> [1, 0, 0, 1, 0]
>>> ]) == 6
>>> maximalRectangle([
>>> [0, 0,... | def maximalRectangle(matrix):
"""
Given a binary matrix, find the maximum area of a submatrix with all 1s.
"""
if not matrix or not matrix[0]:
return 0
max_area = 0
n = len(matrix)
m = len(matrix[0])
heights = [0] * m
for i in range(n):
for j in range(m):
... | from solution import maximalRectangle
def test_example_1():
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert maximalRectangle(matrix) == 6
def test_example_2():
matrix = [
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
... | [
{
"docstring": "Given a binary matrix, find the maximum area of a submatrix with all 1s.",
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the largest rectangle area in histo... | [
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 max_submatrix_area(n, m, matrix):\n if n == 0 or m == 0:\n return 0\n \n max_area = 0\n heights = [0] * (m + 1)\n \n for row i... | trial_gpt4o_2 | {
"original_instruction": "Marie loves working with matrices. One day, she encountered an interesting matrix-related problem and decided to solve it. Marie has a matrix where each element is either 0 or 1. A submatrix is any rectangular section of the matrix, possibly the entire matrix or just one element. Marie want... | 0.663293 | Code_Contests_19548 | C | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 43b836cc29622a2e794d2fa33cf5e4147f509b4e | 0168f5929d5528762d372dc8946b97d9b9bd134f | |||
v1.0 | complete | Code_Contests | Code_Contests_19988_C | def process_articles_and_queries(n: int, input_articles: List[List], q: int, input_queries: List[List]) -> List[List[str]]:
"""Given a list of articles with their headlines and tags, and a list of queries with tags,
return the headlines of articles matching each query.
>>> n = 3
>>> input_articles... | def find_matching_headlines(n, articles, q, queries):
results = []
for query in queries:
query_set = set(query)
matching_headlines = []
for article in articles:
headline, tags = article
if query_set.issubset(tags):
matching_headlines.... | from solution import process_articles_and_queries
def test_example():
n = 3
input_articles = [
["Article1", 3, "sports", "health", "wellness"],
["Article2", 2, "technology", "innovation"],
["Article3", 3, "health", "sports", "technology"],
]
q = 2
input_queries = [
[... | [
{
"docstring": null,
"function_declaration": "def find_matching_headlines(n, articles, q, queries):",
"function_name": "find_matching_headlines",
"parameter_list": "(n, articles, q, queries)"
},
{
"docstring": null,
"function_declaration": "def process_articles_and_queries(n, input_artic... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_articles(n, articles, q, queries):\n \"\"\"\n Finds article headlines matching given queries.\n \n Args:\n - n (int): The number of... | trial_gpt4o_2 | {
"original_instruction": "You are an editor at a news aggregator website. You have access to an archive of articles, and each article's content starts with a headline followed by a series of tags unique to that article. Each article's headline is a string, and each tag is a lowercase string without spaces or punctua... | 0.648296 | Code_Contests_19988 | C | [
"find_matching_headlines",
"process_articles_and_queries"
] | 2 | [
[
"process_articles_and_queries",
"find_matching_headlines"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e87f3e69a50e53be8a2ee83bf0990b6eff8c684c | 8a3023812122c836718d6906a07cc33ad11d89fb | |||
v1.0 | complete | Code_Contests | Code_Contests_19204_C | def maximal_rectangle_area(n: int, m: int, grid: List[List[int]]) -> int:
""" Determine the area of the largest possible contiguous rectangle of fertile land
in a farm represented by a binary grid.
>>> maximal_rectangle_area(4, 5, [[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1]... | def maximalRectangle(matrix):
"""
Returns the area of the largest rectangle of only fertile cells (1s) in the given binary matrix.
"""
if not matrix:
return 0
max_area = 0
dp = [0] * len(matrix[0])
for row in matrix:
for j in range(len(row)):
dp[j] = dp[j] + 1 i... | import pytest
from solution import get_largest_rectangle_area
def test_single_element():
assert get_largest_rectangle_area(1, 1, [[1]]) == 1
assert get_largest_rectangle_area(1, 1, [[0]]) == 0
def test_multiple_elements():
assert get_largest_rectangle_area(4, 5, [[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1... | [
{
"docstring": "Returns the area of the largest rectangle of only fertile cells (1s) in the given binary matrix.",
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to calculate the la... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(grid):\n if not grid or not grid[0]:\n return 0\n \n def largestRectangleArea(heights):\n stack = []\n m... | trial_gpt4o_2 | {
"original_instruction": "A farm has a rectangular grid of size N x M, where each cell can either be fertile or barren. The farm is represented as a binary grid where a '1' indicates a fertile cell and '0' indicates a barren cell. Farmers want to create the largest possible contiguous rectangle of fertile land. Your... | 0.6317 | Code_Contests_19204 | C | [
"maximalRectangle",
"largestRectangleArea",
"get_largest_rectangle_area"
] | 3 | [
[
"get_largest_rectangle_area",
"maximalRectangle"
],
[
"maximalRectangle",
"largestRectangleArea"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9890fb7f4c2b5d66b46fc0e472d0c2b678711924 | eadad27a2d3beb5b1fbe9ee38116c33e11e3103b | |||
v1.0 | complete | Code_Contests | Code_Contests_17646_C | def filter_and_sort_ips(start_range: str, end_range: str, ip_addresses: List[str]) -> List[str]:
"""
Filters and sorts IP addresses that fall within the specified range.
Parameters:
start_range (str): The starting IP address of the range (inclusive).
end_range (str): The ending IP address of the ra... | def ip_to_int(ip):
"""
Convert an IP address to an integer.
"""
parts = ip.split(".")
return int(parts[0]) * 256**3 + int(parts[1]) * 256**2 + int(parts[2]) * 256 + int(parts[3])
def filter_and_sort_ips(start_range, end_range, ip_addresses):
"""
Filters and sorts IP addresses that fall with... | from solution import filter_and_sort_ips
def test_example_case():
start_range = "192.168.1.0"
end_range = "192.168.1.255"
ip_addresses = [
"192.168.1.1",
"192.168.1.200",
"10.0.0.1",
"192.168.1.100",
"192.168.1.10"
]
output = [
"192.168.1.1",
... | [
{
"docstring": "Convert an IP address to an integer.",
"function_declaration": "def ip_to_int(ip):",
"function_name": "ip_to_int",
"parameter_list": "(ip)"
},
{
"docstring": "Filters and sorts IP addresses that fall within the specified range.",
"function_declaration": "def filter_and_so... | [
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 ip_to_int(ip):\n \"\"\"\n Converts a given IP address to an integer.\n \"\"\"\n parts = ip.split('.')\n return (int(parts[0]) << 24) + (... | trial_gpt4o_2 | {
"original_instruction": "A company is developing a new feature where they need to handle and manipulate IP addresses. Write a function that takes a list of IP addresses and a range of valid IP addresses and returns a sorted list of IP addresses from the input that fall within the specified range. The range, as well... | 0.594052 | Code_Contests_17646 | C | [
"ip_to_int",
"filter_and_sort_ips"
] | 2 | [
[
"filter_and_sort_ips",
"ip_to_int"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1d17feac2417cf33d91277862b1fe57b87a3db0a | 547c8050aef4d8916d47f06012d047f25b468fe0 | |||
v1.0 | complete | Code_Contests | Code_Contests_20221_C | def can_be_tree(N: int, M: int, K: int, edges: List[Tuple[int, int, int]]) -> str:
"""
Determines if it is possible to remove at most K edges so that the graph becomes a tree.
A tree must have exactly N-1 edges and no cycles.
>>> can_be_tree(4, 3, 1, [(1, 2, 4), (2, 3, 2), (3, 4, 3)]) == "Yes"
>>> c... | def can_be_tree(N, M, K, edges):
"""
Determines if it is possible to remove at most K edges so that the graph becomes a tree.
A tree must have exactly N-1 edges and no cycles.
"""
# A tree needs exactly N-1 edges to be connected and acyclic.
min_required_edges = N - 1
# If there are les... | def test_can_be_tree_case1():
N, M, K = 4, 3, 1
edges = [(1, 2, 4), (2, 3, 2), (3, 4, 3)]
assert can_be_tree(N, M, K, edges) == "Yes"
def test_can_be_tree_case2():
N, M, K = 4, 5, 0
edges = [(1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 4), (2, 4, 5)]
assert can_be_tree(N, M, K, edges) == "No"
def t... | [
{
"docstring": "Determines if it is possible to remove at most K edges so that the graph becomes a tree.\nA tree must have exactly N-1 edges and no cycles.",
"function_declaration": "def can_be_tree(N, M, K, edges):",
"function_name": "can_be_tree",
"parameter_list": "(N, M, K, edges)"
},
{
... | [
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 can_become_tree(n, m, k, edges):\n # Our target is to check if we can remove k edges to make the graph a tree\n # A tree has exactly N-1 edges an... | trial_gpt4o_2 | {
"original_instruction": "Consider an undirected graph with N nodes numbered 1 through N and M edges. Each edge connects two distinct nodes A and B, and has a weight W. Determine if it is possible to remove at most K edges so that the graph becomes a tree (a connected graph with no cycles).\n\nConstraints\n\n* 1 ≤ N... | 0.665817 | Code_Contests_20221 | C | [
"can_be_tree",
"solve"
] | 2 | [
[
"solve",
"can_be_tree"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7187b0c2132d2b24a542e3665aef6c828cfe9f24 | e089f3e25be1455d39798713194280e6d3ed5971 | |||
v1.0 | complete | Code_Contests | Code_Contests_19699_C | def find_magical_permutation(n: int, sequence: List[int]) -> Union[List[int], str]:
"""
Given a sequence of 'n' unique integers, finds a permutation that forms a magical sequence.
A sequence is magical if for every substring 'abc' comprising three consecutive elements in the sequence,
the sum a + b + c... | def is_magical_permutation(perm):
"""
Helper function to check if a given permutation is magical.
"""
for i in range(len(perm) - 2):
if (perm[i] + perm[i+1] + perm[i+2]) % 7 == 0:
return False
return True
def find_magical_permutation(n, sequence):
"""
Given a sequence of... | from solution import find_magical_permutation
def test_case_1():
assert find_magical_permutation(5, [1, 2, 3, 4, 5]) != "Not possible"
def test_case_2():
assert find_magical_permutation(4, [6, 1, 8, 5]) != "Not possible"
def test_case_3():
assert find_magical_permutation(3, [1, 6, 7]) == "Not possible"
... | [
{
"docstring": "Helper function to check if a given permutation is magical.",
"function_declaration": "def is_magical_permutation(perm):",
"function_name": "is_magical_permutation",
"parameter_list": "(perm)"
},
{
"docstring": "Given a sequence of 'n' unique integers, finds a permutation tha... | [
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_magical_permutation(n, sequence):\n def is_magical(seq):\n for i in range(n - 2):\n if (seq[i] + seq[i+1] + seq[i+2]) % 7 == ... | trial_gpt4o_7 | {
"original_instruction": "You are given a sequence of 'n' unique integers, and you want to transform it into a magical sequence. A sequence is magical if for every substring 'abc' comprising three consecutive elements in the sequence, the sum a + b + c is not divisible by '7'.\n\nYour task is to find a permutation o... | 0.587868 | Code_Contests_19699 | C | [
"is_magical_permutation",
"find_magical_permutation"
] | 2 | [
[
"find_magical_permutation",
"is_magical_permutation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d196afaed0b8c592e4441bd2b561efdbcaa2c76f | d45963632228155ce031699c3c3ceff041ce61e3 | |||
v1.0 | complete | Code_Contests | Code_Contests_19620_C | from typing import List, Optional
import math
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes: List[Optional[int]]) -> Optional[TreeNode]:
if not nodes or nodes[0] is None:
return None
... | from typing import List, Optional
import math
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(nodes: List[Optional[int]]) -> Optional[TreeNode]:
if not nodes or nodes[0] is None:
return None
... | import pytest
from solution import find_maximum_path_sum
def test_sample_input():
assert find_maximum_path_sum([1, 2, 3]) == 6
def test_single_node():
assert find_maximum_path_sum([5]) == 5
def test_all_negative_nodes():
assert find_maximum_path_sum([-10, -20, -30]) == -10
def test_multiple_levels():
... | [] | [
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": "# Define the Binary Tree Node class\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = le... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree, and your task is to determine the maximum path sum. The path can start and end at any two nodes in the tree, and it must go downwards (traveling only from parent nodes to child nodes, but it can only travel through each node once).\n\nInput\nThe input is provide... | 0.607145 | Code_Contests_19620 | C | [
"build_tree",
"max_path_sum",
"find_maximum_path_sum"
] | 3 | [
[
"find_maximum_path_sum",
"build_tree"
],
[
"find_maximum_path_sum",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 3f7d2d956a5b06da4d5757748593d396f5a71faa | 36078337e9e5e16503d2b447e2cf709300e0095a | |||
v1.0 | complete | Code_Contests | Code_Contests_19510_C | def solve(N: int, M: int, K: int, gemstone_types: List[str], shop_info: List[List[str]]) -> int:
""" Calculate the maximum number of unique gemstone types Sara can collect by visiting at most K shops.
Args:
N (int): The number of unique gemstone types.
M (int): The number of shops.
... | from itertools import combinations
def max_unique_gemstones(N, M, K, gemstone_types, shops):
max_unique = 0
for c in combinations(shops, K):
collected_gemstones = set()
for shop in c:
collected_gemstones.update(shop)
max_unique = max(max_unique, len(collected_gemstones)... | import pytest
from solution import solve
def test_example_1():
N, M, K = 3, 4, 2
gemstone_types = ['A', 'B', 'C']
shops = [
[2, 'A', 'B'],
[3, 'A', 'B', 'C'],
[1, 'B'],
[1, 'C']
]
assert solve(N, M, K, gemstone_types, shops) == 3
def test_example_2():
N, M, K = ... | [
{
"docstring": null,
"function_declaration": "def max_unique_gemstones(N, M, K, gemstone_types, shops):",
"function_name": "max_unique_gemstones",
"parameter_list": "(N, M, K, gemstone_types, shops)"
},
{
"docstring": null,
"function_declaration": "def solve(N, M, K, gemstone_types, shop... | [
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 itertools import combinations\n\ndef max_unique_gemstones(N, M, K, gemstones, shops):\n max_unique = 0\n\n for shops_comb in combinations(shops,... | trial_gpt4o_2 | {
"original_instruction": "Sara loves collecting gemstones. There are N different types of gemstones, each represented by an uppercase alphabet letter from 'A' to 'Z'. Sara is planning to travel to M different shops numbered from 1 to M, to collect these gemstones. Each shop stocks a specific combination of gemstone ... | 0.60516 | Code_Contests_19510 | C | [
"max_unique_gemstones",
"solve"
] | 2 | [
[
"solve",
"max_unique_gemstones"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a3fb815f0eef7ecb96e0f0c0548fa9e97bad8610 | 8e0fbb57d331f76642ae43038cc67dc5e463147f | |||
v1.0 | complete | Code_Contests | Code_Contests_20331_C | def min_steps_to_stop(n):
"""
Returns the minimum number of steps to reduce n such that it is no longer divisible by 2, 3, or 4.
>>> min_steps_to_stop(10)
1
>>> min_steps_to_stop(15)
1
>>> min_steps_to_stop(24)
3
>>> min_steps_to_stop(1)
0
"""
pass
def min_steps_for_case... | def min_steps_to_stop(n):
"""
Returns the minimum number of steps to reduce n such that it is no longer divisible by 2, 3, or 4.
"""
steps = 0
while n % 2 == 0 or n % 3 == 0 or n % 4 == 0:
if n % 4 == 0:
n //= 4
elif n % 3 == 0:
n //= 3
else:
... | from solution import min_steps_to_stop, min_steps_for_cases
def test_min_steps_to_stop():
assert min_steps_to_stop(10) == 1
assert min_steps_to_stop(15) == 1
assert min_steps_to_stop(24) == 3
assert min_steps_to_stop(1) == 0
assert min_steps_to_stop(2) == 1
assert min_steps_to_stop(3) == 1
... | [
{
"docstring": "Returns the minimum number of steps to reduce n such that it is no longer divisible by 2, 3, or 4.",
"function_declaration": "def min_steps_to_stop(n):",
"function_name": "min_steps_to_stop",
"parameter_list": "(n)"
},
{
"docstring": "Returns the results for multiple test cas... | [
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 min_steps_to_stop(n):\n \"\"\"\n Returns the minimum number of steps to reduce n such that it is no longer divisible by 2, 3, or 4.\n \"\"\"\n... | trial_gpt4o_0 | {
"original_instruction": "Sarah loves programming and solving puzzles. She also enjoys going on hikes. Sarah created a unique way to challenge herself on the trails: she picks a positive integer $n$ at the start of her hike and attempts to divide it by certain integers while following specific rules.\n\nHere are the... | 0.606338 | Code_Contests_20331 | C | [
"min_steps_to_stop",
"min_steps_for_cases",
"process_input_output"
] | 3 | [
[
"min_steps_for_cases",
"min_steps_to_stop"
],
[
"process_input_output",
"min_steps_for_cases"
]
] | 2 | [
"process_input_output"
] | false | [] | false | pytest | true | [] | true | 6941497e9984a965d0a210bfd52d9ea300753556 | 760068cc88eaecfa97f3dedee12140d1615f87f6 | |||
v1.0 | complete | Code_Contests | Code_Contests_19571_C | from typing import List
def rearrange_sequence_into_palindrome(n: int, sequence: List[int]) -> str:
"""
Determine if a sequence of integers can be rearranged into a palindrome.
If possible, return one possible arrangement as a space-separated string.
Otherwise, return "IMPOSSIBLE".
>>> rearrange_... | from collections import Counter
def can_form_palindrome(n, sequence):
count = Counter(sequence)
# Check for the number of odd occurrences
odd_count = sum(1 for x in count.values() if x % 2 != 0)
# For a sequence to be rearranged to a palindrome, it can have at most one odd count
if odd_co... | from solution import rearrange_sequence_into_palindrome
def test_palindrome_odd_length():
assert rearrange_sequence_into_palindrome(5, [1, 2, 3, 2, 1]) == "1 2 3 2 1"
def test_palindrome_even_length():
result = rearrange_sequence_into_palindrome(4, [4, 3, 3, 4])
# Two possible valid responses for the give... | [
{
"docstring": null,
"function_declaration": "def can_form_palindrome(n, sequence):",
"function_name": "can_form_palindrome",
"parameter_list": "(n, sequence)"
},
{
"docstring": null,
"function_declaration": "def rearrange_sequence_into_palindrome(n, sequence):",
"function_name": "re... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef rearrange_to_palindrome(n, sequence):\n \"\"\"\n Determine if it's possible to rearrange the sequence into a p... | trial_gpt4o_6 | {
"original_instruction": "Alice has a sequence of integers that she wants to convert into a special arrangement. Specifically, she wants to rearrange the numbers such that the sequence becomes a palindrome, if possible. A sequence is a palindrome if it reads the same backward as forward.\n\nThe task is to determine ... | 0.707035 | Code_Contests_19571 | C | [
"can_form_palindrome",
"rearrange_sequence_into_palindrome"
] | 2 | [
[
"rearrange_sequence_into_palindrome",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65ecb63b600807c4503322dbddf6b030aec34e48 | b43a69adcb9fe99953885ca53aa47c2534327f28 | |||
v1.0 | complete | Code_Contests | Code_Contests_20219_C | def min_roads_to_clear(N: int, M: int, V1: int, V2: int, roads: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of roads that need to be cleared to ensure that there is
at least one viable path between village V1 and village V2.
Args:
- N (int): number of villages.
- M (int): number... | from collections import defaultdict, deque
def find_min_roads_to_clear(N, M, V1, V2, roads):
def bfs(start, end):
visited = [False] * (N + 1)
distance = [float('inf')] * (N + 1)
queue = deque([start])
visited[start] = True
distance[start] = 0
while queue:
... | from solution import min_roads_to_clear
def test_case_1():
N, M = 5, 4
V1, V2 = 1, 5
roads = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert min_roads_to_clear(N, M, V1, V2, roads) == 4
def test_case_2():
N, M = 6, 5
V1, V2 = 1, 6
roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
assert min_roa... | [
{
"docstring": null,
"function_declaration": "def find_min_roads_to_clear(N, M, V1, V2, roads):",
"function_name": "find_min_roads_to_clear",
"parameter_list": "(N, M, V1, V2, roads)"
},
{
"docstring": null,
"function_declaration": "def min_roads_to_clear(N, M, V1, V2, edges):",
"fun... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque, defaultdict\n\ndef min_roads_to_clear(N, M, V1, V2, roads):\n if V1 == V2:\n return 0\n \n graph = defaultdi... | trial_gpt4o_2 | {
"original_instruction": "In a mountainous area, there are N villages connected by M roads. Each road connects exactly two villages and is bidirectional. During winter, the villages experience severe snowfall, and certain roads can become blocked.\n\nYou are tasked with ensuring that essential supplies can still be ... | 0.670161 | Code_Contests_20219 | C | [
"find_min_roads_to_clear",
"min_roads_to_clear"
] | 2 | [
[
"min_roads_to_clear",
"find_min_roads_to_clear"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ab4f9e746c8a94586685c2468b3087f52b23a47 | a26ad7cf457c2dc0900d7995ac2a83dda0d34b70 | |||
v1.0 | complete | Code_Contests | Code_Contests_20125_C | from typing import List, Tuple
def find_sccs(V: int, edges: List[Tuple[int, int]]) -> List[List[int]]:
"""
Given the number of vertices (V) and a list of edges in a directed graph,
find the Strongly Connected Components (SCCs) of the graph.
Args:
V: An integer representing the number of vert... | from collections import defaultdict, deque
def kosaraju_scc(V, edges):
"""
Function to find and return strongly connected components in a given directed graph using Kosaraju's algorithm.
"""
def dfs_stack_order(v, graph, visited, stack):
visited.add(v)
for neighbor in graph[v]:
... | from solution import find_sccs
def test_find_sccs_example1():
V, E = 5, 5
edges = [(0, 1), (1, 2), (2, 0), (1, 3), (3, 4)]
expected_result = [[0, 1, 2], [3], [4]]
assert find_sccs(V, edges) == expected_result
def test_find_sccs_example2():
V, E = 5, 6
edges = [(0, 1), (1, 2), (2, 0), (1, 3), (... | [
{
"docstring": "Function to find and return strongly connected components in a given directed graph using Kosaraju's algorithm.",
"function_declaration": "def kosaraju_scc(V, edges):",
"function_name": "kosaraju_scc",
"parameter_list": "(V, edges)"
},
{
"docstring": null,
"function_decla... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef kosaraju_scc(V, E, edges):\n def dfs1(v):\n visited[v] = True\n for neighbor in graph[v]... | trial_gpt4o_2 | {
"original_instruction": "Given a directed graph G(V, E), find the Strongly Connected Components (SCCs) of the graph.\n\nA strongly connected component (SCC) of a directed graph is a maximal strongly connected subgraph. In other words, every vertex is reachable from every other vertex in the subgraph.\n\nConstraints... | 0.576634 | Code_Contests_20125 | C | [
"kosaraju_scc",
"find_sccs"
] | 2 | [
[
"find_sccs",
"kosaraju_scc"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 76f3bbeb0a00936a0ce09e9ed9dac1473b071aa8 | 8982d173a053b33a85405a29ec4eec06039c4666 | |||
v1.0 | complete | Code_Contests | Code_Contests_18354_C | from datetime import datetime, timedelta
from typing import List, Tuple
def analyze_logs(N: int, logs: List[Tuple[int, int, str, str]], Q: int, queries: List[Tuple[int, int, str, str]]) -> List[str]:
""" Analyze the logs to determine how many hours each engineer has worked on each module within a given time range.... | from datetime import datetime, timedelta
def parse_time(time_str):
return datetime.strptime(time_str, "%H:%M")
def total_time_in_range(start_log, end_log, start_query, end_query):
start = max(start_log, start_query)
end = min(end_log, end_query)
if start >= end:
return timedelta()
return e... | from solution import analyze_logs
def test_analyze_logs_sample_case():
N = 5
logs = [
(1, 1, "08:00", "12:00"),
(2, 1, "09:00", "10:00"),
(1, 2, "13:00", "17:00"),
(2, 2, "08:00", "09:00"),
(1, 1, "18:00", "20:00")
]
Q = 3
queries = [
(1, 1, "07:00", ... | [
{
"docstring": null,
"function_declaration": "def parse_time(time_str):",
"function_name": "parse_time",
"parameter_list": "(time_str)"
},
{
"docstring": null,
"function_declaration": "def total_time_in_range(start_log, end_log, start_query, end_query):",
"function_name": "total_time... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime, timedelta\n\ndef parse_time(time_str):\n return datetime.strptime(time_str, \"%H:%M\")\n\ndef time_difference(start, end)... | trial_gpt4o_9 | {
"original_instruction": "A company is interested in analyzing the performance of its software engineers. They maintain logs of the time spent on various modules by different engineers throughout the day. Each log entry records the start and end times an engineer worked on a specific module, along with the engineer'... | 0.709813 | Code_Contests_18354 | C | [
"parse_time",
"total_time_in_range",
"analyze_logs"
] | 3 | [
[
"analyze_logs",
"parse_time"
],
[
"analyze_logs",
"total_time_in_range"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | dcf9ed064f6b1afae38266350c4d383476bd0ab6 | c4c54e2796eca1786967aafa191ae673f46984ea | |||
v1.0 | complete | Code_Contests | Code_Contests_19098_C | def sort_inventory(n: int, items: List[str]) -> Dict[str, Union[List[str], str]]:
"""Organize inventory items using Merge Sort and Quick Sort, and determine stability.
Merge Sort Pseudocode:
MergeSort(A)
1 if A.length > 1
2 mid = A.length / 2
3 L = A[0 .. mid-1]
4 R = A[mid ... | def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
L = arr[:mid]
R = arr[mid:]
merge_sort(L)
merge_sort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if (L[i][0] < R[j][0]) or (L[i][0] == R[j][0] and int(L[i][1:]) <= int(R[j][1:])):
... | from solution import sort_inventory
def test_case_1():
input_items = ["D3", "A15", "B4", "A1"]
expected_merge_sorted = ["A1", "A15", "B4", "D3"]
expected_quick_sorted = ["A1", "A15", "B4", "D3"]
result = sort_inventory(4, input_items)
assert result["merge_sorted_items"] == expected_merge_sort... | [
{
"docstring": null,
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
... | [
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 merge_sort(arr):\n if len(arr) > 1:\n mid = len(arr) // 2\n L = arr[:mid]\n R = arr[mid:]\n\n # Recursive call on each h... | trial_gpt4o_3 | {
"original_instruction": "You are responsible for helping a warehouse organize its inventory. The warehouse has a variety of items, each identified by a unique code consisting of a single character (A-Z) followed by an integer (1-99). For instance, 'A12' could represent a specific item, and 'Z99' could represent ano... | 0.544759 | Code_Contests_19098 | C | [
"merge_sort",
"partition",
"quick_sort",
"is_stable",
"sort_inventory"
] | 5 | [
[
"quick_sort",
"partition"
],
[
"sort_inventory",
"is_stable"
],
[
"sort_inventory",
"merge_sort"
],
[
"sort_inventory",
"quick_sort"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 01dcffce7e60d80330564c16ae0234c2fa284e3f | d0341a8206bac0d2eb676ae590f044d2d603c755 | |||
v1.0 | complete | Code_Contests | Code_Contests_18722_C | def generate_sequences(N, M):
"""
Generate all sequences of length N where each element is between 1 and M (inclusive)
in non-decreasing order.
Parameters:
N (int): Length of each sequence.
M (int): Maximum value of each element in the sequence.
Returns:
List[List[int]]: A lis... | def generate_sequences(N, M):
"""
Generate all sequences of length N where each element is between 1 and M (inclusive)
in non-decreasing order.
Parameters:
N (int): Length of each sequence.
M (int): Maximum value of each element in the sequence.
Returns:
List[List[int]]: A lis... | def test_generate_sequences_2_3():
expected = [
(1, 1), (1, 2), (1, 3),
(2, 2), (2, 3),
(3, 3)
]
assert generate_sequences(2, 3) == expected
def test_generate_sequences_3_2():
expected = [
(1, 1, 1), (1, 1, 2),
(1, 2, 2),
(2, 2, 2)
]
assert ge... | [
{
"docstring": "Generate all sequences of length N where each element is between 1 and M (inclusive) \nin non-decreasing order.\n\nParameters:\nN (int): Length of each sequence.\nM (int): Maximum value of each element in the sequence.\n\nReturns:\nList[List[int]]: A list of sequences in non-decreasing lexicogra... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_sequences(N, M):\n def backtrack(start, sequence):\n if len(sequence) == N:\n result.append(sequence[:])\n ret... | trial_gpt4o_2 | {
"original_instruction": "Problem\n\nIn a magical forest, there are some animals who love solving puzzles. They recently discovered a number puzzle and need your help to solve it. The puzzle works as follows:\n\nGiven two integers $N$ and $M$, generate a sequence of length $N$ where each element is an integer betwee... | 0.720812 | Code_Contests_18722 | C | [
"generate_sequences",
"format_sequences",
"solve"
] | 3 | [
[
"solve",
"format_sequences"
],
[
"solve",
"generate_sequences"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 2b85cf0855c00175babc3f9ecd25e8d77b3e223b | 9ddc7b82d99128283cf9dd0d77b928d17a1c53da | |||
v1.0 | complete | Code_Contests | Code_Contests_19262_C | def max_sum_submatrix(matrix):
""" Find the sum of the elements in the submatrix that has the largest sum among all possible submatrices of the given matrix.
>>> max_sum_submatrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
45
>>> max_sum_submatrix([[-1, -2], [-3, -4]])
-1
"""
def kadane(arr):
max_... | def max_sum_submatrix(matrix):
n = len(matrix)
m = len(matrix[0])
max_sum = float('-inf')
for left in range(m):
temp_row = [0] * n
for right in range(left, m):
for i in range(n):
temp_row[i] += matrix[i][right]
max_s... | from solution import solution
def test_case1():
input_text = "3 3\n1 2 3\n4 5 6\n7 8 9"
assert solution(input_text) == 45
def test_case2():
input_text = "2 2\n-1 -2\n-3 -4"
assert solution(input_text) == -1
def test_case3():
input_text = "1 1\n1000"
assert solution(input_text) == 1000
de... | [
{
"docstring": null,
"function_declaration": "def max_sum_submatrix(matrix):",
"function_name": "max_sum_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def kadane(arr):",
"function_name": "kadane",
"parameter_list": "(arr)"
},
{
... | [
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_submatrix_sum(matrix, n, m):\n def kadane(array):\n max_sum = current_sum = array[0]\n for num in array[1:]:\n current_... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular matrix filled with positive integers. Your task is to find the sum of the elements in the submatrix that has the largest sum among all possible submatrices of the given matrix.\n\nInput\n\nThe first line contains two integers n and m (1 ≤ n, m ≤ 300), where n is ... | 0.601144 | Code_Contests_19262 | C | [
"max_sum_submatrix",
"kadane",
"parse_input",
"solution"
] | 4 | [
[
"max_sum_submatrix",
"kadane"
],
[
"solution",
"max_sum_submatrix"
],
[
"solution",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 4f92e348f11a7499f3a1a4f243549b1110e5983f | 64226c94650d823c850efa7b6c0d7e216420935d | |||
v1.0 | complete | Code_Contests | Code_Contests_19959_C | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
pass
def generate_magic_numbers(k):
"""
Returns a list of the first k prime numbers.
"""
pass
def process_input(input_data):
"""
Processes the input data, which includes multiple test cases.
Retu... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, generate_magic_numbers, process_input
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(31) == True
assert is_prime(1) == False
assert is_prime(0) == False
def te... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of the first k prime numbers.",
"function_declaration": "def generate_magic_numbers(k... | [
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 Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_1 | {
"original_instruction": "Bob loves playing with magic squares. A magic square is an n x n grid filled with distinct numbers such that the sum of the numbers in each row, column, and diagonal is the same.\n\nBob wants to create a list of numbers that can be used to fill in a magic square. A number is considered \"ma... | 0.738783 | Code_Contests_19959 | C | [
"is_prime",
"generate_magic_numbers",
"process_input"
] | 3 | [
[
"generate_magic_numbers",
"is_prime"
],
[
"process_input",
"generate_magic_numbers"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 17dc0bae86d70df0b05b015e13af6ca8040f8bc3 | 377413864c217955320a3a5dd7b4f99d4c29089d | |||
v1.0 | complete | Code_Contests | Code_Contests_20329_C | import math
from functools import reduce
from typing import List
def binary_to_decimal(binary_str: str) -> int:
"""
Converts a binary string to its decimal equivalent.
>>> binary_to_decimal("110")
6
>>> binary_to_decimal("1010")
10
>>> binary_to_decimal("1001")
9
>>> binary_to_... | import math
from functools import reduce
def binary_to_decimal(binary_str):
"""
Converts a binary string to its decimal equivalent.
"""
return int(binary_str, 2)
def gcd_of_list(numbers):
"""
Computes the GCD of a list of numbers.
"""
return reduce(math.gcd, numbers)
def device_activa... | from solution import binary_to_decimal, gcd_of_list, device_activation_time
def test_binary_to_decimal():
assert binary_to_decimal("110") == 6
assert binary_to_decimal("1010") == 10
assert binary_to_decimal("1001") == 9
assert binary_to_decimal("0") == 0
assert binary_to_decimal("1") == 1
def test... | [
{
"docstring": "Converts a binary string to its decimal equivalent.",
"function_declaration": "def binary_to_decimal(binary_str):",
"function_name": "binary_to_decimal",
"parameter_list": "(binary_str)"
},
{
"docstring": "Computes the GCD of a list of numbers.",
"function_declaration": "... | [
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": "import math\nfrom functools import reduce\n\ndef gcd_of_binaries(bin_strings):\n def binary_to_decimal(binary_str):\n \"\"\"\n Converts a ... | trial_gpt4o_5 | {
"original_instruction": "A team of archaeologists has discovered an ancient binary cipher in a newly excavated site. The cipher consists of a sequence of binary strings written on a stone tablet. The researchers have determined that each sequence represents a set of instructions to operate an ancient device. Each b... | 0.627645 | Code_Contests_20329 | C | [
"binary_to_decimal",
"gcd_of_list",
"device_activation_time"
] | 3 | [
[
"device_activation_time",
"binary_to_decimal"
],
[
"device_activation_time",
"gcd_of_list"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1e25260e923b0f78e892b67bd3950132b76df148 | 0b2134e0cb194038b681f1e36c263f1b6b76a087 | |||
v1.0 | complete | Code_Contests | Code_Contests_20175_C | def max_possible_average(N: int, A: List[int]) -> float:
""" Find the maximum possible average of any contiguous sub-sequence.
>>> max_possible_average(4, [1, 12, -5, -6]) 12.0
>>> max_possible_average(5, [1, 2, 3, 4, 5]) 5.0
>>> max_possible_average(3, [-1, -2, -3]) -1.0
"""
from typing import Lis... | def max_average_subsequence(arr):
current_sum = max_sum = arr[0]
for num in arr[1:]:
if current_sum < 0:
current_sum = num
else:
current_sum += num
if current_sum > max_sum:
max_sum = current_sum
return max_sum
def max_possible_average(N... | from solution import max_possible_average
def test_max_possible_average_all_positive():
assert max_possible_average(5, [1, 2, 3, 4, 5]) == 15.0
def test_max_possible_average_mix():
assert max_possible_average(4, [1, 12, -5, -6]) == 13.0
def test_max_possible_average_all_negative():
assert max_possible_av... | [
{
"docstring": null,
"function_declaration": "def max_average_subsequence(arr):",
"function_name": "max_average_subsequence",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def max_possible_average(N, A):",
"function_name": "max_possible_average",
"par... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_average_subsequence(N, A):\n \"\"\"\n Finds the maximum possible average of any contiguous sub-sequence.\n \n Args:\n N: int: Length... | trial_gpt4o_7 | {
"original_instruction": "You are given a sequence of N integers where 1 \\leq i \\leq N. Consider for this sequence all possible contiguous sub-sequences.\n\nYour task is to find the maximum possible average of any contiguous sub-sequence.\n\nNote that the average of a sub-sequence is defined as the sum of the elem... | 0.626231 | Code_Contests_20175 | C | [
"max_average_subsequence",
"max_possible_average"
] | 2 | [
[
"max_possible_average",
"max_average_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 941bc1b8fa62a6b78386ad8524c9b44f854b04f5 | cbf0da15fc9de5036264ea838b4caa9c8976cc44 | |||
v1.0 | complete | Code_Contests | Code_Contests_19598_C | def merge_and_count(arr, temp_arr, left, mid, right):
pass
def merge_sort_and_count(arr, temp_arr, left, right):
pass
def count_inversions(arr):
""" Count the number of inversions in the array.
>>> count_inversions([1, 20, 6, 4, 5])
5
>>> count_inversions([2, 3, 1])
2
>>> count_inversi... | def merge_and_count(arr, temp_arr, left, mid, right):
i = left # Starting index for left subarray
j = mid + 1 # Starting index for right subarray
k = left # Starting index to be sorted
inv_count = 0
# Conditions are checked to ensure that i doesn't exceed mid and j doesn't exceed right
w... | from solution import inversions_for_test_cases
def test_single_test_case():
assert inversions_for_test_cases(1, [(5, [1, 20, 6, 4, 5])]) == [5]
assert inversions_for_test_cases(1, [(3, [2, 3, 1])]) == [2]
def test_multiple_test_cases():
assert inversions_for_test_cases(2, [(5, [1, 20, 6, 4, 5]), (3, [2, 3... | [
{
"docstring": null,
"function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):",
"function_name": "merge_and_count",
"parameter_list": "(arr, temp_arr, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r... | [
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 merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subar... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n integers. An inversion is a pair of indices (i, j) such that i < j and arr[i] > arr[j]. Write a program to count the number of inversions in the array. The program should work efficiently for large arrays.\n\nInput\n\nThe first line contains a single integer t (1... | 0.727772 | Code_Contests_19598 | C | [
"merge_and_count",
"merge_sort_and_count",
"count_inversions",
"inversions_for_test_cases"
] | 4 | [
[
"count_inversions",
"merge_sort_and_count"
],
[
"inversions_for_test_cases",
"count_inversions"
],
[
"merge_sort_and_count",
"merge_and_count"
]
] | 3 | [
"inversions_for_test_cases"
] | false | [] | false | pytest | true | [] | true | 276468ff0c79892a6fa5bd126b5d0c3d91984000 | 71fd0c6203b7ac33d45574a8cfd0f4a43d3ec7c0 | |||
v1.0 | complete | Code_Contests | Code_Contests_18842_C | def mst_min_cost(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int:
""" Calculate the minimum cost to connect all nodes in the forest.
If it is impossible to connect all nodes, return -1.
>>> mst_min_cost(5, 6, [(1, 2, 3), (1, 3, 4), (4, 5, 2), (2, 4, 1), (3, 4, 5), (2, 5, 7)])
10
>>> ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import mst_min_cost
def test_example1():
N = 5
M = 6
connections = [
(1, 2, 3),
(1, 3, 4),
(4, 5, 2),
(2, 4, 1),
(3, 4, 5),
(2, 5, 7),
]
assert mst_min_cost(N, M, connections) == 10
def test_example2():
N = 4
M = 2
connectio... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(pare... | trial_gpt4o_3 | {
"original_instruction": "#### Input\n\nThe input is given from standard input in the following format:\n\n```\nN M\nx1 y1 z1\nx2 y2 z2\n:\n:\nxM yM zM\n```\n\n- N is the number of nodes in a forest.\n- M is the number of connections between the nodes.\n- xi, yi, zi (1 ≤ xi, yi ≤ N) represent a connection between no... | 0.685279 | Code_Contests_18842 | C | [
"find",
"union",
"kruskal",
"mst_min_cost",
"main"
] | 5 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"mst_min_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 0ae365280d9f85c2cf7ebf19310e41b52efafa1a | 9b05deea3aa21699ac4d9b06c5889226c49519f0 | |||
v1.0 | complete | Code_Contests | Code_Contests_20435_C | from typing import List
def replace_primes_with_next(lst: List[int]) -> List[int]:
""" Given a list of integers, replace primes with the next prime number greater than the original.
Non-prime numbers remain unchanged.
Args:
lst (List[int]): A list of integers.
Returns:
List[int]: The ... | 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 next_prime(n):
if n <= 1:
retu... | from solution import replace_primes_with_next
def test_replace_primes_with_next():
assert replace_primes_with_next([3, 4, 11, 20]) == [5, 4, 13, 20]
assert replace_primes_with_next([7, 2, 15]) == [11, 3, 15]
assert replace_primes_with_next([1, 22, 13, 29, 30]) == [1, 22, 17, 31, 30]
assert replace_prim... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers. You need to implement a function that modifies the list such that the primes in the list are replaced by their next prime number greater than the original, and non-prime numbers remain unchanged.\n\nA prime number is a natural number greater than 1 that has... | 0.647809 | Code_Contests_20435 | C | [
"is_prime",
"next_prime",
"replace_primes_with_next"
] | 3 | [
[
"next_prime",
"is_prime"
],
[
"replace_primes_with_next",
"is_prime"
],
[
"replace_primes_with_next",
"next_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 14768474007820cdd4299d45bb2ecac15b7b82a1 | 0eb45e79d8cf252cf7b5068f0080c90e9c14b2fb | |||
v1.0 | complete | Code_Contests | Code_Contests_20407_C | from typing import List, Tuple
def minimum_clusters(n: int, d: float, coordinates: List[Tuple[float, float, float]]) -> int:
""" Find the minimum number of clusters needed to group all stars according to the specified distance constraint.
>>> minimum_clusters(5, 2.0, [(1.0, 2.0, 3.0), (2.0, 2.0, 3.0), (3.0, 2.... | import math
from collections import deque
def distance(star1, star2):
return math.sqrt((star1[0] - star2[0])**2 + (star1[1] - star2[1])**2 + (star1[2] - star2[2])**2)
def find_clusters(stars, n, d):
visited = [False] * n
clusters = 0
def bfs(start):
q = deque([start])
visited[star... | from solution import minimum_clusters
def test_example_case():
n = 5
d = 2.0
coordinates = [
(1.0, 2.0, 3.0),
(2.0, 2.0, 3.0),
(3.0, 2.0, 3.0),
(5.0, 5.0, 5.0),
(6.0, 5.0, 5.0)
]
assert minimum_clusters(n, d, coordinates) == 2
def test_single_star():
n =... | [
{
"docstring": null,
"function_declaration": "def distance(star1, star2):",
"function_name": "distance",
"parameter_list": "(star1, star2)"
},
{
"docstring": null,
"function_declaration": "def find_clusters(stars, n, d):",
"function_name": "find_clusters",
"parameter_list": "(sta... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom collections import deque\n\ndef distance(star1, star2):\n return math.sqrt((star1[0] - star2[0])**2 + (star1[1] - star2[1])**2 + (star... | trial_gpt4o_0 | {
"original_instruction": "You are helping a researcher organize data for a database of the physical properties of stars. Each star is represented as a point in 3-dimensional space with coordinates (x, y, z). The researcher wants to group the stars into clusters such that the distance between any two stars within a c... | 0.626934 | Code_Contests_20407 | C | [
"distance",
"find_clusters",
"minimum_clusters"
] | 3 | [
[
"find_clusters",
"distance"
],
[
"minimum_clusters",
"find_clusters"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d4c172d09cc2bca3b4fa4ee9bbdc3b6b00a29f40 | ef91c4e203c104fafaf86683d31a2d003d957b0f | |||
v1.0 | complete | Code_Contests | Code_Contests_21027_C | def generate_pascals_triangle(n):
"""
Generate the first `n` rows of Pascal's Triangle.
>>> generate_pascals_triangle(1)
[[1]]
>>> generate_pascals_triangle(2)
[[1], [1, 1]]
>>> generate_pascals_triangle(3)
[[1], [1, 1], [1, 2, 1]]
"""
def print_pascals_triangle(n):
... | def generate_pascals_triangle(n):
"""
Generate the first `n` rows of Pascal's Triangle.
"""
if n <= 0:
return []
triangle = [[1]]
for row_num in range(1, n):
row = [1]
prev_row = triangle[row_num - 1]
for j in range(1, row_num):
row.... | from solution import generate_pascals_triangle, print_pascals_triangle
import builtins
def test_generate_pascals_triangle_1():
assert generate_pascals_triangle(1) == [[1]]
def test_generate_pascals_triangle_2():
assert generate_pascals_triangle(2) == [[1], [1, 1]]
def test_generate_pascals_triangle_3():
... | [
{
"docstring": "Generate the first `n` rows of Pascal's Triangle.",
"function_declaration": "def generate_pascals_triangle(n):",
"function_name": "generate_pascals_triangle",
"parameter_list": "(n)"
},
{
"docstring": "Print the first `n` rows of Pascal's Triangle.",
"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 generate_pascals_triangle(n):\n \"\"\"\n Generate the first `n` rows of Pascal's Triangle.\n \"\"\"\n if n <= 0:\n return []\n \n... | trial_gpt4o_0 | {
"original_instruction": "You are given a number `n` and you must generate the first `n` rows of Pascal's Triangle. Pascal's Triangle is a triangular array of numbers where the entries on the edges are always `1` and each number within the triangle is the sum of the two numbers directly above it.\n\nFor example, the... | 0.597546 | Code_Contests_21027 | C | [
"generate_pascals_triangle",
"print_pascals_triangle"
] | 2 | [
[
"print_pascals_triangle",
"generate_pascals_triangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 27cb1b0b800c1415376cfec30171610d7e3a3d1a | a403ab78448e47cf805f047ecd014fe8d3a28ba2 | |||
v1.0 | complete | Code_Contests | Code_Contests_20469_C | def process_assembly_line(n, m, segments, robots_ranges):
"""
Determine if the assembly line can complete the production of all products with the given robots and find the minimum number of robots required.
Args:
n (int): Number of stages in each product.
m (int): Number of robots.
segment... | def min_robots_required(n, m, stages, robots):
segments = [0] * 1001
for stage in stages:
segments[stage] += 1
# Only consider segments that are actually used
relevant_segments = [i for i, count in enumerate(segments) if count > 0]
# If there are no stages, no robot is needed
... | from solution import process_assembly_line
def test_case_1():
assert process_assembly_line(8, 3, [3, 1, 4, 5, 2, 6, 8, 7], [(1, 5), (4, 8), (2, 6)]) == 2
def test_case_2():
assert process_assembly_line(5, 2, [1, 2, 3, 4, 5], [(2, 3), (3, 4)]) == -1
def test_case_3():
assert process_assembly_line(6, 4, [2... | [
{
"docstring": null,
"function_declaration": "def min_robots_required(n, m, stages, robots):",
"function_name": "min_robots_required",
"parameter_list": "(n, m, stages, robots)"
},
{
"docstring": null,
"function_declaration": "def process_assembly_line(n, m, segments, robots_ranges):",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_robots_required(n, m, stage_segments, robot_ranges):\n stages_needed = set(stage_segments)\n robots_covering_segment = [set() for _ in range(... | trial_gpt4o_1 | {
"original_instruction": "A factory has an assembly line where robots build products. Each product goes through a specific number of stages, and each stage is assigned to a segment in the assembly line. Each robot covers a range of segments, where it can operate on any stage within those segments. The robots work si... | 0.606984 | Code_Contests_20469 | C | [
"min_robots_required",
"process_assembly_line"
] | 2 | [
[
"process_assembly_line",
"min_robots_required"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b8a0243c947f2f3c2d809c5f88e3557990cd644e | 2e35b4f43b75518b92597b183b34c7431aac1201 | |||
v1.0 | complete | Code_Contests | Code_Contests_20411_C | def is_armstrong_number(number: int) -> bool:
"""
Check if a given number is an Armstrong number.
>>> is_armstrong_number(153)
True
>>> is_armstrong_number(9474)
True
>>> is_armstrong_number(123)
False
>>> is_armstrong_number(0)
True
>>> is_armstrong_number(1)
True
>>... | def is_armstrong_number(number):
"""
Check if a given number is an Armstrong number.
"""
digits = list(map(int, str(number)))
power = len(digits)
sum_of_powers = sum(digit ** power for digit in digits)
return sum_of_powers == number
def check_armstrong_numbers(count, numbers):
"""
R... | from solution import is_armstrong_number, check_armstrong_numbers
def test_is_armstrong_number():
assert is_armstrong_number(153) == True
assert is_armstrong_number(9474) == True
assert is_armstrong_number(123) == False
assert is_armstrong_number(0) == True
assert is_armstrong_number(1) == True
... | [
{
"docstring": "Check if a given number is an Armstrong number.",
"function_declaration": "def is_armstrong_number(number):",
"function_name": "is_armstrong_number",
"parameter_list": "(number)"
},
{
"docstring": "Return a list of \"YES\" or \"NO\" based on whether each number in numbers 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": "def is_armstrong_number(num):\n \"\"\"\n Checks if a number is an Armstrong number.\n \n Args:\n num: int. The number to check.\n \n R... | trial_gpt4o_2 | {
"original_instruction": "John loves playing with numbers. Recently, he came across a special type of number known as an Armstrong number. An Armstrong number for a given number of digits is an integer such that the sum of its own digits each raised to the power of the number of digits is equal to the number itself.... | 0.597446 | Code_Contests_20411 | C | [
"is_armstrong_number",
"check_armstrong_numbers"
] | 2 | [
[
"check_armstrong_numbers",
"is_armstrong_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 99cb9d5d3f95470351af9ea9f50426acc89ea6d3 | 862007b9ff7683b7a47d7a409fe84de7b0eb36eb | |||
v1.0 | complete | Code_Contests | Code_Contests_21008_C | def can_be_split(S: str) -> str:
""" Determines if the string S can be split into three strings A, B, and C such that A and C are reverses of each other and B is a palindrome.
>>> can_be_split("abccba") == "YES"
>>> can_be_split("abcdecba") == "NO"
>>> can_be_split("aabcdefedcbaa") == "YES"
>>> can_... | def is_palindrome(s):
return s == s[::-1]
def can_be_split(S):
n = len(S)
for i in range(n):
for j in range(i, n):
A = S[:i]
B = S[i:j+1]
C = S[j+1:]
if A == C[::-1] and is_palindrome(B):
return "YES"
return "NO" | from solution import can_be_split
def test_can_be_split_example1():
assert can_be_split("abccba") == "YES"
def test_can_be_split_example2():
assert can_be_split("abcdecba") == "NO"
def test_can_be_split_example3():
assert can_be_split("aabcdefedcbaa") == "YES"
def test_can_be_split_single_char():
as... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def can_be_split(S):",
"function_name": "can_be_split",
"parameter_list": "(S)"
}
] | [
0,
0,
0,
0,
0,
1,
1,
0,
1,
0
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_be_split(S):\n \"\"\"\n Determines if string S can be split into strings A, B, and C such that\n A and C are reverses of each other and B ... | trial_gpt4o_8 | {
"original_instruction": "Given a string `S`, we can write it as the concatenation of string `A`, string `B`, and string `C`, i.e., S = A + B + C. We are interested in the case where string `A` and `C` are reverses of each other and string `B` forms a palindrome by itself. Write a function that determines if `S` can... | 0.72954 | Code_Contests_21008 | C | [
"is_palindrome",
"can_be_split"
] | 2 | [
[
"can_be_split",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d97eaf2ca15b2ba71c495aabb23d98b39012bf04 | 4efaa2bdf4d3cc262833a49f5239d032d474a42c | |||
v1.0 | complete | Code_Contests | Code_Contests_19335_C | def preprocess_matrix(matrix):
""" Preprocess the matrix to create a prefix sum matrix.
Args:
- matrix: List[List[int]], the original matrix.
Returns:
- List[List[int]], the prefix sum matrix.
"""
pass
def query_sum(prefix_sum, r1, c1, r2, c2):
""" Calculate the sum of the submatrix de... | def preprocess_matrix(matrix):
n = len(matrix)
m = len(matrix[0])
# Create prefix sum matrix
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = (
matrix[i-1][j-1] +
pr... | def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
assert preprocess_matrix(matrix) == expected_prefix_sum
def test_query_sum():
... | [
{
"docstring": null,
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def query_sum(prefix_sum, r1, c1, r2, c2):",
"function_name": "query_sum",
"parameter... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_matrix(matrix, n, m):\n \"\"\"\n Preprocess the given matrix to create a prefix sum matrix.\n \"\"\"\n prefix_sum = [[0] * (m + ... | trial_gpt4o_2 | {
"original_instruction": "You are given an n x m matrix of integers. Your task is to handle q queries regarding submatrices of this matrix. Each query consists of four integers: r1, c1, r2, and c2, which define the top-left and bottom-right corners of a submatrix. For each query, you need to calculate the sum of all... | 0.555727 | Code_Contests_19335 | C | [
"preprocess_matrix",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess_matrix"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 12d3016e365b5d1c53291346571ca7174086e410 | 5442d5a1fc1b9a1af51b396b9e9e199042f47a1a | |||
v1.0 | complete | Code_Contests | Code_Contests_20672_C | from typing import List, Tuple
def longest_path(N: int, M: int, edges: List[Tuple[int, int]]) -> int:
"""Identify the longest possible path within the network of computers.
Args:
N: int - Number of computers in the network
M: int - Number of direct connections
edges: List[Tuple[int, int]] - Li... | from collections import defaultdict, deque
def find_farthest_node(start_node, adj_list):
visited = set()
q = deque([(start_node, 0)]) # (node, distance)
farthest_node = start_node
max_distance = 0
visited.add(start_node)
while q:
current_node, distance = q.popleft()
if distanc... | from solution import longest_path
def test_single_edge():
assert longest_path(2, 1, [(1, 2)]) == 1
def test_no_edges():
assert longest_path(5, 0, []) == 0
def test_example_1():
assert longest_path(4, 3, [(1, 2), (2, 3), (3, 4)]) == 3
def test_example_2():
assert longest_path(5, 4, [(1, 2), (1, 3), (... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(start_node, adj_list):",
"function_name": "find_farthest_node",
"parameter_list": "(start_node, adj_list)"
},
{
"docstring": null,
"function_declaration": "def longest_path(N, M, edges):",
"function_name": "longest_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef longest_path(n, edges):\n graph = defaultdict(list)\n for u, v in edges:\n graph[u].append(v... | trial_gpt4o_2 | {
"original_instruction": "In a network of computers, some pairs of computers are directly connected through a cable. The network can be represented as an undirected graph, with computers as nodes and cables as edges. Evaluate the network structure to identify the longest possible path within the network, where the l... | 0.632214 | Code_Contests_20672 | C | [
"find_farthest_node",
"longest_path"
] | 2 | [
[
"longest_path",
"find_farthest_node"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 177d536412f994a80484a3b34bf031a60c8ede96 | 7f6ffd4e90a1d3ef8945a3073c923e55f3418b9a | |||
v1.0 | complete | Code_Contests | Code_Contests_20429_C | def min_cost_to_monitor_network(n, m, costs, connections):
""" Determine the minimum total cost to monitor the entire network of servers.
Parameters:
n (int): The number of servers.
m (int): The number of connections between servers.
costs (List[int]): The cost to deploy the monitoring system o... | def min_cost_to_monitor_network(n, m, costs, connections):
from collections import defaultdict
import sys
# Step 1: Create the graph using adjacency list representation
graph = defaultdict(list)
for u, v in connections:
graph[u].append(v)
graph[v].append(u)
vis... | def test_simple_case():
assert solve(4, 3, [4, 2, 6, 3], [(1, 2), (2, 3), (3, 4)]) == 2
def test_disconnected_case():
assert solve(6, 4, [4, 6, 3, 5, 8, 3], [(1, 2), (3, 4), (4, 5), (5, 6)]) == 7
def test_fully_connected_case():
assert solve(4, 6, [1, 2, 3, 4], [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3,... | [
{
"docstring": null,
"function_declaration": "def min_cost_to_monitor_network(n, m, costs, connections):",
"function_name": "min_cost_to_monitor_network",
"parameter_list": "(n, m, costs, connections)"
},
{
"docstring": null,
"function_declaration": "def solve(n, m, costs, connections):"... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_cost(n, m, costs, edges):\n from heapq import heappop, heappush\n from collections import defaultdict\n \n # Use union-find to fin... | trial_gpt4o_9 | {
"original_instruction": "A company has a network of centralized servers. Each server is represented by a node, and each connection between servers is represented by an undirected and weighted edge. The network is represented as an undirected graph with n nodes (numbered from 1 to n) and m edges. You are required to... | 0.63771 | Code_Contests_20429 | C | [
"min_cost_to_monitor_network",
"solve"
] | 2 | [
[
"solve",
"min_cost_to_monitor_network"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 917a5695742a771a5443aa31fd71ac93218fd559 | 2c0516dfd86d2961ef5400a8b626319593285964 | |||
v1.0 | complete | Code_Contests | Code_Contests_20866_C | def binary_tree_height(n: int, edges: List[Tuple[int, int]]) -> int:
"""
Constructs a binary tree using the provided node relationships and
then determines the height of the tree.
Args:
n (int): The number of nodes in the tree.
edges (List[Tuple[int, int]]): List of tuples representing the... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(edges):
nodes = {}
for u, v in edges:
if u not in nodes:
nodes[u] = TreeNode(u)
if v not in nodes:
nodes[v] = TreeNode(v)
if not node... | def test_single_node():
assert binary_tree_height(1, []) == 0
def test_linear_tree():
assert binary_tree_height(3, [(1, 2), (2, 3)]) == 2
def test_already_balanced_tree():
assert binary_tree_height(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 2
def test_completely_balanced_tree():
assert binary_tree_heigh... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef calculate_tree_height(n, edges):\n if n == 1:\n return 0\n\n tree = defaultdict(list)\n f... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree with n nodes, each node having a unique value from 1 to n. Each node can have up to two children, but not necessarily both. Your task is to construct the tree using the provided node relationships and then determine the height of the tree. The height of a binary ... | 0.605183 | Code_Contests_20866 | C | [
"build_tree",
"find_root",
"height_of_tree",
"binary_tree_height"
] | 4 | [
[
"binary_tree_height",
"build_tree"
],
[
"binary_tree_height",
"find_root"
],
[
"binary_tree_height",
"height_of_tree"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 97481d5db98df303894d98e3983d4819d65cefb8 | 64a0813ad982232372982e2ebab0bc3231c3e5ad | |||
v1.0 | complete | Code_Contests | Code_Contests_19931_C | import math
from typing import List, Tuple
def is_even(n: int) -> bool:
""" Check if a number is even.
>>> is_even(4)
True
>>> is_even(7)
False
"""
pass
def is_prime(n: int) -> bool:
""" Check if a number is prime.
>>> is_prime(5)
True
>>> is_prime(10)
False
"""
... | import math
def is_even(n):
return n % 2 == 0
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 ... | from solution import validate_results
def test_validate_results():
assert validate_results(5, [
(1, 48),
(2, 23),
(3, 25),
(1, 35),
(2, 49)
]) == ["Valid", "Valid", "Valid", "Invalid", "Invalid"]
def test_even_scores():
assert validate_results(2, [
(1, 2... | [
{
"docstring": null,
"function_declaration": "def is_even(n):",
"function_name": "is_even",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"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": "import math\n\ndef validate_scores(t, scores):\n results = []\n \n def is_prime(n):\n if n <= 1:\n return False\n if n <=... | trial_gpt4o_2 | {
"original_instruction": "Pranav is organizing a marathon coding competition, and he needs a function to help with validating the results. Each participant will provide a solution for a series of coding problems, and the function will have to verify the results based on different criteria. Each problem in the marath... | 0.623675 | Code_Contests_19931 | C | [
"is_even",
"is_prime",
"is_perfect_square",
"validate_results"
] | 4 | [
[
"validate_results",
"is_even"
],
[
"validate_results",
"is_perfect_square"
],
[
"validate_results",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 8580ceef1498d1d44848cd8c1d29936197ef5efc | f80710e578ea23f0249f46bbd89b8d3c99fa3267 | |||
v1.0 | complete | Code_Contests | Code_Contests_20707_C | def rotate_garden(n: int, m: int, garden: List[List[str]], k: int) -> List[List[str]]:
""" Rotates the garden 90 degrees clockwise k times.
Args:
n : int : number of rows in the garden
m : int : number of columns in the garden
garden : List[List[str]] : initial arrangement of flowers and empty cells... | def rotate_90_degrees(garden, n, m):
return [[garden[n - 1 - i][j] for i in range(n)] for j in range(m)]
def rotate_garden(n, m, garden, k):
k = k % 4 # Since 4 rotations result in the same pattern
for _ in range(k):
garden = rotate_90_degrees(garden, n, m)
n, m = m, n
return garden | from solution import rotate_garden
def test_rotate_garden_once():
n = 4
m = 3
garden = [
['A', 'B', 'C'],
['D', 'E', 'F'],
['G', 'H', 'I'],
['J', 'K', 'L']
]
k = 1
expected = [
['J', 'G', 'D', 'A'],
['K', 'H', 'E', 'B'],
['L', 'I', 'F', 'C... | [
{
"docstring": null,
"function_declaration": "def rotate_90_degrees(garden, n, m):",
"function_name": "rotate_90_degrees",
"parameter_list": "(garden, n, m)"
},
{
"docstring": null,
"function_declaration": "def rotate_garden(n, m, garden, k):",
"function_name": "rotate_garden",
"... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate_garden(n, m, garden, k):\n \"\"\"\n Rotates the garden 90 degrees clockwise k times.\n \"\"\"\n def rotate_90_clockwise(grid):\n ... | trial_gpt4o_1 | {
"original_instruction": "Alice is an avid gardener and loves arranging flowers in her garden. She has a rectangular garden of size n x m (n rows and m columns). Each cell in the garden can contain one type of flower or be empty. The flowers in Alice's garden are represented by distinct uppercase letters ('A' to 'Z'... | 0.548732 | Code_Contests_20707 | C | [
"rotate_90_degrees",
"rotate_garden"
] | 2 | [
[
"rotate_garden",
"rotate_90_degrees"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1da4955f124f4a560a0da888e4bc7fa8fdd093ad | 64f1a207db33d4a0ac5c58abd66eddcb355c476c | |||
v1.0 | complete | Code_Contests | Code_Contests_21084_C | def run_length_encode(s: str) -> str:
"""
Perform Run-Length Encoding on the given string.
Args:
s: The input string
Returns:
The Run-Length Encoded string
>>> run_length_encode("aabcccccaaa") "a2bc5a3"
>>> run_length_encode("abcd") "abcd"
>>> run_length_encode("aaabbb... | def run_length_encode(s):
"""
Perform Run-Length Encoding on the given string.
Args:
s: The input string
Returns:
The Run-Length Encoded string
"""
if not s:
return ""
encoded_string = []
count = 1
previous_char = s[0]
for char in s[1:]:
... | from solution import run_length_encode, process_strings
def test_run_length_encode():
assert run_length_encode("aabcccccaaa") == "a2bc5a3"
assert run_length_encode("abcd") == "abcd"
assert run_length_encode("aaabbbaaaacccddd") == "a3b3a4c3d3"
assert run_length_encode("a") == "a"
assert run_length_e... | [
{
"docstring": "Perform Run-Length Encoding on the given string.\n\nArgs:\ns: The input string\n\nReturns:\nThe Run-Length Encoded string",
"function_declaration": "def run_length_encode(s):",
"function_name": "run_length_encode",
"parameter_list": "(s)"
},
{
"docstring": "Process a list of ... | [
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 run_length_encoding(strings):\n def encode(s):\n if not s:\n return \"\"\n encoded = []\n count = 1\n previou... | trial_gpt4o_2 | {
"original_instruction": "Your company is working on an advanced search engine. As part of this project, one of the tasks is to implement a text compression algorithm using the Run-Length Encoding (RLE) technique to handle large text data efficiently.\n\nRun-Length Encoding is a simple form of data compression where... | 0.705592 | Code_Contests_21084 | C | [
"run_length_encode",
"process_strings"
] | 2 | [
[
"process_strings",
"run_length_encode"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b976e7c97451ea6573e059c7ebb3d5cdceb668de | 51dbe435c9cbe89559756a99f518ec309ff795b0 | |||
v1.0 | complete | Code_Contests | Code_Contests_19503_C | def validate_sudoku(board: List[str]) -> str:
""" Validate if a given Sudoku board is valid.
The board is valid if each row, column, and the 3x3 sub-boxes contain the digits 1-9 without repetition.
Args:
board (List[str]): A list representing a 9x9 Sudoku board.
Returns:
... | def is_valid_sudoku(board):
def is_valid_row(board):
for row in board:
if not is_valid_unit(row):
return False
return True
def is_valid_col(board):
for col in zip(*board):
if not is_valid_unit(col):
return False
return True... | def test_sudoku_valid_case_1():
board = [
"53..7....",
"6..195...",
".98....6.",
"8...6...3",
"4..8.3..1",
"7...2...6",
".6....28.",
"...419..5",
"....8..79"
]
assert validate_sudoku(board) == "YES"
def test_sudoku_invalid_case_1():
... | [
{
"docstring": null,
"function_declaration": "def is_valid_sudoku(board):",
"function_name": "is_valid_sudoku",
"parameter_list": "(board)"
},
{
"docstring": null,
"function_declaration": "def validate_sudoku(board):",
"function_name": "validate_sudoku",
"parameter_list": "(board... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_sudoku(board):\n \"\"\"\n Determine if a given Sudoku board is valid.\n \"\"\"\n def is_valid_block(block):\n block = [x fo... | trial_gpt4o_1 | {
"original_instruction": "John is a software developer who has recently been fascinated by the popular game Sudoku. He decided to create a function to validate Sudoku boards. A Sudoku board is a 9x9 grid, where each cell can have a digit from 1 to 9 or be empty, represented by a dot ('.'). The board is valid if the ... | 0.570509 | Code_Contests_19503 | C | [
"is_valid_sudoku",
"validate_sudoku"
] | 2 | [
[
"validate_sudoku",
"is_valid_sudoku"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 06add528d3c4d57e06f1103e5d93714c2b889265 | fefce11bf8d5752a69ed5ece434b50d3ad11a665 | |||
v1.0 | complete | Code_Contests | Code_Contests_21243_C | from typing import List
from collections import Counter
def can_form_palindrome(s: str) -> bool:
""" Determines if the characters of the string s can be rearranged to form a palindrome.
>>> can_form_palindrome('aabb') == True
>>> can_form_palindrome('abc') == False
>>> can_form_palindrome('aabbcc') == ... | from collections import Counter
def can_form_palindrome(s):
"""
Determines if the characters of the string s can be rearranged to form a palindrome.
A string can be rearranged to form a palindrome if at most one character has an odd count.
"""
char_count = Counter(s)
odd_count = sum(1 for ... | from solution import can_form_palindrome, magical_words_possible
def test_can_form_palindrome():
assert can_form_palindrome('aabb') == True
assert can_form_palindrome('abc') == False
assert can_form_palindrome('aabbcc') == True
assert can_form_palindrome('a') == True
assert can_form_palindrome('aa'... | [
{
"docstring": "Determines if the characters of the string s can be rearranged to form a palindrome.\n\nA string can be rearranged to form a palindrome if at most one character has an odd count.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"paramet... | [
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(s):\n \"\"\"\n Determines if a given string can be rearranged to form a palindrome.\n \"\"\"\n from collections import ... | trial_gpt4o_2 | {
"original_instruction": "In the land of Palindromeia, words are considered magical if they read the same forwards and backwards. Amy, an inhabitant of Palindromeia, enjoys creating magical words and wonders if a given string can be transformed into a palindrome by rearranging its characters. She comes to you and as... | 0.723185 | Code_Contests_21243 | C | [
"can_form_palindrome",
"magical_words_possible"
] | 2 | [
[
"magical_words_possible",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bd3ec7978031776891da554f9d5ed417a7f6df23 | 953681463794924ca7bbb30dbe6696ed83b56921 | |||
v1.0 | complete | Code_Contests | Code_Contests_21164_C | from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
""" Generate a list of all primes up to n using the Sieve of Eratosthenes.
>>> sieve_of_eratosthenes(10)
[2, 3, 5, 7]
>>> sieve_of_eratosthenes(20)
[2, 3, 5, 7, 11, 13, 17, 19]
"""
def prime_game_winner(T: int, test_cases: ... | def sieve_of_eratosthenes(n):
"""
Generate a list of all primes up to n using the Sieve of Eratosthenes.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if is_prime[p] == True:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
r... | from solution import prime_game_winner
def test_prime_game_winner():
# Test case 1
T = 2
test_cases = [10, 15]
result = prime_game_winner(T, test_cases)
assert result == ["Alice", "Bob"]
# Test case 2
T = 3
test_cases = [1, 2, 3]
result = prime_game_winner(T, test_cases)
as... | [
{
"docstring": "Generate a list of all primes up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Determine the winner of each prime game test case.",
"fun... | [
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 is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return ... | trial_gpt4o_7 | {
"original_instruction": "In the land of loops and conditions, there exists a game titled \"Prime Game,\" played by two friends, Alice and Bob. Being avid programmers, they love dealing with prime numbers. The game proceeds as follows:\n\n1. Both players have an initial integer `N`.\n2. During their turn, a player c... | 0.60468 | Code_Contests_21164 | C | [
"sieve_of_eratosthenes",
"prime_game_winner"
] | 2 | [
[
"prime_game_winner",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 891cf2338400f0c6021667fd8002c39f254584a0 | c29775e40be9fb0122e11482068c76b94eef1493 | |||
v1.0 | complete | Code_Contests | Code_Contests_20844_C | def optimal_lecture_schedule(n: int, primes: List[int]) -> Tuple[int, List[int]]:
"""
Given the number of lectures and a list of distinct prime numbers, returns the
order of prime numbers such that the sum of the differences between consecutive
primes is minimized, along with the sum of differences.
... | def schedule_lectures(primes):
"""
Given a list of distinct prime numbers, returns the order in which lectures should be scheduled such that
the sum of differences between consecutive primes is minimized.
"""
primes.sort()
return primes
# Function to be called with the input
def optimal_lecture... | from solution import optimal_lecture_schedule
def test_example1():
n = 5
primes = [3, 5, 7, 11, 13]
diff_count, optimal_order = optimal_lecture_schedule(n, primes)
assert diff_count == 4
assert optimal_order == [3, 5, 7, 11, 13]
def test_example2():
n = 3
primes = [11, 7, 3]
diff_count... | [
{
"docstring": "Given a list of distinct prime numbers, returns the order in which lectures should be scheduled such that\nthe sum of differences between consecutive primes is minimized.",
"function_declaration": "def schedule_lectures(primes):",
"function_name": "schedule_lectures",
"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 schedule_lectures(n, primes):\n \"\"\"\n Orders prime numbers such that the differences between any\n two consecutive primes are minimized.\n ... | trial_gpt4o_1 | {
"original_instruction": "Dave, an avid mathematician, is organizing a series of lectures on number theory. He has a peculiar way of planning his lectures in such a way that each lecture discusses a topic centered around a prime number. Dave wants to spread out his lectures over consecutive days, but he doesn't want... | 0.578021 | Code_Contests_20844 | C | [
"schedule_lectures",
"optimal_lecture_schedule"
] | 2 | [
[
"optimal_lecture_schedule",
"schedule_lectures"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e10ae4f3cf6a18232c6dbf0b3dc1f9a45638b01b | 78e374a640b5d7bbba6e78830d7f034f19218b5b | |||
v1.0 | complete | Code_Contests | Code_Contests_20908_C | from typing import List, Tuple
def shortest_delivery_route(n: int, m: int, connections: List[Tuple[int, int, int]]) -> int:
""" Calculate the minimum cost to start from point 1, visit all delivery points, and return to point 1.
Parameters:
n (int): Number of delivery points.
m (int): Number of dir... | import itertools
def calculate_min_cost(n, m, paths):
import sys
from itertools import permutations
# create adjacency matrix with costs as edge weights
cost = [[sys.maxsize] * (n + 1) for _ in range(n + 1)]
for u, v, w in paths:
cost[u][v] = w
cost[v][u] = w
# function to co... | from solution import shortest_delivery_route
def test_single_path():
assert shortest_delivery_route(2, 1, [(1, 2, 10)]) == 20
def test_example():
assert shortest_delivery_route(5, 7, [
(1, 2, 10),
(1, 3, 15),
(1, 4, 20),
(1, 5, 25),
(2, 5, 10),
(3, 4, 30),
... | [
{
"docstring": null,
"function_declaration": "def calculate_min_cost(n, m, paths):",
"function_name": "calculate_min_cost",
"parameter_list": "(n, m, paths)"
},
{
"docstring": null,
"function_declaration": "def shortest_delivery_route(n, m, connections):",
"function_name": "shortest_... | [
0,
0,
0,
0,
0,
1,
1,
0,
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 itertools\n\ndef tsp_dp(graph, start):\n n = len(graph)\n dp = [[float('inf')] * n for _ in range(1 << n)]\n dp[1 << start][start] = 0\n ... | trial_gpt4o_8 | {
"original_instruction": "A delivery company has a set of delivery points in a grid and needs to find the shortest path that collects all items from different points and returns to the starting point. Points are connected, and each move from one point to another has an associated cost. The company wants to know the ... | 0.693132 | Code_Contests_20908 | C | [
"calculate_min_cost",
"shortest_delivery_route"
] | 2 | [
[
"shortest_delivery_route",
"calculate_min_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4aa0440bc39f7b8c568fdf5dae4c1704694962fb | bf23a3ee745256dd502e811cff4fcd40ca5fff5c | |||
v1.0 | complete | Code_Contests | Code_Contests_21266_C | def smallest_maximum_distance(P: int, Q: int, roads: List[Tuple[int, int, int]]) -> Tuple[int, int]:
""" Given the number of cities (P) and roads (Q) with their lengths, find the optimal road to place a teleportation system to minimize the maximum travel distance between any two cities.
Args:
P: int - ... | import heapq
def floyd_warshall(n, dist):
""" Apply Floyd Warshall algorithm to find all pairs shortest paths """
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
def f... | import pytest
from solution import smallest_maximum_distance
def test_example_1():
P = 4
Q = 4
roads = [(1, 2, 3), (2, 3, 1), (3, 4, 2), (4, 1, 4)]
result = smallest_maximum_distance(P, Q, roads)
# multiple correct answers are possible
assert result in [(1, 2), (2, 3), (3, 4), (4, 1)]
def ... | [
{
"docstring": "Apply Floyd Warshall algorithm to find all pairs shortest paths ",
"function_declaration": "def floyd_warshall(n, dist):",
"function_name": "floyd_warshall",
"parameter_list": "(n, dist)"
},
{
"docstring": null,
"function_declaration": "def find_optimal_teleportation(P, Q... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef find_best_teleportation(points, edges):\n def dijkstra(start, graph):\n dist = [float('inf')] * len(graph)\n dist[star... | trial_gpt4o_3 | {
"original_instruction": "In a kingdom far, far away, there are P cities connected by Q bidirectional roads of various lengths. Every city in the kingdom can be reached from any other city directly or indirectly through a series of roads. The King has decided to build a new magic teleportation system to further impr... | 0.681908 | Code_Contests_21266 | C | [
"floyd_warshall",
"find_optimal_teleportation",
"smallest_maximum_distance"
] | 3 | [
[
"find_optimal_teleportation",
"floyd_warshall"
],
[
"smallest_maximum_distance",
"find_optimal_teleportation"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c5f41f29f78a357a715dadd1caca34446813db1e | 4709452469671ec9a8a2dd0f46cb9561ffef1c92 | |||
v1.0 | complete | Code_Contests | Code_Contests_21514_C | def categorize_heart_rate(h):
"""
Categorize the heart rate based on predefined thresholds.
>>> categorize_heart_rate(100) 'Low'
>>> categorize_heart_rate(101) 'Moderate'
>>> categorize_heart_rate(200) 'High'
>>> categorize_heart_rate(201) 'Very High'
"""
def highest_heart_rate(clients_... | def categorize_heart_rate(h):
"""
Categorize the heart rate based on predefined thresholds.
"""
if h <= 100:
return "Low"
elif 101 <= h <= 150:
return "Moderate"
elif 151 <= h <= 200:
return "High"
else:
return "Very High"
def highest_heart_rate(clients_data)... | from solution import highest_heart_rate, categorize_heart_rate
def test_categorize_heart_rate():
assert categorize_heart_rate(100) == "Low"
assert categorize_heart_rate(101) == "Moderate"
assert categorize_heart_rate(150) == "Moderate"
assert categorize_heart_rate(151) == "High"
assert categorize_h... | [
{
"docstring": "Categorize the heart rate based on predefined thresholds.",
"function_declaration": "def categorize_heart_rate(h):",
"function_name": "categorize_heart_rate",
"parameter_list": "(h)"
},
{
"docstring": "Finds the highest heart rate and its category for each client.",
"func... | [
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 categorize_heart_rate(heart_rate):\n if heart_rate <= 100:\n return 'Low'\n elif 101 <= heart_rate <= 150:\n return 'Moderate'\n ... | trial_gpt4o_2 | {
"original_instruction": "Highest Heart Rate\nDr. Fit is a fitness trainer who monitors the health data of his clients. He particularly pays attention to their heart rate data during exercise routines. Dr. Fit records the heart rate of his clients at regular intervals and wants to know the peak heart rate during eac... | 0.479433 | Code_Contests_21514 | C | [
"categorize_heart_rate",
"highest_heart_rate"
] | 2 | [
[
"highest_heart_rate",
"categorize_heart_rate"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 33783905a3e3a0663b63b00937e43b6f1f751b0d | e469e4af9385d806dee5cc8db1d56cfde7d419ed | |||
v1.0 | complete | Code_Contests | Code_Contests_20379_C | def travel_time_with_budget(input_string: str) -> int:
"""Calculate the minimum time to travel from city 1 to city n given a budget constraint.
Args:
input_string (str): Input data containing n, m, k followed by m lines of u, v, t, c.
Returns:
int: Minimum time to travel from city 1 to city n ... | import heapq
from collections import defaultdict
def min_time_to_travel(n, m, k, roads):
# Create a graph dictionary
graph = defaultdict(list)
for u, v, t, c in roads:
graph[u].append((v, t, c))
graph[v].append((u, t, c))
# Min-Heap to store (total time, current city, total cost)
h... | from solution import travel_time_with_budget
def test_example_1():
input_data = "5 7 10\n1 2 3 4\n1 3 5 2\n2 3 2 5\n2 4 6 3\n3 4 1 4\n3 5 4 6\n4 5 2 8\n"
assert travel_time_with_budget(input_data) == 9
def test_example_2():
input_data = "4 4 5\n1 2 4 3\n2 3 2 2\n3 4 3 1\n1 4 10 6\n"
assert travel_time... | [
{
"docstring": null,
"function_declaration": "def min_time_to_travel(n, m, k, roads):",
"function_name": "min_time_to_travel",
"parameter_list": "(n, m, k, roads)"
},
{
"docstring": null,
"function_declaration": "def travel_time_with_budget(input_string):",
"function_name": "travel_t... | [
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 heapq\n\ndef min_travel_time(n, m, k, roads):\n # Adjacency list for the cities\n graph = [[] for _ in range(n + 1)]\n \n for u, v, t, c... | trial_gpt4o_1 | {
"original_instruction": "In a country with n cities and m bidirectional roads, a traveler wants to move from city 1 to city n. Each road has a time (in minutes) it takes to travel from one city to another and a cost (in dollars) associated with it.\n\nThe traveler has a limited budget, k dollars, and can only use t... | 0.705043 | Code_Contests_20379 | C | [
"min_time_to_travel",
"travel_time_with_budget"
] | 2 | [
[
"travel_time_with_budget",
"min_time_to_travel"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 440b6064f9345b7d19a0a8376b2aa4debaa16cb9 | e10353d432a860c7011292cdec044465d20ab747 | |||
v1.0 | complete | Code_Contests | Code_Contests_19710_C | def process_events(event_count: int, event_list: List[Tuple[str, str]]) -> List[str]:
"""
Processes events based on their priorities.
Parameters:
event_count (int): Number of events
event_list (list): List of tuples where each tuple contains (priority, description)
Returns:
list: List of d... | def process_events(event_count, event_list):
"""
Processes events based on their priorities.
Parameters:
event_count (int): Number of events
event_list (list): List of tuples where each tuple contains (priority, description)
Returns:
list: List of descriptions of events in the order they s... | def test_process_events_example_1():
input_data = "5\nhigh ServerReboot\ncritical NetworkFailure\nmedium DiskSpaceLow\nlow DailyBackup\nhigh SecurityBreach"
expected_output = ["NetworkFailure", "ServerReboot", "SecurityBreach", "DiskSpaceLow", "DailyBackup"]
assert event_prioritization(input_data) == expect... | [
{
"docstring": "Processes events based on their priorities.\n\nParameters:\nevent_count (int): Number of events\nevent_list (list): List of tuples where each tuple contains (priority, description)\n\nReturns:\nlist: List of descriptions of events in the order they should be processed",
"function_declaration... | [
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 process_events(event_count, event_list):\n \"\"\"\n Processes events based on their priorities.\n\n Parameters:\n event_count (int): Number... | trial_gpt4o_0 | {
"original_instruction": "A new feature has been introduced in an event management system called \"event prioritization.\" Each event is assigned a priority level based on five categories: critical, high, medium, low, informational. The system processes events in queue in the order of their priorities. Events of the... | 0.533981 | Code_Contests_19710 | C | [
"process_events",
"parse_input",
"event_prioritization"
] | 3 | [
[
"event_prioritization",
"parse_input"
],
[
"event_prioritization",
"process_events"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 397e6ff373771a6b8732ef0b82c8a8e33c96d227 | 5d2cf8c807d9bb6698ae7f071b2f3b12199cffba | |||
v1.0 | complete | Code_Contests | Code_Contests_21261_C | from typing import List, Tuple
def min_steps_in_grid(T: int, test_cases: List[Tuple[int, int, List[List[str]], Tuple[int, int], Tuple[int, int]]]) -> List[int]:
""" Determine the minimum number of steps required to move from the start point to the end point in a grid.
For each test case, print the minimum ... | from collections import deque
def valid_move(x, y, M, N, grid, visited):
return 0 <= x < M and 0 <= y < N and grid[x][y] == '.' and not visited[x][y]
def min_steps_in_grid(T, test_cases):
results = []
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right
for case in test_cases:
... | def test_min_steps_in_grid():
T = 2
test_cases = [
(5, 5, [
['.', '.', '#', '.', '.'],
['.', '#', '.', '.', '.'],
['.', '#', '#', '.', '.'],
['.', '.', '.', '.', '.'],
['.', '.', '.', '#', '.'],
], (0, 0), (4, 4)),
(3, ... | [
{
"docstring": null,
"function_declaration": "def valid_move(x, y, M, N, grid, visited):",
"function_name": "valid_move",
"parameter_list": "(x, y, M, N, grid, visited)"
},
{
"docstring": null,
"function_declaration": "def min_steps_in_grid(T, test_cases):",
"function_name": "min_ste... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_reach_end(M, N, grid, start, end):\n def is_valid(x, y):\n return 0 <= x < M and 0 <= y < N and... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid of size MxN consisting of cells that are either walkable (denoted by '.') or blocked (denoted by '#'). Two points are given on this grid: the start point (Sx, Sy) and end point (Ex, Ey). You need to determine the minimum number of steps required to move from the start p... | 0.705135 | Code_Contests_21261 | C | [
"valid_move",
"min_steps_in_grid"
] | 2 | [
[
"min_steps_in_grid",
"valid_move"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | ce53d050c9b50cc9f616de104e9fcc43ce44cbed | adf186fc6ea501a210e0739d602cd4ad2d100f1a | |||
v1.0 | complete | Code_Contests | Code_Contests_21971_C | def min_path_sum_from_input(n, m, grid_data):
""" Calculate the minimum path sum in an n x m grid when starting from the top-left corner
and only being able to move down or right
Args:
n (int): number of rows in the grid
m (int): number of columns in the grid
grid_data (Lis... | def min_path_sum(grid):
n = len(grid)
m = len(grid[0])
# Initialize the dp array with the same dimensions as grid
dp = [[0] * m for _ in range(n)]
# Start with the top-left corner
dp[0][0] = grid[0][0]
# Fill the first row (can only move from the left)
for j in range(1, m)... | from solution import min_path_sum_from_input
def test_min_path_sum_case1():
assert min_path_sum_from_input(3, 3, [1, 3, 1, 1, 5, 1, 4, 2, 1]) == 7
def test_min_path_sum_case2():
assert min_path_sum_from_input(2, 2, [1, 2, 1, 1]) == 3
def test_min_path_sum_single_cell():
assert min_path_sum_from_input(1, ... | [
{
"docstring": null,
"function_declaration": "def min_path_sum(grid):",
"function_name": "min_path_sum",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def min_path_sum_from_input(n, m, grid_data):",
"function_name": "min_path_sum_from_input",
"parame... | [
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 min_path_sum(n, m, grid):\n \"\"\"\n Calculates the minimum sum of all numbers along the path from top-left to bottom-right corner of the grid.\n... | trial_gpt4o_2 | {
"original_instruction": "Johnny is trying out a new game on his phone where he needs to navigate through a grid. The grid is an n x m grid filled with non-negative integers. Johnny starts at the top-left corner (1,1) (which is position (0,0) in index programming) and he must reach the bottom-right corner (n,m) (whi... | 0.707784 | Code_Contests_21971 | C | [
"min_path_sum",
"min_path_sum_from_input"
] | 2 | [
[
"min_path_sum_from_input",
"min_path_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 53ccf25385cc50722d08c5b18a046fffe152b322 | b7dab0f8c83281f46789628eb825206dedffff6c | |||
v1.0 | complete | Code_Contests | Code_Contests_21590_C | def find_longest_word(words: List[str], s: str) -> str:
""" Given a collection of different words, find and output the longest word
that can be formed by deleting some characters of a given string `s` without
reordering the characters. If there is more than one possible longest word,
select the one t... | def is_subsequence(word, s):
it = iter(s)
return all(char in it for char in word)
def find_longest_word(words, s):
words.sort(key=lambda word: (-len(word), word))
for word in words:
if is_subsequence(word, s):
return word
return "" | from solution import find_longest_word
def test_example_case():
words = ["able", "apple", "monkey", "plea"]
s = "abpcplea"
assert find_longest_word(words, s) == "apple"
def test_no_valid_subsequence():
words = ["able", "bale", "kangaroo"]
s = "abc"
assert find_longest_word(words, s) == ""
def... | [
{
"docstring": null,
"function_declaration": "def is_subsequence(word, s):",
"function_name": "is_subsequence",
"parameter_list": "(word, s)"
},
{
"docstring": null,
"function_declaration": "def find_longest_word(words, s):",
"function_name": "find_longest_word",
"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 is_subsequence(x, s):\n \"\"\"\n Returns True if x is a subsequence of s, False otherwise.\n \"\"\"\n it = iter(s)\n return all(c in it ... | trial_gpt4o_1 | {
"original_instruction": "Time Limit: 10 sec / Memory Limit: 128 MB\n\nGiven a collection of different words, your task is to find and output the longest word that can be formed by deleting some characters of a given string `s` without reordering the characters. If there is more than one possible longest word, selec... | 0.783723 | Code_Contests_21590 | C | [
"is_subsequence",
"find_longest_word"
] | 2 | [
[
"find_longest_word",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 204c02581abbae075b671c7f3d345b6363b6eda2 | 13746d320317a66ace1413d823a4cf4fb64899d3 | |||
v1.0 | complete | Code_Contests | Code_Contests_21755_C | def min_coins(n, amount, coins):
""" Calculate the minimum number of coins needed to make up a given amount
with an infinite supply of coins of given denominations.
>>> min_coins(3, 11, [1, 2, 5])
3
>>> min_coins(2, 7, [2, 4])
-1
>>> min_coins(5, 23, [2, 5, 10, 1, 2])
4
"""
de... | def min_coins(n, amount, coins):
max_val = amount + 1
dp = [max_val] * (amount + 1)
dp[0] = 0
for coin in coins:
for x in range(coin, amount + 1):
dp[x] = min(dp[x], dp[x - coin] + 1)
return dp[amount] if dp[amount] != max_val else -1
def find_min_coins(datasets):
... | import pytest
from solution import parse_input_and_solve
def test_sample_case():
input_str = "3\n3 11\n1 2 5\n2 7\n2 4\n5 23\n2 5 10 1 2\n"
expected_output = "3\n-1\n4"
assert parse_input_and_solve(input_str) == expected_output
def test_single_coin():
input_str = "1\n1 10\n1\n"
expected_output = "... | [
{
"docstring": null,
"function_declaration": "def min_coins(n, amount, coins):",
"function_name": "min_coins",
"parameter_list": "(n, amount, coins)"
},
{
"docstring": null,
"function_declaration": "def find_min_coins(datasets):",
"function_name": "find_min_coins",
"parameter_lis... | [
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 min_coins(t, datasets):\n def find_min_coins(coins, amount):\n dp = [float('inf')] * (amount + 1)\n dp[0] = 0\n \n for c... | trial_gpt4o_2 | {
"original_instruction": "Write a program that calculates the minimum number of coins needed to make up a given amount with an infinite supply of coins of given denominations. Your solution should find the minimum coin count for each amount in a series of input datasets. If it is not possible to make up the amount w... | 0.650061 | Code_Contests_21755 | C | [
"min_coins",
"find_min_coins",
"parse_input_and_solve"
] | 3 | [
[
"find_min_coins",
"min_coins"
],
[
"parse_input_and_solve",
"find_min_coins"
]
] | 2 | [
"parse_input_and_solve"
] | false | [] | false | pytest | true | [] | true | 9a3ed36c82a6f08c23ef51d45cf9cdc658f9fb00 | 4ae6cc502339b33c21d3e0d8459f2210aae70578 | |||
v1.0 | complete | Code_Contests | Code_Contests_21837_C | def max_complete_rows(N: int) -> int:
""" Given a number of flower pots N, returns the maximum number of rows
that can be completely filled such that each row has an incremental
number of flower pots starting from 1.
>>> max_complete_rows(7)
3
>>> max_complete_rows(10)
4
>>> max_c... | def max_complete_rows(N):
"""
Given a number of flower pots N, returns the maximum number of rows
that can be completely filled such that each row has an incremental
number of flower pots starting from 1.
"""
# The total number of pots needed for filling x rows is the sum of the first x natura... | from solution import max_complete_rows, max_rows_for_cases
def test_max_complete_rows():
assert max_complete_rows(7) == 3
assert max_complete_rows(10) == 4
assert max_complete_rows(1) == 1
assert max_complete_rows(15) == 5
assert max_complete_rows(6) == 3
assert max_complete_rows(0) == 0
as... | [
{
"docstring": "Given a number of flower pots N, returns the maximum number of rows \nthat can be completely filled such that each row has an incremental \nnumber of flower pots starting from 1.",
"function_declaration": "def max_complete_rows(N):",
"function_name": "max_complete_rows",
"parameter_l... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_complete_rows(N):\n \"\"\"\n Given a number of flower pots N, returns the maximum number of rows \n that can be completely filled such tha... | trial_gpt4o_0 | {
"original_instruction": "Amara is a gardener and loves to arrange her flower pots in a specific fashion. She wants to arrange the pots such that the number of flower pots in each row is strictly increasing by one from the previous row. For instance, if the first row has 1 flower pot, the second row should have 2 fl... | 0.603734 | Code_Contests_21837 | C | [
"max_complete_rows",
"max_rows_for_cases",
"solve"
] | 3 | [
[
"max_rows_for_cases",
"max_complete_rows"
],
[
"solve",
"max_rows_for_cases"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1361c6ceaceb2158c8ffbf629afc0310f004f5fa | ff0e82fe4136c56d0153dd22bf69cba4ea7f9e88 | |||
v1.0 | complete | Code_Contests | Code_Contests_22586_C | def prime_factors(n):
"""
Return the set of distinct prime factors of n.
"""
pass
def sum_of_distinct_prime_factors(A, B):
"""
Return the sum of all distinct prime factors of A^B.
Pass
"""
pass
def games_sum_prime_factors(T, test_cases):
"""
Calculate the sum of all distin... | def prime_factors(n):
"""
Return the set of distinct prime factors of n.
"""
i = 2
factors = set()
while i * i <= n:
while (n % i) == 0:
factors.add(i)
n //= i
i += 1
if n > 1:
factors.add(n)
return factors
def sum_of_distinct_prime_factor... | def test_prime_factors():
assert prime_factors(12) == {2, 3}
assert prime_factors(15) == {3, 5}
assert prime_factors(7) == {7}
assert prime_factors(1) == set()
def test_sum_of_distinct_prime_factors():
assert sum_of_distinct_prime_factors(12, 2) == 5
assert sum_of_distinct_prime_factors(15, 3) ... | [
{
"docstring": "Return the set of distinct prime factors of n.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Return the sum of all distinct prime factors of A^B.",
"function_declaration": "def sum_of_distin... | [
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 math\n\ndef distinct_prime_factors(n):\n primes = set()\n if n % 2 == 0:\n primes.add(2)\n while n % 2 == 0:\n n //= ... | trial_gpt4o_4 | {
"original_instruction": "Alice and Bob love playing games that involve numbers. Recently, they have come up with a new game that involves prime factors. The rules are simple: given two numbers `A` and `B`, they need to find the sum of all distinct prime factors of `A^B`.\n\nFor example, if `A` is 12 and `B` is 2, t... | 0.644657 | Code_Contests_22586 | C | [
"prime_factors",
"sum_of_distinct_prime_factors",
"games_sum_prime_factors"
] | 3 | [
[
"games_sum_prime_factors",
"sum_of_distinct_prime_factors"
],
[
"sum_of_distinct_prime_factors",
"prime_factors"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d1c94cd1a2a53a67bc3f5c660ded24749e41a8c6 | 540f4fb9491926aa25fabad95db3601a36956e00 | |||
v1.0 | complete | Code_Contests | Code_Contests_21608_C | def find_median(dataset):
"""
Finds the median of a list of non-negative integers.
If the list has an even number of elements, it returns the integer average of the two middle values.
"""
def median_of_datasets(input_lines):
"""
Processes multiple datasets input and returns the median value... | def find_median(dataset):
"""
Finds the median of a list of non-negative integers.
If the list has an even number of elements, it returns the integer average of the two middle values.
"""
sorted_ds = sorted(dataset)
n = len(sorted_ds)
if n % 2 == 1: # odd length
return sorted_d... | from solution import find_median, median_of_datasets, process_input
def test_find_median_odd_length():
assert find_median([1, 3, 3, 6, 7, 8, 9]) == 6
def test_find_median_even_length():
assert find_median([7, 8, 3, 6, 1, 9]) == 6
def test_find_median_two_elements():
assert find_median([1, 2]) == 1
def t... | [
{
"docstring": "Finds the median of a list of non-negative integers.\nIf the list has an even number of elements, it returns the integer average of the two middle values.",
"function_declaration": "def find_median(dataset):",
"function_name": "find_median",
"parameter_list": "(dataset)"
},
{
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_median(arr):\n \"\"\"\n Given a list of non-negative integers, returns the median.\n If the list length is even, returns the average of t... | trial_gpt4o_2 | {
"original_instruction": "Create a program that reads a list of non-negative integers and outputs the median value. If the list has an even number of integers, the median is defined as the average of the two middle elements (you may assume the integer division and result will still be an integer). Each integer in th... | 0.751841 | Code_Contests_21608 | C | [
"find_median",
"median_of_datasets",
"process_input"
] | 3 | [
[
"median_of_datasets",
"find_median"
],
[
"process_input",
"median_of_datasets"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | af887fb17145f8b990ad378b1f29754239ecca1b | 295a47f2d3b5e4ac568ebfbb87b46cf85d5f6710 | |||
v1.0 | complete | Code_Contests | Code_Contests_22792_C | def mod_comb(n, k, mod=10**9 + 7):
"""
Calculate n choose k (nCk) modulo mod.
"""
pass
def number_of_paths(N, M):
"""
Calculate the number of distinct paths from (1, 1) to (N, M) on a N x M grid.
"""
pass
def process_test_cases(test_cases):
"""
Process test cases to determine t... | def mod_comb(n, k, mod=10**9 + 7):
"""
Calculate n choose k (nCk) modulo mod.
"""
if k > n - k:
k = n - k
num = 1
den = 1
for i in range(k):
num = num * (n - i) % mod
den = den * (i + 1) % mod
return num * pow(den, mod - 2, mod) % mod
def number_of_paths(N, M):
... | from solution import process_test_cases
def test_case_1():
assert process_test_cases([(2, 2)]) == [2]
def test_case_2():
assert process_test_cases([(3, 2)]) == [3]
def test_multiple_cases():
assert process_test_cases([(2, 2), (3, 2), (4, 3)]) == [2, 3, 10]
def test_case_large():
assert process_test_... | [
{
"docstring": "Calculate n choose k (nCk) modulo mod.",
"function_declaration": "def mod_comb(n, k, mod=10 ** 9 + 7):",
"function_name": "mod_comb",
"parameter_list": "(n, k, mod=10 ** 9 + 7)"
},
{
"docstring": "Calculate the number of distinct paths from (1, 1) to (N, M) on a N x M grid.",... | [
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": "def number_of_paths(N, M):\n MOD = 10**9 + 7\n \n # Calculate factorials and factorial inverses modulo MOD\n fact = [1] * (N + M)\n inv_fact... | trial_gpt4o_4 | {
"original_instruction": "You have been hired by an amusement park to develop a simulation for one of their new attractions: a robotic boat ride. The ride consists of a rectangular grid of cells, where each cell represents a distinct position in the water. At the start of the ride, the boat is positioned at the top-... | 0.676781 | Code_Contests_22792 | C | [
"mod_comb",
"number_of_paths",
"process_test_cases"
] | 3 | [
[
"number_of_paths",
"mod_comb"
],
[
"process_test_cases",
"number_of_paths"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 7eedc97213bc7669f74b2c10fd2d14a159f0ba3f | 1ca642058fa134374a67d17a9c2b114250a5e72c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.