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 | instruct | Code_Contests | Code_Contests_35741_I | The mayor of a small town wants to organize a series of events to celebrate the town's anniversary. The main event will be a series of connected parades, moving from one venue to another. Each venue can be considered a node, and the roads connecting them are edges in an undirected graph. The mayor wants to ensure that ... | from itertools import permutations
def is_hamiltonian_cycle(n, edges):
if n <= 1:
return True
adj_list = {i: set() for i in range(1, n + 1)}
for u, v in edges:
adj_list[u].add(v)
adj_list[v].add(u)
for perm in permutations(range(1, n + 1)):
valid = True
... | from solution import can_form_hamiltonian_cycle
def test_example_1():
n = 4
m = 4
edge_list = ["1 2", "2 3", "3 4", "4 1"]
assert can_form_hamiltonian_cycle(n, m, edge_list) == "Yes"
def test_example_2():
n = 4
m = 3
edge_list = ["1 2", "2 3", "3 1"]
assert can_form_hamiltonian_cycle(n... | [
{
"docstring": null,
"function_declaration": "def is_hamiltonian_cycle(n, edges):",
"function_name": "is_hamiltonian_cycle",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def can_form_hamiltonian_cycle(n, m, edge_list):",
"function_name": "can_form_h... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef is_hamiltonian_cycle(n, edges):\n if n <= 1:\n return True\n \n adj_list = {i: set() for i in ran... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035741",
"row_id": 35741,
"seed_ids": "[4518]"
} | 0.628587 | Code_Contests_35741 | I | [
"is_hamiltonian_cycle",
"can_form_hamiltonian_cycle"
] | 2 | [
[
"can_form_hamiltonian_cycle",
"is_hamiltonian_cycle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6f9b50c6e4ed64ab3150da8ef665398dfab4330 | 62795ac0dd6028ee7902416d867c5f9b52fc88e8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35763_I | Amanda is solving a problem relating to binary trees. She needs to find the maximum depth of a binary tree. The depth of a binary tree is the number of nodes along the longest path from the root node down to the farthest leaf node.
Help Amanda by writing a function that computes the maximum depth of a binary tree.
Yo... | from typing import List, Optional
from collections import deque
class TreeNode:
def __init__(self, val: Optional[int]):
self.val = val
self.left = None
self.right = None
def build_tree(level_order: List[Optional[int]]) -> Optional[TreeNode]:
if not level_order:
return None
... | from solution import max_depth
def test_empty_tree():
assert max_depth([]) == 0
def test_single_node():
assert max_depth([1]) == 1
def test_two_levels():
assert max_depth([1, 2, 3]) == 2
def test_unbalanced_tree():
assert max_depth([1, None, 2, None, 3]) == 3
def test_balanced_tree():
assert ma... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Optional\nfrom collections import deque\n\ndef max_depth(tree: List[Optional[int]]) -> int:\n if not tree or tree[0] is None:\n... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00035763",
"row_id": 35763,
"seed_ids": "[3710]"
} | 0.606492 | Code_Contests_35763 | I | [
"build_tree",
"max_depth"
] | 2 | [
[
"max_depth",
"build_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | fd2529d5958237bb3903d256313f9c7fc4c6fb5b | 1687ab9709ca51ad79755e1e346dbfc0fc36316e | |||
v1.0 | instruct | Code_Contests | Code_Contests_35779_I | In a certain country, there are n cities and m roads connecting some pairs of cities. Every road has an associated cost, which represents the fee travelers have to pay to use it. The government of the country wants to ensure that it is possible to travel between any two cities, but they also want to minimize the total ... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | from solution import kruskal_min_cost
def test_min_cost_case1():
n, m = 4, 5
edges = [
(1, 2, 3),
(1, 3, 2),
(2, 3, 4),
(3, 4, 1),
(2, 4, 5)
]
assert kruskal_min_cost(n, edges) == 6
def test_min_cost_case2():
n, m = 3, 3
edges = [
(1, 2, 1),
... | [
{
"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,
1,
1
] | 3 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00035779",
"row_id": 35779,
"seed_ids": "[9019]"
} | 0.779463 | Code_Contests_35779 | I | [
"find",
"union",
"kruskal_min_cost"
] | 3 | [
[
"kruskal_min_cost",
"find"
],
[
"kruskal_min_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 9dddb89e9ce906ad8e13475767ddd4eb95505380 | ac3c2b4206b2de5b6e04d716a1d54ddc1af24d2f | |||
v1.0 | instruct | Code_Contests | Code_Contests_35894_I | ### Problem Statement
Jiro has a rectangular grid of size H x W, where each cell of the grid contains a letter. He can perform the following operation any number of times:
- Select two adjacent cells (either vertically or horizontally) and swap their letters.
He would like to form a palindrome from the letters in th... | def is_palindromic_grid_possible(grid, H, W):
"""
Determines if it's possible to rearrange the grid into a palindromic grid.
:param grid: 2D list of characters representing the grid.
:param H: height of the grid.
:param W: width of the grid.
:return: tuple (bool, list_of_swaps). If possible, ret... | def test_palindromic_grid_basic():
grid = [
list('aba'),
list('aba'),
list('aba')
]
result = palindromic_grid(3, 3, grid)
assert result == ['YES', '0']
def test_palindromic_grid_with_swaps():
grid = [
list('abcc'),
list('bccb'),
list('abcc')
]
... | [
{
"docstring": "Determines if it's possible to rearrange the grid into a palindromic grid.\n:param grid: 2D list of characters representing the grid.\n:param H: height of the grid.\n:param W: width of the grid.\n:return: tuple (bool, list_of_swaps). If possible, return (True, swaps_list). Otherwise, (False, [])... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindromic_grid_possible(grid, H, W):\n \"\"\"\n Determines if it's possible to rearrange the grid into a palindromic grid.\n :param grid:... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035894",
"row_id": 35894,
"seed_ids": "[7893]"
} | 0.772128 | Code_Contests_35894 | I | [
"is_palindromic_grid_possible",
"palindromic_grid",
"read_input",
"main"
] | 4 | [
[
"palindromic_grid",
"is_palindromic_grid_possible"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 3522daa08bea7a611eb5421b848aee3ce9f95215 | 53e63a399e846053f6ca88ac34bf2c4f192485b3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35956_I | Aliens and Palindromes
Aliens from the planet Zog love palindromes. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward (ignoring spaces, punctuation, and capitalization). The Zog scientists have developed a special sequence of integers and want to find the l... | def is_palindrome(arr):
"""
This function checks if the input array is a palindrome.
"""
return arr == arr[::-1]
def longest_palindrome_subarray_length(arr):
"""
This function finds the length of the longest contiguous subarray
that forms a palindrome.
"""
n = len(arr)
max_leng... | from solution import longest_palindrome_subarray_length, solve
def test_single_element_array():
assert longest_palindrome_subarray_length([1]) == 1
def test_entire_array_palindrome():
assert longest_palindrome_subarray_length([1, 2, 3, 2, 1]) == 5
def test_no_palindromes():
assert longest_palindrome_suba... | [
{
"docstring": "This function checks if the input array is a palindrome.",
"function_declaration": "def is_palindrome(arr):",
"function_name": "is_palindrome",
"parameter_list": "(arr)"
},
{
"docstring": "This function finds the length of the longest contiguous subarray \nthat forms a palind... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_subarray(arr):\n \"\"\"\n Returns the length of the longest palindromic subarray in the given array.\n \"\"\"\n n = len... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035956",
"row_id": 35956,
"seed_ids": "[5925]"
} | 0.689118 | Code_Contests_35956 | I | [
"is_palindrome",
"longest_palindrome_subarray_length",
"solve"
] | 3 | [
[
"longest_palindrome_subarray_length",
"is_palindrome"
],
[
"solve",
"longest_palindrome_subarray_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 81fa2a4f87ca185be8690190797f248abd6c2415 | cd53f9bea8355cc0a4795a0877af3627191dc39c | |||
v1.0 | instruct | Code_Contests | Code_Contests_35959_I | A popular card game involves an initial shuffle of a deck of 52 cards, followed by repeated drawing and shuffling in a particular pattern. Each card in the deck is identified by its suit and rank. The suits are denoted by "H" (Hearts), "D" (Diamonds), "S" (Spades), and "C" (Clubs), and the ranks range from 2 to 10, J, ... | import random
from collections import deque
def max_cards_drawn(deck):
def draw_card(deck, card):
hand = [card]
queue = deque([card])
while queue:
current = queue.popleft()
next_cards = [c for c in deck if c[0] == current[0] or c[1] == current[1]]
for nex... | from solution import max_cards_drawn_in_each_round, process_input
def test_single_card():
input_string = "1\n1\n3D"
test_cases = process_input(input_string)
result = max_cards_drawn_in_each_round(test_cases)
assert result == [1]
def test_no_matching_cards():
input_string = "1\n4\n2H JD 4C 7C"
... | [
{
"docstring": null,
"function_declaration": "def max_cards_drawn(deck):",
"function_name": "max_cards_drawn",
"parameter_list": "(deck)"
},
{
"docstring": null,
"function_declaration": "def max_cards_drawn_in_each_round(test_cases):",
"function_name": "max_cards_drawn_in_each_round"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\nimport random\n\ndef max_cards_drawn(m, deck):\n \"\"\"\n Returns the maximum number of cards that can be drawn ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035959",
"row_id": 35959,
"seed_ids": "[541]"
} | 0.674391 | Code_Contests_35959 | I | [
"max_cards_drawn",
"max_cards_drawn_in_each_round",
"process_input"
] | 3 | [
[
"max_cards_drawn_in_each_round",
"max_cards_drawn"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | a3b2017d82ec18fc71b5c6b047988cbfbad8f556 | 2d736f22c39c3df2e6a4952846931bc1d8bc6e5c | |||
v1.0 | instruct | Code_Contests | Code_Contests_35964_I | You are given a 2D grid of size N x M consisting of cells marked with either '1' or '0'. A cell marked with '1' is walkable, while a cell marked with '0' is not walkable. You start at the top-left corner (0, 0) and want to reach the bottom-right corner (N-1, M-1). You can only move right or down from a cell. Determine ... | def num_paths(grid):
if grid[0][0] == '0' or grid[-1][-1] == '0':
return 0
N = len(grid)
M = len(grid[0])
dp = [[0] * M for _ in range(N)]
dp[0][0] = 1
for i in range(N):
for j in range(M):
if grid[i][j] == '1':
if i > 0:
... | from solution import find_num_paths
def test_3x3_grid():
grid = [
"1 1 1",
"1 0 1",
"1 1 1"
]
assert find_num_paths(3, 3, grid) == 2
def test_2x2_grid():
grid = [
"1 0",
"1 1"
]
assert find_num_paths(2, 2, grid) == 1
def test_no_paths():
grid = [
... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_num_paths(N, M, grid_lines):",
"function_name": "find_num_paths",
"parameter_list": "(N, M, grid... | [
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 num_paths(grid):\n \"\"\"\n Returns the number of distinct paths from the top-left corner to the bottom-right corner\n of a given grid.\n \... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035964",
"row_id": 35964,
"seed_ids": "[285]"
} | 0.809762 | Code_Contests_35964 | I | [
"num_paths",
"find_num_paths"
] | 2 | [
[
"find_num_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 250ef0f524b0f9e81b53935d310d54e04c9c1e2c | 25ee793314ef1fe39989689414830b1f22219666 | |||
v1.0 | instruct | Code_Contests | Code_Contests_35965_I | Given a series of lowercase words, your mission is to find the longest common prefix among them. The input consists of lines, each containing a space-separated list of words. The input terminates with a line containing a single dash ('-'). For each list of words, your program should output the longest common prefix. If... | def longest_common_prefix(words):
"""
Finds the longest common prefix among a list of words.
If there is no common prefix, returns an empty string.
"""
if not words:
return ""
prefix = words[0]
for word in words[1:]:
while word[:len(prefix)] != prefix and prefix:
... | from solution import process_input_lines, longest_common_prefix
def test_longest_common_prefix():
assert longest_common_prefix(['flower', 'flow', 'flight']) == 'fl'
assert longest_common_prefix(['dog', 'racecar', 'car']) == ''
assert longest_common_prefix(['reflow', 'reform', 'refund']) == 'ref'
assert... | [
{
"docstring": "Finds the longest common prefix among a list of words.\nIf there is no common prefix, returns an empty string.",
"function_declaration": "def longest_common_prefix(words):",
"function_name": "longest_common_prefix",
"parameter_list": "(words)"
},
{
"docstring": "Processes mul... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_common_prefix(words):\n \"\"\"\n Finds the longest common prefix among a list of words.\n If there is no common prefix, returns an emp... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00035965",
"row_id": 35965,
"seed_ids": "[12068]"
} | 0.796244 | Code_Contests_35965 | I | [
"longest_common_prefix",
"process_input_lines"
] | 2 | [
[
"process_input_lines",
"longest_common_prefix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3885b8d66c5dbc57a9a53300626e11a18692662a | e36b6e48c41462a9a9eac61972ea2005ef3db29c | |||
v1.0 | instruct | Code_Contests | Code_Contests_36044_I | Ahmed is fascinated with strings and their beauty. He defines the beauty of a string as the length of the longest substring in which all characters are distinct. Ahmed wants your help in figuring out the beauty of multiple strings.
Given a list of strings, determine the beauty of each string.
### Input
- The first l... | def longest_unique_substring_length(s):
"""
Returns the length of the longest substring with all distinct characters in the given string s.
"""
char_index = {}
max_length = 0
start = 0
for i, char in enumerate(s):
if char in char_index and char_index[char] >= start:
... | from solution import process_input, longest_unique_substring_length
def test_longest_unique_substring_length():
assert longest_unique_substring_length("abcabcbb") == 3
assert longest_unique_substring_length("bbbbb") == 1
assert longest_unique_substring_length("pwwkew") == 3
assert longest_unique_substr... | [
{
"docstring": "Returns the length of the longest substring with all distinct characters in the given string s.",
"function_declaration": "def longest_unique_substring_length(s):",
"function_name": "longest_unique_substring_length",
"parameter_list": "(s)"
},
{
"docstring": "Returns a list o... | [
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 beauty_of_string(s):\n \"\"\"\n Function to determine the beauty of a string, defined as the length of the longest substring \n in which all c... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036044",
"row_id": 36044,
"seed_ids": "[8788]"
} | 0.786951 | Code_Contests_36044 | I | [
"longest_unique_substring_length",
"beauty_of_strings",
"process_input"
] | 3 | [
[
"beauty_of_strings",
"longest_unique_substring_length"
],
[
"process_input",
"beauty_of_strings"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | c2f043af06c57452ea488285902bd9126ea55780 | e53c0eb5a6aa0ca795439f503b0e8c2a680214d7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36045_I | You are given an array of integers and a set of update operations. Each update operation involves incrementing a range of elements in the array by a specified value. After performing all the updates, you need to answer multiple queries that ask for the sum of elements within a specific subrange of the array.
Input
Th... | def increment_range(array, l, r, x):
"""
Increments all elements in the range [l, r] by x.
"""
for i in range(l-1, r):
array[i] += x
def range_sum(array, l, r):
"""
Returns the sum of elements in the range [l, r].
"""
return sum(array[l-1:r])
def process_operations(n, q, array,... | import pytest
from solution import increment_range, range_sum, process_operations
def test_increment_range():
array = [1, 2, 3, 4, 5]
increment_range(array, 1, 3, 10)
assert array == [11, 12, 13, 4, 5]
def test_range_sum():
array = [1, 2, 3, 4, 5]
assert range_sum(array, 1, 1) == 1
assert rang... | [
{
"docstring": "Increments all elements in the range [l, r] by x.",
"function_declaration": "def increment_range(array, l, r, x):",
"function_name": "increment_range",
"parameter_list": "(array, l, r, x)"
},
{
"docstring": "Returns the sum of elements in the range [l, r].",
"function_dec... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ArrayOperations:\n def __init__(self, n, array):\n self.n = n\n self.array = array\n self.diff = [0] * (n + 1)\n \n def... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036045",
"row_id": 36045,
"seed_ids": "[10269]"
} | 0.667602 | Code_Contests_36045 | I | [
"increment_range",
"range_sum",
"process_operations"
] | 3 | [
[
"process_operations",
"increment_range"
],
[
"process_operations",
"range_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7375f1d93459d6f9a5ec50f423e28353164ca82a | 8e287d32ac5ab00103a4fbcfa74260846d60b7fd | |||
v1.0 | instruct | Code_Contests | Code_Contests_36066_I | Alice is building a security system that only grants access when a correct password sequence is detected within an entered string. A correct password sequence is composed of the following conditions:
1. The sequence must start with a prime number with exactly 3 digits (for example, 101, 103, etc.).
2. The sequence dir... | def is_prime(n):
"""Returns True if n is a prime number, False otherwise."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6... | from solution import find_valid_sequences, process_input
def test_is_prime():
assert is_prime(101) == True
assert is_prime(103) == True
assert is_prime(100) == False
assert is_prime(1) == False
def test_is_palindrome():
assert is_palindrome("a") == True
assert is_palindrome("ab") == False
... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns True if s is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(s):... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036066",
"row_id": 36066,
"seed_ids": "[8426]"
} | 0.654736 | Code_Contests_36066 | I | [
"is_prime",
"is_palindrome",
"find_valid_sequences",
"process_input"
] | 4 | [
[
"find_valid_sequences",
"is_palindrome"
],
[
"find_valid_sequences",
"is_prime"
],
[
"process_input",
"find_valid_sequences"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 4e69ace42aa9da02cb2d7f6a844ab4554e2d3b76 | e9179c6cd7f0feaccdea95abd58649b2d8085df1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36095_I | In a faraway land, there exists a grid of dimensions n x n, consisting of cells. Each cell can either be empty (represented by a '.') or contain an obstacle (represented by an 'X'). You, as the brave knight, can move through this grid, starting from the top-left corner (1,1) to the bottom-right corner (n,n). However, y... | def max_transformations(grid, T):
n = len(grid)
# dp table to store the maximum number of transformations we can meet at each cell
dp = [[-1] * n for _ in range(n)]
# Base case
dp[0][0] = T[0][0] if grid[0][0] == '.' else -1
# DP computation
for i in range(n):
for j in range(n)... | def test_example_case():
n = 4
grid = [
"....",
".X..",
"..X.",
"...."
]
T = [
[0, 0, 1, 1],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 1]
]
assert solve(n, grid, T) == 0
def test_no_obstacles():
n = 3
grid = [
"...",
... | [
{
"docstring": null,
"function_declaration": "def max_transformations(grid, T):",
"function_name": "max_transformations",
"parameter_list": "(grid, T)"
},
{
"docstring": null,
"function_declaration": "def solve(n, grid, T):",
"function_name": "solve",
"parameter_list": "(n, grid,... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_transformations(grid, T):\n n = len(grid)\n dp = [[float('inf')] * n for _ in range(n)]\n dp[0][0] = T[0][0] if grid[0][0] == '.' else flo... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00036095",
"row_id": 36095,
"seed_ids": "[9416]"
} | 0.720255 | Code_Contests_36095 | I | [
"max_transformations",
"solve"
] | 2 | [
[
"solve",
"max_transformations"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f4bc6c7eedf9c20a136beda4d03fed699ea5fb35 | bf3a7687a5b628b9bc438ac78112170f5ed100ed | |||
v1.0 | instruct | Code_Contests | Code_Contests_36097_I | ```markdown
Given a string S containing only lowercase alphabets. You have to determine the minimum number of characters to delete to make S a palindrome.
A palindrome is a string that reads the same backward as forward.
Note:
- You must delete characters to get the resulting string as the longest possible palindrome... | def longest_palindromic_subsequence_length(s):
n = len(s)
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if s[i] == s[j] and cl == 2:
dp[i][j] = 2
... | def test_longest_palindromic_subsequence_length():
from solution import longest_palindromic_subsequence_length
assert longest_palindromic_subsequence_length("bbbab") == 4
assert longest_palindromic_subsequence_length("cbbd") == 2
assert longest_palindromic_subsequence_length("a") == 1
assert longest... | [
{
"docstring": null,
"function_declaration": "def longest_palindromic_subsequence_length(s):",
"function_name": "longest_palindromic_subsequence_length",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def min_deletions_to_make_palindrome(s):",
"function_name... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_deletions_to_palindrome(s: str) -> int:\n \"\"\"\n Returns the minimum number of deletions required to make s a palindrome.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036097",
"row_id": 36097,
"seed_ids": "[1118]"
} | 0.817509 | Code_Contests_36097 | I | [
"longest_palindromic_subsequence_length",
"min_deletions_to_make_palindrome",
"process_test_cases",
"main"
] | 4 | [
[
"min_deletions_to_make_palindrome",
"longest_palindromic_subsequence_length"
],
[
"process_test_cases",
"min_deletions_to_make_palindrome"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 5990ca751d862b616ad31088e770acae0a82f151 | a03d10f6460bc8af71890a83ecd4a47aaa834c35 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36126_I | Balanced String Check
In a software development company, programmers often encounter a type of well-known challenge: handling parenthesis and bracket balancing in strings. A balanced string is a string with a matching opening and closing pair for each type of parentheses and brackets.
Your task is to write a function... | def is_balanced(string):
"""
Determines if a string with parentheses and brackets is balanced.
Parameters:
string (str): The input string containing parentheses and brackets.
Returns:
str: 'YES' if the string is balanced, 'NO' otherwise.
"""
stack = []
matching_brackets = {... | from solution import is_balanced, check_balanced_strings
def test_is_balanced_valid_cases():
assert is_balanced("(){}[]") == 'YES'
assert is_balanced("({[]})") == 'YES'
assert is_balanced("{[()]}") == 'YES'
def test_is_balanced_invalid_cases():
assert is_balanced("({[}])") == 'NO'
assert is_balanc... | [
{
"docstring": "Determines if a string with parentheses and brackets is balanced.\n\nParameters:\nstring (str): The input string containing parentheses and brackets.\n\nReturns:\nstr: 'YES' if the string is balanced, 'NO' otherwise.",
"function_declaration": "def is_balanced(string):",
"function_name": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_balanced(s):\n \"\"\"\n Determine if the input string s is a balanced string of parentheses and brackets.\n \"\"\"\n stack = []\n map... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036126",
"row_id": 36126,
"seed_ids": "[4367]"
} | 0.705492 | Code_Contests_36126 | I | [
"is_balanced",
"check_balanced_strings"
] | 2 | [
[
"check_balanced_strings",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70555d06971c4d5bdd210455cfe27b6ee6868eea | c900c0c9b5bb2d27ab9855bcd53bbe37db51efaa | |||
v1.0 | instruct | Code_Contests | Code_Contests_36234_I | Sophia is studying number theory and is particularly interested in prime numbers. One day, she encountered a challenging problem related to the sum of prime numbers in a given range.
You are given a range defined by two integers L and R. Sophia wants to find the sum of all prime numbers between L and R (inclusive).
A... | def generate_primes_up_to(n):
"""
Returns a list of prime numbers up to n
"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(n**0.5) + 1):
if is_prime[start]:
for multiple in range(start*start, n + 1, start):
is_pr... | from solution import process_test_cases
def test_case_1():
assert process_test_cases(1, [(1, 10)]) == [17]
def test_case_2():
assert process_test_cases(1, [(11, 19)]) == [60]
def test_case_3():
assert process_test_cases(1, [(20, 30)]) == [52]
def test_case_4():
assert process_test_cases(3, [(1, 10),... | [
{
"docstring": "Returns a list of prime numbers up to n",
"function_declaration": "def generate_primes_up_to(n):",
"function_name": "generate_primes_up_to",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers between L and R (inclusive)",
"function_declaration": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes_up_to(n):\n \"\"\"\n Returns a list of prime numbers up to n\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0] = is_p... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036234",
"row_id": 36234,
"seed_ids": "[8333]"
} | 0.61637 | Code_Contests_36234 | I | [
"generate_primes_up_to",
"sum_primes_in_range",
"sum_primes_in_ranges",
"process_test_cases"
] | 4 | [
[
"process_test_cases",
"sum_primes_in_ranges"
],
[
"sum_primes_in_ranges",
"generate_primes_up_to"
],
[
"sum_primes_in_ranges",
"sum_primes_in_range"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 6d6c39a3a46f978cb75c1a294ce81a4ccb1f5aec | 68ea997c13c77e77a54a6255666a3ba3862c5ff8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36245_I | You are given a list of tasks that need to be scheduled on a single CPU machine. Each task has a duration, and some tasks must be performed before others. Create a program to find the minimum amount of time required to finish all tasks.
Each task is represented by a unique identifier and its duration. The dependencies... | from collections import defaultdict, deque
def find_minimum_time(n, m, tasks, dependencies):
# Create a task duration map
task_duration = {}
for task in tasks:
task_id, duration = task
task_duration[task_id] = duration
# Create adjacency list and in-degree map
adj_list = defaultdic... | def test_example_1():
input_data = """5 4
1 3
2 2
3 4
4 6
5 8
1 2
2 3
3 4
4 5"""
assert minimum_time_to_complete_all_tasks(input_data) == 23
def test_example_2():
input_data = """3 1
1 5
2 10
3 3
1 2"""
assert minimum_time_to_complete_all_tasks(input_data) == 15
def test_no_dependencies():
input_d... | [
{
"docstring": null,
"function_declaration": "def find_minimum_time(n, m, tasks, dependencies):",
"function_name": "find_minimum_time",
"parameter_list": "(n, m, tasks, dependencies)"
},
{
"docstring": null,
"function_declaration": "def minimum_time_to_complete_all_tasks(input_data):",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef min_time_to_finish(tasks, dependencies):\n # Create a graph and in-degree count based on dependencies\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036245",
"row_id": 36245,
"seed_ids": "[13002]"
} | 0.762247 | Code_Contests_36245 | I | [
"find_minimum_time",
"minimum_time_to_complete_all_tasks"
] | 2 | [
[
"minimum_time_to_complete_all_tasks",
"find_minimum_time"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 94ac72ed13211b04f6b07e7830db62d800690d80 | 22d23e3f2c0d33968e51a4d45f5287f83e288d68 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36273_I | There is a unique game played in Gridland in which players need to traverse a grid filled with various obstacles. The grid is of size `n x m`, and some cells contain obstacles that make them inaccessible. The player starts from the top-left corner of the grid and needs to reach the bottom-right corner. The player can m... | def unique_paths_with_obstacles(grid):
n = len(grid)
m = len(grid[0])
# If starting point or ending point is an obstacle, return 0
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
# Initialize a 2D dp array with 0s
dp = [[0] * m for _ in range(n)]
# Starting poi... | from solution import number_of_unique_paths
def test_paths_with_obstacles():
assert number_of_unique_paths(3, 3, ['. . .', '. # .', '. . .']) == 2
assert number_of_unique_paths(3, 3, ['. # .', '# . #', '. # .']) == 0
assert number_of_unique_paths(2, 2, ['. .', '. .']) == 2
assert number_of_unique_paths... | [
{
"docstring": null,
"function_declaration": "def unique_paths_with_obstacles(grid):",
"function_name": "unique_paths_with_obstacles",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_unique_paths(n, m, grid):",
"function_name": "number_of_uni... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths(grid):\n n = len(grid)\n m = len(grid[0])\n \n # If the start or end is an obstacle, return 0 immediately\n if grid[0][0] =... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036273",
"row_id": 36273,
"seed_ids": "[4214]"
} | 0.78822 | Code_Contests_36273 | I | [
"unique_paths_with_obstacles",
"number_of_unique_paths"
] | 2 | [
[
"number_of_unique_paths",
"unique_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eb7224bf4076ca88619436972cb73b862d57f00e | e4119378aea6749a63e62fcf09a245ed8d239ed2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36276_I | You are given a string representing a chemical equation. The string consists of alphanumeric characters and symbols indicating elements, quantities, reactants, and products. The equation follows the traditional format: `Reactants -> Products`, where each element is represented by its chemical symbol (e.g., H for Hydrog... | import re
from collections import defaultdict
def parse_chemical_formula(formula: str):
"""
Parse a chemical formula into a dictionary of elements and their counts.
Args:
formula (str): A string representing the chemical formula.
Returns:
dict: A dictionary with elements as keys and t... | from solution import is_chemical_equation_balanced
def test_balanced_equation():
assert is_chemical_equation_balanced('H2 + O2 -> H2O') == None # Expected to print "Balanced"
def test_unbalanced_equation():
assert is_chemical_equation_balanced('C2H6 + O2 -> CO2 + H2O') == None # Expected to print "Unbalance... | [
{
"docstring": "Parse a chemical formula into a dictionary of elements and their counts.\n\nArgs:\nformula (str): A string representing the chemical formula.\n\nReturns:\ndict: A dictionary with elements as keys and their counts as values.",
"function_declaration": "def parse_chemical_formula(formula):",
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import re\nfrom collections import defaultdict\n\ndef parse_compound(compound):\n \"\"\"Parse a chemical compound to return a d... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00036276",
"row_id": 36276,
"seed_ids": "[9105]"
} | 0.574464 | Code_Contests_36276 | I | [
"parse_chemical_formula",
"parse_equation",
"is_chemical_equation_balanced"
] | 3 | [
[
"is_chemical_equation_balanced",
"parse_equation"
],
[
"parse_equation",
"parse_chemical_formula"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f5996d07146e761ce065d04c19e2f7214d361cf6 | f3522c1a7c289a15b1a4f613c58481ebf1508304 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36298_I | You are given a sequence of n integers (a_1, a_2, ..., a_n) and a list of m queries. Each query is represented as a pair of integers l and r (1 ≤ l ≤ r ≤ n). To answer a query, you need to find the sum of all integers in the subsequence (a_l, a_{l+1}, ..., a_r). Write a program to efficiently handle multiple queries on... | def preprocess(prefix_sums, sequence):
"""
Fill the prefix_sums array where prefix_sums[i] is the sum of all elements
from the beginning of the sequence up to and including index i-1.
"""
for i in range(1, len(sequence) + 1):
prefix_sums[i] = prefix_sums[i - 1] + sequence[i - 1]
def query_s... | from solution import preprocess, query_sum, process_queries
def test_preprocess():
sequence = [1, 2, 3, 4, 5]
prefix_sums = [0] * (len(sequence) + 1)
preprocess(prefix_sums, sequence)
assert prefix_sums == [0, 1, 3, 6, 10, 15]
def test_query_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert que... | [
{
"docstring": "Fill the prefix_sums array where prefix_sums[i] is the sum of all elements\nfrom the beginning of the sequence up to and including index i-1.",
"function_declaration": "def preprocess(prefix_sums, sequence):",
"function_name": "preprocess",
"parameter_list": "(prefix_sums, sequence)"... | [
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 prefix_sum(arr):\n \"\"\"\n Function to compute prefix sums of the provided array.\n \"\"\"\n n = len(arr)\n prefix = [0] * (n+1)\n f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036298",
"row_id": 36298,
"seed_ids": "[6268]"
} | 0.725393 | Code_Contests_36298 | I | [
"preprocess",
"query_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"preprocess"
],
[
"process_queries",
"query_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 8c4184eccfefa42590b2319cd5c0306d8d70a79e | 0d1f0084b54272a82b2329bda13d0edc10966197 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36437_I | Kenneth recently encountered a unique problem while developing an AI algorithm. He needs to manipulate a given array of integers according to a set of operations to achieve the maximum sum of all elements in the array. He is allowed to perform the following operations exactly once on the entire array:
1. Choose two el... | def max_sum_after_operations(T, test_cases):
results = []
for i in range(T):
n, arr = test_cases[i]
max_sum = sum(arr)
# Since replacing or reversing doesn't change the sum, the maximum sum after
# operation will still be the sum of the array.
resu... | from solution import solve
def test_case_1():
T = 2
test_cases = [(3, [1, -2, 3]), (4, [-1, -3, 4, 2])]
results = solve(T, test_cases)
assert results == [2, 2]
def test_case_2():
T = 1
test_cases = [(5, [1, -1, 1, -1, 1])]
results = solve(T, test_cases)
assert results == [1]
def test_... | [
{
"docstring": null,
"function_declaration": "def max_sum_after_operations(T, test_cases):",
"function_name": "max_sum_after_operations",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def solve(T, test_cases):",
"function_name": "solve",
"pa... | [
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_possible_sum(T, test_cases):\n results = []\n \n for i in range(T):\n n = test_cases[i][0]\n array = test_cases[i][1]\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036437",
"row_id": 36437,
"seed_ids": "[11736]"
} | 0.734715 | Code_Contests_36437 | I | [
"max_sum_after_operations",
"solve"
] | 2 | [
[
"solve",
"max_sum_after_operations"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 791ab9009954f2c43d22db47c584c11b7de9ed7f | 847f206df7b8ed07e99fac754f48c58ac4d51e3e | |||
v1.0 | instruct | Code_Contests | Code_Contests_36475_I | A word ladder is a puzzle where you must convert a starting word to an ending word by changing one letter at a time, with each intermediate word being a valid word in the given dictionary. Each step must result in a valid word and you can only change one letter at a time.
Input
First line contains two space-separated ... | from collections import deque
def word_ladder(start, end, dictionary):
"""
Returns the minimum number of steps to convert start to end using the given dictionary.
Each step changes one letter and resulting word must be in the dictionary.
If the conversion is not possible, returns -1.
"""
if end... | from solution import word_ladder, get_input_and_solve
def test_example_case():
input_string = "hit cog\n6\nhot dot dog lot log cog"
output = get_input_and_solve(input_string)
assert output == 5
def test_impossible_case():
input_string = "hit cog\n4\nhot dot dog log"
output = get_input_and_solve(in... | [
{
"docstring": "Returns the minimum number of steps to convert start to end using the given dictionary.\nEach step changes one letter and resulting word must be in the dictionary.\nIf the conversion is not possible, returns -1.",
"function_declaration": "def word_ladder(start, end, dictionary):",
"funct... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef word_ladder(start, end, dictionary):\n if end not in dictionary:\n return -1\n\n word_set = set(dictionar... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00036475",
"row_id": 36475,
"seed_ids": "[10937]"
} | 0.525525 | Code_Contests_36475 | I | [
"word_ladder",
"get_input_and_solve"
] | 2 | [
[
"get_input_and_solve",
"word_ladder"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3953e21977adeb966e4c85daceb12333bd7b333 | 4589166706c5c4fbd6d574314d9911280a165c93 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36483_I | You are given two strings: `S` (the text) and `P` (the pattern). Your task is to find all the starting indices of the pattern `P` in the text `S`. You need to implement a function that searches for occurrences of the pattern in the text using the Knuth-Morris-Pratt (KMP) algorithm, which should work efficiently even fo... | def KMP_search(S, P):
"""
KMP algorithm to find all starting indices of pattern P in text S.
"""
# Function to create the longest proper prefix which is also suffix array
def compute_lps_array(P):
lps = [0] * len(P)
length = 0 # length of the previous longest prefix suffix
i... | def test_find_pattern_indices():
from solution import find_pattern_indices
# Redirect stdout
import io
import sys
captured_output = io.StringIO()
sys.stdout = captured_output
# Test cases
find_pattern_indices("ababcababcabc", "abc")
assert captured_output.getvalue().strip() == ... | [
{
"docstring": "KMP algorithm to find all starting indices of pattern P in text S.",
"function_declaration": "def KMP_search(S, P):",
"function_name": "KMP_search",
"parameter_list": "(S, P)"
},
{
"docstring": null,
"function_declaration": "def find_pattern_indices(S, P):",
"function... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def KMP_search(S, P):\n \"\"\"\n KMP algorithm to find all starting indices of pattern P in text S.\n \"\"\"\n # Function to create the longest... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036483",
"row_id": 36483,
"seed_ids": "[1353]"
} | 0.629585 | Code_Contests_36483 | I | [
"KMP_search",
"find_pattern_indices"
] | 2 | [
[
"find_pattern_indices",
"KMP_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b370993dd69b79a9e3bdec956f2f1c379c37f0cd | 001ea782c82a66464fef59753c4e35148e9b27d1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36486_I | In a faraway kingdom, there are $N$ unique magical potions and $M$ bi-directional magical pathways connecting them. Each pathway connects two potions, and traveling through a pathway for a certain amount of time allows the traveler to consume the effects of all potions connected through the pathway. The magic intensity... | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif rank[ro... | def test_example_1():
input_str = "3 3 1\n1 2 2\n2 3 3\n1 3 4\n"
assert solve_problem(input_str) == 4
def test_example_2():
input_str = "4 4 2\n1 2 5\n2 3 3\n3 4 7\n4 1 10\n"
assert solve_problem(input_str) == 10
def test_example_3():
input_str = "5 5 5\n1 2 1\n2 3 2\n3 4 3\n4 5 4\n5 1 5\n"
as... | [
{
"docstring": null,
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, u, v):",
"function_name": "union",
"parameter_list": "(parent, rank, u, v)"
},
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef maximum_intensity(N, M, S, pathways):\n graph = {i: [] for i in range(1, N + 1)}\n for u, v, c in pathways:\n graph[u].app... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00036486",
"row_id": 36486,
"seed_ids": "[7182]"
} | 0.588298 | Code_Contests_36486 | I | [
"find",
"union",
"maximum_intensity_elixir",
"solve_problem"
] | 4 | [
[
"maximum_intensity_elixir",
"find"
],
[
"maximum_intensity_elixir",
"union"
],
[
"solve_problem",
"maximum_intensity_elixir"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 754307d133b08cd054dbeca64db6f1dade0c6e6b | 3062c233083c9cc32506d5a71ee4f565d8a6e79f | |||
v1.0 | instruct | Code_Contests | Code_Contests_36490_I | You are given a tree with n nodes, rooted at node 1. The nodes are numbered from 1 to n. Each node i has a value vi. A tree is a connected acyclic graph.
A query is a pair (u, k) which means you need to find the k-th smallest value in the subtree of node u. The subtree of a node u is the set of all nodes that have u a... | from collections import defaultdict
import bisect
def dfs(node, parent, adj_list, node_values, subtree_nodes):
"""
Performs a depth-first search to collect all nodes in each subtree.
"""
subtree_nodes[node].append(node_values[node-1])
for neighbor in adj_list[node]:
if neighbor != parent:
... | from solution import dfs, kth_smallest_in_subtree, process_queries
def test_dfs():
n = 5
node_values = [5, 1, 4, 2, 3]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
adj_list = defaultdict(list)
for u, v in edges:
adj_list[u].append(v)
adj_list[v].append(u)
subtree_nodes = defaultdict... | [
{
"docstring": "Performs a depth-first search to collect all nodes in each subtree.",
"function_declaration": "def dfs(node, parent, adj_list, node_values, subtree_nodes):",
"function_name": "dfs",
"parameter_list": "(node, parent, adj_list, node_values, subtree_nodes)"
},
{
"docstring": "Re... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef dfs_subtree(node, parent, tree, values, subtree_values):\n subtree_values[node].append(values[node-1])... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036490",
"row_id": 36490,
"seed_ids": "[8683]"
} | 0.731573 | Code_Contests_36490 | I | [
"dfs",
"kth_smallest_in_subtree",
"process_queries"
] | 3 | [
[
"process_queries",
"dfs"
],
[
"process_queries",
"kth_smallest_in_subtree"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | e383c7d25c202d644cd81f634d0704c1c4863903 | ada63c6ac3524f080eaac5677fca9833a10033be | |||
v1.0 | instruct | Code_Contests | Code_Contests_36501_I | Martha is very interested in botany and has recently become fascinated with the structure of trees. She learned that every tree can be uniquely represented as an undirected acyclic graph. She is interested in finding two particular nodes in a tree, which she will call x and y, such that the distance between x and y is ... | from collections import deque, defaultdict
def bfs(farthest_node_start, n, graph):
visited = [-1] * (n + 1)
queue = deque([farthest_node_start])
visited[farthest_node_start] = 0
farthest_node = farthest_node_start
max_distance = 0
while queue:
node = queue.popleft()
current... | def test_max_distance_in_tree():
edges1 = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert max_distance_in_tree(5, edges1) == 3
edges2 = [(1, 2), (1, 3), (3, 4), (3, 5), (4, 6)]
assert max_distance_in_tree(6, edges2) == 4
edges3 = [(1, 2), (2, 3), (3, 4), (4, 5)]
assert max_distance_in_tree(5, edges3) ... | [
{
"docstring": null,
"function_declaration": "def bfs(farthest_node_start, n, graph):",
"function_name": "bfs",
"parameter_list": "(farthest_node_start, n, graph)"
},
{
"docstring": null,
"function_declaration": "def max_distance_in_tree(n, edges):",
"function_name": "max_distance_in... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs_farthest_node(start, graph):\n \"\"\"\n Perform BFS to find the farthest node from the starting node and its... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036501",
"row_id": 36501,
"seed_ids": "[11573]"
} | 0.692315 | Code_Contests_36501 | I | [
"bfs",
"max_distance_in_tree"
] | 2 | [
[
"max_distance_in_tree",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9f69c141dbbc859771d908adc28b5c10d445ba84 | b78aafa38edfd349c485737efca8eb766a193b6c | |||
v1.0 | instruct | Code_Contests | Code_Contests_36533_I | Alyssa loves encryption and challenges her friends with puzzles. She invented a simple encryption technique based on shifting characters in a string. Given a string and an integer 'k', she shifts each character in the string by 'k' positions to the right where the alphabet wraps around (i.e., 'z' followed by 'a'). She ... | def shift_character(char, k):
"""
Shift a character by k positions in the alphabet.
"""
return chr((ord(char) - ord('a') + k) % 26 + ord('a'))
def encrypt_string(s, k):
"""
Encrypt the string by shifting each character by k positions.
"""
return ''.join(shift_character(char, k) for char... | from solution import process_cases, parse_input
def test_encrypt_string():
cases = [
("abc", 2),
("xyz", 1),
("hello", 3)
]
expected = [
"cde",
"yza",
"khoor"
]
assert process_cases(cases) == expected
def test_parser_and_processor():
input_data =... | [
{
"docstring": "Shift a character by k positions in the alphabet.",
"function_declaration": "def shift_character(char, k):",
"function_name": "shift_character",
"parameter_list": "(char, k)"
},
{
"docstring": "Encrypt the string by shifting each character by k positions.",
"function_decl... | [
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 encrypt_string(s, k):\n \"\"\"\n Encrypts the string s by shifting each character k positions to the right.\n The alphabet wraps around so tha... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036533",
"row_id": 36533,
"seed_ids": "[1740]"
} | 0.755873 | Code_Contests_36533 | I | [
"shift_character",
"encrypt_string",
"process_cases",
"parse_input"
] | 4 | [
[
"encrypt_string",
"shift_character"
],
[
"process_cases",
"encrypt_string"
]
] | 2 | [
"process_cases",
"parse_input"
] | false | [] | false | pytest | true | [] | true | 109b307e2649440faee72b133144c2bd2d3efd7c | b997eef1e1a2b6f5da64c6893b6de7272109a6a8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36547_I | You are given a grid with dimensions n x m, where each cell contains a positive integer. You need to perform a number of operations on this grid. In each operation, you will be given a starting cell and a target cell, and you need to find the sum of all numbers within the rectangle defined by these two cells (inclusive... | def preprocess_grid(grid):
"""
Preprocess the grid to create a sum matrix for efficient query.
Args:
- grid: 2D list of integers representing the grid.
Returns:
- sum_matrix: 2D list of integers representing the sum matrix.
"""
n = len(grid) # Number of rows
m = len(grid[0]) # Nu... | import pytest
from solution import preprocess_grid, query_sum, sum_in_rectangles
def test_preprocess_grid():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
sum_matrix = preprocess_grid(grid)
expected_sum_matrix = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
... | [
{
"docstring": "Preprocess the grid to create a sum matrix for efficient query.\n\nArgs:\n- grid: 2D list of integers representing the grid.\n\nReturns:\n- sum_matrix: 2D list of integers representing the sum matrix.",
"function_declaration": "def preprocess_grid(grid):",
"function_name": "preprocess_gr... | [
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_grid(grid, n, m):\n \"\"\"Preprocess the grid to generate cumulative sum table.\"\"\"\n cumulative_grid = [[0] * (m + 1) for _ in rang... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036547",
"row_id": 36547,
"seed_ids": "[1182]"
} | 0.64704 | Code_Contests_36547 | I | [
"preprocess_grid",
"query_sum",
"sum_in_rectangles"
] | 3 | [
[
"sum_in_rectangles",
"preprocess_grid"
],
[
"sum_in_rectangles",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5457c9864c64c8c6f60b3740b634ab14f9159a05 | a08aff90f007a703b33b9ca74b5ce6815e811b05 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36581_I | Ana is creating a rectangular grid composed of lowercase letters from 'a' to 'z'. She wants to make sure that no two cells in the same row or the same column contain the same letter. Additionally, each subgrid (3x4) must only contain unique letters.
Write a program that reads multiple datasets and verifies Ana's grid ... | def check_valid_grid(grid):
rows, cols = len(grid), len(grid[0])
# Check rows and columns
for r in range(rows):
row_letters = set()
for c in range(cols):
if grid[r][c] in row_letters:
return r, c, grid[r][c]
row_letters.add(grid[r][c])
fo... | def test_valid_grid():
datasets = [
[
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l']
]
]
results = validate_datasets(datasets)
assert results == [[
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l... | [
{
"docstring": null,
"function_declaration": "def check_valid_grid(grid):",
"function_name": "check_valid_grid",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def validate_datasets(datasets):",
"function_name": "validate_datasets",
"parameter_list": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_grid(n, datasets):\n def is_valid_grid(grid):\n rows, cols = len(grid), len(grid[0])\n \n # Check rows and columns\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036581",
"row_id": 36581,
"seed_ids": "[4257]"
} | 0.696364 | Code_Contests_36581 | I | [
"check_valid_grid",
"validate_datasets",
"format_output"
] | 3 | [
[
"validate_datasets",
"check_valid_grid"
]
] | 1 | [
"format_output"
] | false | [] | false | pytest | false | [] | true | b75ebd78aa7433668f45c9a39f2d83bc6d86e72a | 5dc49202a4a3d4820d352c2409f0572806c25320 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36586_I | Aman is fascinated by patterns in numbers. He recently stumbled upon a sequence problem and wants to automate the process of finding the sequence for a given set of numbers. As Aman is still learning programming, he seeks your assistance.
The sequence is defined as follows:
Starting from an integer n (n ≥ 1), the next... | def reverse_number(n):
return int(str(n)[::-1])
def is_palindrome(n):
return str(n) == str(n)[::-1]
def iterations_to_palindrome(n):
for i in range(1001):
if is_palindrome(n):
return i
n += reverse_number(n)
return -1
def sequence_iterations(numbers):
return [iteration... | from solution import reverse_number, is_palindrome, iterations_to_palindrome, sequence_iterations
def test_reverse_number():
assert reverse_number(123) == 321
assert reverse_number(400) == 4
assert reverse_number(789) == 987
def test_is_palindrome():
assert is_palindrome(121) is True
assert is_pal... | [
{
"docstring": null,
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docst... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_iterations_to_palindrome(n):\n \"\"\"\n Given an integer n, finds the number of iterations required to reach a palindrome\n by repeatedly... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036586",
"row_id": 36586,
"seed_ids": "[11525]"
} | 0.687048 | Code_Contests_36586 | I | [
"reverse_number",
"is_palindrome",
"iterations_to_palindrome",
"sequence_iterations"
] | 4 | [
[
"iterations_to_palindrome",
"is_palindrome"
],
[
"iterations_to_palindrome",
"reverse_number"
],
[
"sequence_iterations",
"iterations_to_palindrome"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fc823c99a4b0c364080eb208d8607cb002c74f96 | c2088da9d32cd7a08bfdfea6107b75ce2dedeec5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36639_I | Write a program that helps you to verify if your Sudoku solution is correct.
A Sudoku puzzle consists of a 9x9 grid, divided into nine 3x3 subgrids. The objective is to fill the grid with numbers from 1 to 9 so that each row, each column, and each 3x3 subgrid contains all nine digits.
Your task is to write a program ... | def is_valid_sudoku(grid):
def is_valid_block(block):
return sorted(block) == list(range(1, 10))
def get_column(grid, col_idx):
return [grid[row_idx][col_idx] for row_idx in range(9)]
def get_subgrid(grid, start_row, start_col):
return [grid[r][c] for r in range(start_row, ... | from solution import is_valid_sudoku, sudoku_validator
def test_valid_sudoku():
grid = [
[5, 3, 4, 6, 7, 8, 9, 1, 2],
[6, 7, 2, 1, 9, 5, 3, 4, 8],
[1, 9, 8, 3, 4, 2, 5, 6, 7],
[8, 5, 9, 7, 6, 1, 4, 2, 3],
[4, 2, 6, 8, 5, 3, 7, 9, 1],
[7, 1, 3, 9, 2, 4, 8, 5, 6],
... | [
{
"docstring": null,
"function_declaration": "def is_valid_sudoku(grid):",
"function_name": "is_valid_sudoku",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def sudoku_validator(T, grids):",
"function_name": "sudoku_validator",
"parameter_list": "(T,... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_sudoku(grid):\n def is_valid_block(block):\n return sorted(block) == list(range(1, 10))\n \n for i in range(9):\n row =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036639",
"row_id": 36639,
"seed_ids": "[11756]"
} | 0.734891 | Code_Contests_36639 | I | [
"is_valid_sudoku",
"sudoku_validator"
] | 2 | [
[
"sudoku_validator",
"is_valid_sudoku"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 618d13cad7528fd63f47b76b6dfb50bbb813b9f1 | 004875978dd914f0489a184f9fd917fd641d3f07 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36700_I | A network of computers is represented as an undirected graph with n nodes and m edges. Each node is uniquely identified by an integer from 1 to n. Write a program to determine the minimum number of computers that need to be infected initially to ensure that all computers in the network become infected given that if a c... | def find_connected_components(n, connections):
from collections import defaultdict, deque
graph = defaultdict(list)
for u, v in connections:
graph[u].append(v)
graph[v].append(u)
visited = [False] * (n + 1)
components = 0
def bfs(start):
queue = deque([star... | from solution import min_initial_infected
def test_min_initial_infected_example_1():
n = 6
connections = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
assert min_initial_infected(n, connections) == 1
def test_min_initial_infected_example_2():
n = 7
connections = [(1, 2), (2, 3), (4, 5), (6, 7)]
ass... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(n, connections):",
"function_name": "find_connected_components",
"parameter_list": "(n, connections)"
},
{
"docstring": null,
"function_declaration": "def min_initial_infected(n, connections):",
"function_nam... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_initial_infections(n, edges):\n \"\"\"\n Determines the minimum number of computers that need to be infected initially\n to ensure that al... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036700",
"row_id": 36700,
"seed_ids": "[5247]"
} | 0.605142 | Code_Contests_36700 | I | [
"find_connected_components",
"min_initial_infected"
] | 2 | [
[
"min_initial_infected",
"find_connected_components"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c51fe499c8cc90472a3cdf18f35ea119677f12a | 5a9a5dbd457fcdd989ac79d3f0b58aa44a40f174 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36714_I | A group of delivery drones needs to deliver packages to various destinations. Each drone has a limited battery capacity and a fixed rate of battery consumption per kilometer. Given the initial battery charge of the drone, its consumption rate, and a list of destinations it must reach, determine the minimum number of st... | from math import sqrt
from collections import deque
def distance(x1, y1, x2, y2):
return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_recharges(d, c, k, destinations, recharge_stations):
initial_battery = c
current_position = (0, 0)
current_battery = initial_battery
recharges = 0
destina... | from solution import minimum_recharges
def test_case_1():
d = 3
c = 50
k = 1
destinations = [(10, 10, 20), (20, 5, 30), (15, 15, 10)]
recharge_stations = [(5, 5), (25, 10)]
assert minimum_recharges(d, c, k, destinations, recharge_stations) == 1
def test_case_2():
d = 2
c = 100
k = ... | [
{
"docstring": null,
"function_declaration": "def distance(x1, y1, x2, y2):",
"function_name": "distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def minimum_recharges(d, c, k, destinations, recharge_stations):",
"function_name": "minimu... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.hypot(x2 - x1, y2 - y1)\n\ndef min_recharges_to_complete_deliveries(d, c, k, destin... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00036714",
"row_id": 36714,
"seed_ids": "[12069]"
} | 0.60081 | Code_Contests_36714 | I | [
"distance",
"minimum_recharges"
] | 2 | [
[
"minimum_recharges",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c39bf34e8878f8c0bb921f4485bb6854bf3662c4 | cbdfa69af0231b8f11d7ed39cbbc0f2bafe53adc | |||
v1.0 | instruct | Code_Contests | Code_Contests_36731_I | A chef is planning to open a new restaurant chain and wants to make sure that the seating capacity of each restaurant meets the local regulations. The seating capacity is determined by various seating areas: tables, booths, and bar stools. Each area has a different seat allocation, and they must all fit within the rest... | class SeatingArea:
def __init__(self, name, number_of_seats):
self.name = name
self.number_of_seats = number_of_seats
class Restaurant:
def __init__(self, name, width, height):
self.name = name
self.width = width
self.height = height
self.seating_areas = {}
... | def test_seating_capacity_example_case():
n = 7
instructions = [
"Restaurant main_dining(20,20)",
"Table t1(4)",
"Booth b1(6)",
"Stool s1(2)",
"main_dining.add_seating(t1,5,5)",
"main_dining.add_seating(b1,5,5)",
"main_dining.add_seating(s1,2,2)"
]
... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class SeatingArea:\n def __init__(self, name, number_of_seats):\n self.name = name\n self.number_of_seats = number_of_seats\n\n\nclass Res... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036731",
"row_id": 36731,
"seed_ids": "[9540]"
} | 0.665857 | Code_Contests_36731 | I | [
"parse_instruction",
"seating_capacity"
] | 2 | [
[
"seating_capacity",
"parse_instruction"
]
] | 1 | [] | false | [
"SeatingArea",
"Restaurant"
] | true | pytest | false | [] | true | 1ea6c130f2de55de7bcea5ddb4e93e606b11f82c | a2e0f034aa6eaa10390bb7bc8821118b81c1a5ac | |||
v1.0 | instruct | Code_Contests | Code_Contests_36784_I | Given a matrix of size M x N consisting of only 0s and 1s, write a program that finds the maximum size square sub-matrix with all 1s and returns its area.
### Input:
Two integers M and N, representing the dimensions of the matrix.
Following M lines contain N space-separated integers, each representing the elements of... | def max_square_submatrix_area(matrix):
"""
Finds the maximum size square sub-matrix with all 1s and returns its area.
:param matrix: List of List of integers (0s and 1s)
:return: Integer representing the area of the largest square sub-matrix with all 1s
"""
if not matrix or not matrix[0]:
... | import pytest
from solution import max_square_submatrix_area, max_square_submatrix_area_from_input
def test_max_square_submatrix_area():
matrix1 = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert max_square_submatrix_area(matrix1) == 4
m... | [
{
"docstring": "Finds the maximum size square sub-matrix with all 1s and returns its area.\n\n:param matrix: List of List of integers (0s and 1s)\n:return: Integer representing the area of the largest square sub-matrix with all 1s",
"function_declaration": "def max_square_submatrix_area(matrix):",
"func... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximal_square_area(matrix):\n if not matrix or not matrix[0]:\n return 0\n\n M, N = len(matrix), len(matrix[0])\n # Initialize a dp ar... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036784",
"row_id": 36784,
"seed_ids": "[6109]"
} | 0.682475 | Code_Contests_36784 | I | [
"max_square_submatrix_area",
"max_square_submatrix_area_from_input"
] | 2 | [
[
"max_square_submatrix_area_from_input",
"max_square_submatrix_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 558a7d70b4489e2406313f00ea16753381b55f58 | 09405e60e490af1a7430c30dd3eebad470f89f17 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36803_I | You are given a 2D grid of size n x m, where each cell contains a lowercase English letter. Your task is to find the length of the shortest word that can be formed by traversing this grid starting from any cell. The rule for traversal is that you can move to an adjacent cell (up, down, left, right) if the letter in tha... | def bfs(grid, start):
from collections import deque
n = len(grid)
m = len(grid[0])
q = deque([start])
visited = set()
visited.add(start)
length = 1
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while q:
x, y = q.popleft()
for dx, dy in directions:... | from solution import shortest_word_length, parse_input_data
def test_single_cell_grid():
input_data = "1 1\na"
grid = parse_input_data(input_data)
assert shortest_word_length(grid) == 1
def test_simple_grid():
input_data = "3 3\nabc\ndef\nghi"
grid = parse_input_data(input_data)
assert shortes... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, start):",
"function_name": "bfs",
"parameter_list": "(grid, start)"
},
{
"docstring": null,
"function_declaration": "def shortest_word_length(grid):",
"function_name": "shortest_word_length",
"parameter_list": "(grid)"
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_word_length(n, m, grid):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n def bfs(start_i, sta... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00036803",
"row_id": 36803,
"seed_ids": "[374]"
} | 0.725428 | Code_Contests_36803 | I | [
"bfs",
"shortest_word_length",
"parse_input_data"
] | 3 | [
[
"shortest_word_length",
"bfs"
]
] | 1 | [
"parse_input_data"
] | false | [] | false | pytest | true | [] | true | 583e99c88cd75dbc1523f36366917e8193e1105f | 3c15d819858bab9d36ba51a9e35a5b5cf8913516 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36834_I | In the magical forest of Zog, there are N mystical creatures, each residing in their own lair. Some of these lairs are connected by enchanted trails that can only be traversed in one direction, specified by the sorcerer's decree. Due to a recent surge in dark magic, communication between creatures has become crucial to... | from collections import defaultdict, deque
def kosaraju_sccs(n, graph):
def dfs1(v):
visited.add(v)
for u in graph[v]:
if u not in visited:
dfs1(u)
stack.append(v)
def dfs2(v):
component.append(v)
visited.add(v)
for u in reverse_g... | import pytest
from solution import minimum_portals
def test_minimum_portals_1():
assert minimum_portals(4, [(1, 2), (2, 3)]) == 2
def test_minimum_portals_2():
assert minimum_portals(5, [(1, 2), (2, 3), (3, 1), (4, 5), (5, 4)]) == 2
def test_minimum_portals_fully_connected():
assert minimum_portals(3, [(... | [
{
"docstring": null,
"function_declaration": "def kosaraju_sccs(n, graph):",
"function_name": "kosaraju_sccs",
"parameter_list": "(n, graph)"
},
{
"docstring": null,
"function_declaration": "def minimum_portals(n, trails):",
"function_name": "minimum_portals",
"parameter_list": "... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef min_portals_needed(N, T, trails):\n def kosaraju_scc(n, trails):\n g = defaultdict(list)\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00036834",
"row_id": 36834,
"seed_ids": "[1568]"
} | 0.541318 | Code_Contests_36834 | I | [
"kosaraju_sccs",
"minimum_portals",
"main"
] | 3 | [
[
"minimum_portals",
"kosaraju_sccs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 677f2a355d3c21061272775ef1c200370331efd3 | a2633fd8ab388ff687b4e89a2d60f15e8e915504 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36893_I | In a rectangular grid, you start at the top-left corner and at each step, you can move right or down. You need to navigate to the bottom-right corner of the grid. Given some cells marked as obstacles, find the number of distinct paths from the top-left to the bottom-right corner that do not cross any obstacle.
Input
... | def count_paths(n, m, obstacles):
"""
Returns the number of distinct paths from the top-left to the bottom-right
corner of the grid, avoiding obstacles.
"""
grid = [[0] * m for _ in range(n)]
if (1, 1) in obstacles or (n, m) in obstacles:
return 0
grid[0][0] = 1
for i i... | def test_count_paths_no_obstacles():
input_str = "2 2\n0"
assert grid_paths(input_str) == 2
def test_count_paths_with_obstacle():
input_str = "3 3\n1\n2 2"
assert grid_paths(input_str) == 2
def test_count_paths_obstacle_at_start():
input_str = "3 3\n1\n1 1"
assert grid_paths(input_str) == 0
d... | [
{
"docstring": "Returns the number of distinct paths from the top-left to the bottom-right\ncorner of the grid, avoiding obstacles.",
"function_declaration": "def count_paths(n, m, obstacles):",
"function_name": "count_paths",
"parameter_list": "(n, m, obstacles)"
},
{
"docstring": null,
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths_with_obstacles(n, m, k, obstacles):\n # Initialize the grid with 0s\n grid = [[0] * m for _ in range(n)]\n\n # Mark the obstacles... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036893",
"row_id": 36893,
"seed_ids": "[2653]"
} | 0.778264 | Code_Contests_36893 | I | [
"count_paths",
"parse_input",
"grid_paths"
] | 3 | [
[
"grid_paths",
"count_paths"
],
[
"grid_paths",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 4190e718491686dc8d252c4423b6977508029ccb | c6e5502567fba975c7693481dc714f0c6a1cd40c | |||
v1.0 | instruct | Code_Contests | Code_Contests_36918_I | A company is organizing a team-building event for its employees. Each employee can form a team with any other employee if they share at least one common skill. The team's strength is determined by the number of unique skills possessed by the team members.
Your task is to find out the maximum team strength that can be ... | def max_team_strength(n, skill_sets):
"""
Returns the maximum possible team strength by selecting two employees.
:param n: Number of employees
:param skill_sets: A list of sets, each containing the skill IDs of each employee
:return: Maximum possible team strength
"""
max_strength = 0
... | from solution import calculate_max_team_strength
def test_example_1():
n = 3
employees_skills = [
[3, 1, 2, 3],
[3, 2, 4, 5],
[2, 3, 5]
]
assert calculate_max_team_strength(n, employees_skills) == 5
def test_example_2():
n = 4
employees_skills = [
[2, 1, 2],
... | [
{
"docstring": "Returns the maximum possible team strength by selecting two employees.\n\n:param n: Number of employees\n:param skill_sets: A list of sets, each containing the skill IDs of each employee\n:return: Maximum possible team strength",
"function_declaration": "def max_team_strength(n, skill_sets):... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_team_strength(n, employees):\n \"\"\"\n Returns the maximum team strength by selecting two employees which\n is determined by the number o... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036918",
"row_id": 36918,
"seed_ids": "[6554]"
} | 0.728686 | Code_Contests_36918 | I | [
"max_team_strength",
"calculate_max_team_strength"
] | 2 | [
[
"calculate_max_team_strength",
"max_team_strength"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 851984770b8cfd232a202bee0e46798565d7936f | 803893eaa134a5da56f7a58c74d9ce64bbaac68f | |||
v1.0 | instruct | Code_Contests | Code_Contests_36930_I | Your task is to write a program that reads a sequence of non-negative integers and computes the sum of all primes up to but not including the number 100. The input ends when you read a number that is either negative or greater than or equal to 100. Use a function to check for the primality of each number. All numbers a... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sum_of_prim... | from solution import is_prime, sum_of_primes
# Tests for is_prime
def test_is_prime():
assert is_prime(2)
assert not is_prime(1)
assert not is_prime(0)
assert is_prime(11)
assert not is_prime(4)
assert not is_prime(10)
assert is_prime(17)
assert not is_prime(98)
# Tests for sum_of_prim... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the input list that are less than 100.",
"function_declaration": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036930",
"row_id": 36930,
"seed_ids": "[3094]"
} | 0.604642 | Code_Contests_36930 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fcf0561a381fecc3eb288f1a88349eabefdc527a | 09f35c97e7c3273f92cab1e4518616b6b6514aa9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_36994_I | Sophie is training for a coding competition and is practicing problems involving number theory and prime numbers. She came across an intriguing problem but needs help verifying her results. The problem tasks her with computing the number of prime numbers between two given integers, inclusive.
Write a program to help S... | def sieve(max_num):
"""
Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes.
"""
is_prime = [True] * (max_num + 1)
p = 2
while p * p <= max_num:
if is_prime[p]:
for i in range(p * p, max_num + 1, p):
is_prime[i] = False
p +=... | from solution import number_of_primes_between_ranges
def test_basic_cases():
assert number_of_primes_between_ranges([(10, 20)]) == [4], "Test case (10, 20) failed"
assert number_of_primes_between_ranges([(15, 25)]) == [3], "Test case (15, 25) failed"
assert number_of_primes_between_ranges([(1, 10)]) == [4]... | [
{
"docstring": "Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes.",
"function_declaration": "def sieve(max_num):",
"function_name": "sieve",
"parameter_list": "(max_num)"
},
{
"docstring": "Counts the number of prime numbers between l and r inclusive using a pr... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(n):\n is_prime = [True] * (n + 1)\n is_prime[0] = is_prime[1] = False\n p = 2\n while (p * p <= n):\n if (is_p... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036994",
"row_id": 36994,
"seed_ids": "[7254]"
} | 0.649699 | Code_Contests_36994 | I | [
"sieve",
"count_primes",
"number_of_primes_between_ranges"
] | 3 | [
[
"number_of_primes_between_ranges",
"count_primes"
],
[
"number_of_primes_between_ranges",
"sieve"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 599b7d18982d2464278ff9f1670305dc4d2f7dc7 | 1cbe36bdbe531cd76fcc0d83d888929a218306b3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37027_I | A large advanced robotics company is developing a new line of autonomous delivery robots, and they want to create a simulation of the robot's paths. Each robot will follow a predefined sequence of steps (as a string) and the company wants to know the final position of the robot after executing all the steps in an infin... | def calculate_final_position(steps):
"""
This function takes a sequence of steps and calculates the final position of the robot.
:param steps: A string composed only of characters 'U', 'D', 'L', and 'R'
:return: A tuple of two integers representing the final coordinates (x, y)
"""
x, y = 0, 0
... | from solution import calculate_final_position, print_final_position
def test_final_position_only_up():
assert calculate_final_position('UUUU') == (0, 4)
def test_final_position_only_down():
assert calculate_final_position('DDDD') == (0, -4)
def test_final_position_only_left():
assert calculate_final_posi... | [
{
"docstring": "This function takes a sequence of steps and calculates the final position of the robot.\n:param steps: A string composed only of characters 'U', 'D', 'L', and 'R'\n:return: A tuple of two integers representing the final coordinates (x, y)",
"function_declaration": "def calculate_final_positi... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_position(steps):\n \"\"\"\n This function takes a sequence of steps and calculates the final position of the robot.\n :param s... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037027",
"row_id": 37027,
"seed_ids": "[7324]"
} | 0.655978 | Code_Contests_37027 | I | [
"calculate_final_position",
"print_final_position"
] | 2 | [
[
"print_final_position",
"calculate_final_position"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 78145ba4b03904123e914565624fd97113dfd59b | 9d8542bbea5c68c66df5d7174e0ac387cadff987 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37103_I | You are given a list of integers which represent the heights of columns of different widths placed side by side. The width of each column is 1 unit. Calculate the maximum area of a rectangular water reservoir that can be formed within the bounds of these columns, assuming water extends horizontally between columns and ... | def max_area_of_water_reservoir(heights):
"""
Calculate the maximum area of water that can be contained within the given heights.
"""
left = 0
right = len(heights) - 1
max_area = 0
while left < right:
height = min(heights[left], heights[right])
width = right - left
... | from solution import max_area_of_water_reservoir, solve, parse_input
def test_max_area_of_water_reservoir():
assert max_area_of_water_reservoir([1, 8, 6, 2, 5, 4, 8, 3, 7]) == 49
assert max_area_of_water_reservoir([1, 1, 1, 1, 1]) == 4
assert max_area_of_water_reservoir([1, 2, 1]) == 2
assert max_area_... | [
{
"docstring": "Calculate the maximum area of water that can be contained within the given heights.",
"function_declaration": "def max_area_of_water_reservoir(heights):",
"function_name": "max_area_of_water_reservoir",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_decla... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_water_area(heights):\n \"\"\"\n Calculates the maximum area of a rectangular water reservoir that can be \n formed between two columns in ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037103",
"row_id": 37103,
"seed_ids": "[8750]"
} | 0.671357 | Code_Contests_37103 | I | [
"max_area_of_water_reservoir",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"max_area_of_water_reservoir"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 50839d87f6722dc67d65ac19c8eb02adcca6b4e9 | 45b22cf410bb720895cdd7846daad9d4fdc54790 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37124_I | Alex is an enthusiastic chess player who loves to study different chess positions and solve related puzzles. Recently, he came across a piece movement puzzle and needs your help to determine the minimum number of moves a knight needs to reach a target position on a standard 8x8 chessboard.
The knight is placed at a so... | from collections import deque
def is_valid(x, y):
return 1 <= x <= 8 and 1 <= y <= 8
def min_knight_moves(x1, y1, x2, y2):
if x1 == x2 and y1 == y2:
return 0
# Knight's possible moves
dx = [2, 2, -2, -2, 1, 1, -1, -1]
dy = [1, -1, 1, -1, 2, -2, 2, -2]
queue = deque([(x1, y1, 0)])... | from solution import min_knight_moves
def test_min_knight_moves_same_position():
assert min_knight_moves(4, 4, 4, 4) == 0
def test_min_knight_moves_standard_case():
assert min_knight_moves(1, 1, 8, 8) == 6
def test_min_knight_moves_short_distance():
assert min_knight_moves(1, 1, 2, 2) == 4
def test_min_... | [
{
"docstring": null,
"function_declaration": "def is_valid(x, y):",
"function_name": "is_valid",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def min_knight_moves(x1, y1, x2, y2):",
"function_name": "min_knight_moves",
"parameter_list": "(x1, y1, x2... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_valid(x, y):\n return 1 <= x <= 8 and 1 <= y <= 8\n\ndef min_knight_moves(x1, y1, x2, y2):\n if x1 == x2 and ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037124",
"row_id": 37124,
"seed_ids": "[6263]"
} | 0.673491 | Code_Contests_37124 | I | [
"is_valid",
"min_knight_moves"
] | 2 | [
[
"min_knight_moves",
"is_valid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 274324d0de17124e7fcc67d2d7cf56be2a67087f | 3033332141693faef452025030889d90b8bebf56 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37140_I | You are given a grid with N rows and M columns, where each cell contains either a '#' character representing a wall or a '.' character representing an empty space. Your task is to determine if there exists a path to navigate from the top-left corner of the grid (1,1) to the bottom-right corner (N,M) without passing thr... | def is_path_possible(grid):
"""
Determines if there is a path from the top-left corner to the bottom-right corner in a 2D grid.
Args:
grid (list of list of str): A 2D list where each element is either '.' (empty space) or '#' (wall).
Returns:
str: 'possible' if a path exists, 'impossib... | import pytest
from solution import is_path_possible, check_path
def test_example_1():
n = 4
m = 4
grid_lines = [
"..#.",
".#..",
"....",
"..#."
]
assert check_path(n, m, grid_lines) == "possible"
def test_example_2():
n = 3
m = 3
grid_lines = [
"... | [
{
"docstring": "Determines if there is a path from the top-left corner to the bottom-right corner in a 2D grid.\n\nArgs:\ngrid (list of list of str): A 2D list where each element is either '.' (empty space) or '#' (wall).\n\nReturns:\nstr: 'possible' if a path exists, 'impossible' otherwise.",
"function_dec... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_path_possible(n, m, grid):\n directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n \n def is_valid(x, y):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037140",
"row_id": 37140,
"seed_ids": "[1759]"
} | 0.73532 | Code_Contests_37140 | I | [
"is_path_possible",
"check_path"
] | 2 | [
[
"check_path",
"is_path_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2b6a5b0b003d9ccda002ba7a3dc4c273e1634e9 | ffe97091af74d64a405654fa79cece288fe47433 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37196_I | In a country there are several cities connected by bidirectional roads. Each road has a certain toll cost associated with it. Due to recent budget cuts, the government wants to minimize the total toll cost for travelers by reducing the number of active roads. Your task is to determine the smallest possible toll cost to... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[r... | def test_single_road():
data = "2 1\nCity1\nCity2\nCity1 City2 10\n"
assert minimum_toll_cost(data) == 10
def test_multiple_cities():
data = "4 5\nMumbai\nDelhi\nBangalore\nChennai\nMumbai Delhi 10\nDelhi Bangalore 15\nBangalore Chennai 5\nChennai Mumbai 7\nMumbai Bangalore 20\n"
assert minimum_toll_co... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ro... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037196",
"row_id": 37196,
"seed_ids": "[6738]"
} | 0.752372 | Code_Contests_37196 | I | [
"find",
"union",
"minimum_spanning_tree",
"parse_input",
"minimum_toll_cost"
] | 5 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"minimum_toll_cost",
"minimum_spanning_tree"
],
[
"minimum_toll_cost",
"parse_input"
],
[
"union",
"find"
]
] | 5 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 83eb1b70f6b1cb680ba4a735a0b15f25e48fdfd3 | f3eeace1473031eac5a6e06b36aa6ee91b80195f | |||
v1.0 | instruct | Code_Contests | Code_Contests_37202_I | During his daily walk in the park, Alex found a peculiar tree with an interesting challenge. The tree has nodes and each node can have 0, 1, or 2 children. Each node contains a unique integer value. Alex challenges you with the task of finding the maximum sum path in the tree. A path is defined as any sequence of nodes... | class TreeNode:
def __init__(self, value):
self.value = value
self.children = []
def build_tree(values, edges):
nodes = [TreeNode(value) for value in values]
for u, v in edges:
u -= 1 # Convert to 0-based indexing
v -= 1
nodes[u].children.append(nodes[v])
return... | from solution import find_max_sum_path
def test_example_case():
n = 5
node_values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert find_max_sum_path(n, node_values, edges) == 8
def test_single_node():
n = 1
node_values = [10]
edges = []
assert find_max_sum_path(n, node... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.children = []\n\ndef build_tree(values, edges):\n nodes = [Tre... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037202",
"row_id": 37202,
"seed_ids": "[4595]"
} | 0.693253 | Code_Contests_37202 | I | [
"build_tree",
"max_sum_path",
"find_max_sum_path"
] | 3 | [
[
"find_max_sum_path",
"build_tree"
],
[
"find_max_sum_path",
"max_sum_path"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 86f2922e0ad44d491670cc4682ccef4f69de139a | e8160964c3d2a554b87a3ab2f844d082dbab2b9f | |||
v1.0 | instruct | Code_Contests | Code_Contests_37234_I | You are given a tree (connected undirected graph with no cycles) with n nodes rooted at node 1. Each node is assigned a unique value. Your task is to answer q queries of the following type: Given two nodes u and v, find the maximum value on the path from node u to node v.
Input
The first line contains two integers n ... | def find_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
for node in graph[start]:
if node not in path:
new_path = find_path(graph, node, end, path)
if new_path:
return new_path
return None
def max_value_on_pat... | from solution import solve
def test_simple_case():
n, q = 5, 3
node_values = [5, 3, 7, 6, 2]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [(1, 5), (2, 4), (3, 5)]
assert solve(n, q, node_values, edges, queries) == [7, 7, 7]
def test_single_node():
n, q = 1, 1
node_values = [7]
ed... | [
{
"docstring": null,
"function_declaration": "def find_path(graph, start, end, path=[]):",
"function_name": "find_path",
"parameter_list": "(graph, start, end, path=[])"
},
{
"docstring": null,
"function_declaration": "def max_value_on_path(values, path):",
"function_name": "max_valu... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef preprocess_values(values):\n values_dict = {}\n for i, val in enumerate(values, start=1):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037234",
"row_id": 37234,
"seed_ids": "[12769]"
} | 0.745367 | Code_Contests_37234 | I | [
"find_path",
"max_value_on_path",
"solve"
] | 3 | [
[
"solve",
"find_path"
],
[
"solve",
"max_value_on_path"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2113fd0af806332a7eb8575fa7b59e8143804c8a | 4b7c173ade414407c15d6bf1de97995e94f265ee | |||
v1.0 | instruct | Code_Contests | Code_Contests_37239_I | There are n cities connected by bidirectional roads. Each road has a certain length. You are given the task of finding the minimum total length of the roads that should be included to maintain the connectivity of the entire set of cities (called the minimum spanning tree of the graph).
Input
The first line of input c... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
paren... | from solution import min_spanning_tree
def test_min_spanning_tree_simple_case():
n = 4
m = 5
roads = [
(1, 2, 1),
(1, 3, 4),
(3, 4, 2),
(2, 4, 3),
(2, 3, 5)
]
assert min_spanning_tree(n, m, roads) == 6
def test_min_spanning_tree_no_roads():
n = 3
m =... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037239",
"row_id": 37239,
"seed_ids": "[2242]"
} | 0.724368 | Code_Contests_37239 | I | [
"find",
"union",
"kruskal",
"min_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 30df1c311436b57b1727d7634003a3cfb5488c97 | fa9d7c2aa94bbbc858d938958db1c0f05c8ba832 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37254_I | You are provided with a sequence of integers and you need to answer a series of queries. The types of queries are:
1. "1 x y": Add the value y to the element at index x (1-based indexing).
2. "2 l r": Return the maximum value in the subarray from index l to index r (inclusive).
You need to process multiple test cases... | def process_queries(test_cases):
results = []
for n, q, queries in test_cases:
array = [0] * n
for query in queries:
if query[0] == 1:
x, y = query[1] - 1, query[2]
array[x] += y
elif query[0] == 2:
l, r = query[1] - 1, quer... | def test_process_queries():
input_data = """2
6 5
2 1 6
1 3 2
2 2 4
1 6 3
2 1 6
4 4
1 2 7
1 1 -4
2 1 4
1 4 10"""
expected_output = [0, 2, 3, 7]
assert solve(input_data) == expected_output
def test_edge_cases():
# A single test case with the smallest inputs
input_data = """1
1 1
2 1 1"... | [
{
"docstring": null,
"function_declaration": "def process_queries(test_cases):",
"function_name": "process_queries",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"parameter_list": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ArrayMaxQuery:\n def __init__(self, n):\n self.n = n\n self.array = [0] * n\n\n def add(self, x, y):\n self.array[x - 1] +... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037254",
"row_id": 37254,
"seed_ids": "[7414]"
} | 0.757216 | Code_Contests_37254 | I | [
"process_queries",
"parse_input",
"solve"
] | 3 | [
[
"solve",
"parse_input"
],
[
"solve",
"process_queries"
]
] | 2 | [
"process_queries",
"parse_input"
] | false | [] | false | pytest | false | [] | true | 2a9a4350fb30d78bdd3ff3ddb1e0beb6a59f6c98 | e24fb8f93024a36766a9ee022d5b3bdb334eda2f | |||
v1.0 | instruct | Code_Contests | Code_Contests_37281_I | Given an undirected connected graph with n vertices and m edges, each edge has a non-negative weight. Your goal is to determine the maximum value of the minimum edge weight that can be achieved by removing exactly one edge from the graph. The remaining graph must still be connected after removing the edge.
Input form... | def find_max_of_min_edge(n, m, edges):
def kruskal_mst(n, edges, ignore_edge=None):
parent = list(range(n))
def find(x):
if parent[x] != x:
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
root_x = find(x)
... | from solution import solution
def test_solution_sample_case():
n, m = 4, 5
edge_list = [
(1, 2, 1),
(2, 3, 2),
(3, 4, 3),
(4, 1, 4),
(1, 3, 5)
]
assert solution(n, m, edge_list) == 2
def test_solution_no_edges():
n, m = 1, 0
edge_list = [
]
asser... | [
{
"docstring": null,
"function_declaration": "def find_max_of_min_edge(n, m, edges):",
"function_name": "find_max_of_min_edge",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def solution(n, m, edge_list):",
"function_name": "solution",
"parame... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def solve_max_min_edge_weight(n, m, edges):\n from collections import defaultdict\n import heapq\n\n def mst_kruskal(n, e... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00037281",
"row_id": 37281,
"seed_ids": "[4340]"
} | 0.718911 | Code_Contests_37281 | I | [
"find_max_of_min_edge",
"solution"
] | 2 | [
[
"solution",
"find_max_of_min_edge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8a8626c8db6735a8ab51130a3362eaf057f692fe | bafdcf125c9499b37546f6fa76ea8fd3dab56388 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37317_I | Write a program that reads a list of integers and for each integer, outputs the sum of its digits. The program should continue reading integers until it reads an end-of-input signal, which is represented by the integer -1. The output should not include the sum for the end-of-input signal.
SAMPLE INPUT
123
456
789
-1
... | def sum_of_digits(n):
"""
Returns the sum of the digits of the given integer n.
"""
return sum(int(digit) for digit in str(n))
def process_numbers(numbers):
"""
Given a list of numbers, return a list of the sum of digits for each
number, excluding the end-of-input signal -1.
"""
res... | from solution import sum_of_digits, process_numbers
def test_sum_of_digits():
assert sum_of_digits(123) == 6
assert sum_of_digits(456) == 15
assert sum_of_digits(789) == 24
assert sum_of_digits(0) == 0
assert sum_of_digits(100) == 1
def test_process_numbers():
assert process_numbers([123, 456,... | [
{
"docstring": "Returns the sum of the digits of the given integer n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of numbers, return a list of the sum of digits for each\nnumber, excluding the en... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of digits of the integer n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef read_... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037317",
"row_id": 37317,
"seed_ids": "[3094]"
} | 0.658616 | Code_Contests_37317 | I | [
"sum_of_digits",
"process_numbers"
] | 2 | [
[
"process_numbers",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 30046a4e6df170a659c018445b18f3d23df2df42 | a3cdedc1ebbfe4b6ce51103657cdcbde6cc1ef2a | |||
v1.0 | instruct | Code_Contests | Code_Contests_37392_I | You are given a binary tree and you need to find if there exists a root-to-leaf path such that adding up all the values along the path equals a given sum. A leaf is defined as a node with no children.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of nodes in the binary tree.
The second line c... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def hasPathSum(root: TreeNode, targetSum: int) -> bool:
if not root:
return False
if not root.left and not root.right:
return root.val == targetSum
... | def test_example_1():
n = 5
values = [5, 4, 8, 11, 13]
left_indices = [2, 4, 0, 0, 0]
right_indices = [3, 5, 0, 0, 0]
targetSum = 22
result = solution(n, values, left_indices, right_indices, targetSum)
assert result == "Yes"
def test_example_2():
n = 3
values = [1, 2, 3]
left_in... | [] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00037392",
"row_id": 37392,
"seed_ids": "[3500]"
} | 0.610788 | Code_Contests_37392 | I | [
"hasPathSum",
"build_tree",
"solution"
] | 3 | [
[
"solution",
"build_tree"
],
[
"solution",
"hasPathSum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 511698ee67e49a5a85f2bcffa1e9ffd41b30a9b5 | 73d98d9bb58241a902f0112a2ffb71646d48db24 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37514_I | John is a city planner designing a new downtown area. He received a list of segments, where each segment represents a street. Each street can be defined by two endpoints in a 2-dimensional Cartesian coordinate system.
John needs to ensure that there are no intersections between any two streets (segments) as he finaliz... | def orientation(p, q, r):
"""
To find the orientation of the ordered triplet (p, q, r).
The function returns:
0 -> p, q and r are collinear
1 -> Clockwise
2 -> Counterclockwise
"""
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
re... | def test_no_intersections():
assert are_intersections(2, [(0, 0, 3, 3), (4, 4, 6, 6)]) == "NO"
def test_intersections_within_same_line():
assert are_intersections(3, [(0, 0, 3, 3), (1, 1, 2, 2), (0, 3, 3, 0)]) == "YES"
def test_intersections_at_single_point():
assert are_intersections(3, [(0, 0, 3, 3), (0... | [
{
"docstring": "To find the orientation of the ordered triplet (p, q, r).\nThe function returns:\n 0 -> p, q and r are collinear\n 1 -> Clockwise\n 2 -> Counterclockwise",
"function_declaration": "def orientation(p, q, r):",
"function_name": "orientation",
"parameter_list": "(p, q, r)"
},... | [
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 orientation(p, q, r):\n \"\"\"\n Calculate the orientation of the triplet (p, q, r).\n 0 --> p, q and r are collinear\n 1 --> Clockwise\n ... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00037514",
"row_id": 37514,
"seed_ids": "[1929]"
} | 0.683189 | Code_Contests_37514 | I | [
"orientation",
"on_segment",
"do_intersect",
"are_intersections"
] | 4 | [
[
"are_intersections",
"do_intersect"
],
[
"do_intersect",
"on_segment"
],
[
"do_intersect",
"orientation"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 9c197b8d5e27c5e4f09e5a906674a73f947974a2 | e66d8d779933f411cf2c65ee8ae32e4c46945ac0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37540_I | You are given a rectangular grid with R rows and C columns. Each cell in the grid can either be occupied or empty, represented by '1' and '0' respectively.
A sub-grid is any rectangular section of the grid obtained by selecting a contiguous block of cells.
Your task is to determine the area of the largest rectangular... | def largestRectangleArea(heights):
stack, max_area = [], 0
heights.append(0)
for i, height in enumerate(heights):
while stack and height < heights[stack[-1]]:
h = heights[stack.pop()]
w = i if not stack else i - stack[-1] - 1
max_area = max(max_area, h * w)
... | from solution import largest_rectangular_subgrid
def test_example_1():
R = 4
C = 5
grid = ["10100", "10111", "11111", "10010"]
assert largest_rectangular_subgrid(R, C, grid) == 6
def test_example_2():
R = 3
C = 3
grid = ["111", "111", "111"]
assert largest_rectangular_subgrid(R, C, gri... | [
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def maximalRectangle(grid):",
"function_name": "maximalRectangle",
"parameter... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maxRectangleArea(R, C, grid):\n if R == 0 or C == 0:\n return 0\n\n def maximal_histogram_area(histogram):\n stack = []\n ma... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037540",
"row_id": 37540,
"seed_ids": "[3520]"
} | 0.720284 | Code_Contests_37540 | I | [
"largestRectangleArea",
"maximalRectangle",
"largest_rectangular_subgrid"
] | 3 | [
[
"largest_rectangular_subgrid",
"maximalRectangle"
],
[
"maximalRectangle",
"largestRectangleArea"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 992a4b7458943c5d5f2bd332ee6b01a63590ed60 | 9141b3358713a5596eac25a4012e4e079518399d | |||
v1.0 | instruct | Code_Contests | Code_Contests_37548_I | Alice is fond of prime numbers and she also loves collecting gemstones. One day, she came up with a game where she merges her two interests. The game consists of n gemstones, each with a distinct integer value. Alice wants to select a subset of the gemstones such that the sum of their values is a prime number. Since th... | from typing import List
from itertools import combinations
def is_prime(number: int) -> bool:
"""
Returns True if the number is prime, else False.
"""
if number <= 1:
return False
if number <= 3:
return True
if number % 2 == 0 or number % 3 == 0:
return False
i = 5
... | from solution import smallest_prime_sum
def test_example1():
assert smallest_prime_sum(5, [3, 7, 10, 2, 5]) == 2
def test_example2():
assert smallest_prime_sum(4, [4, 6, 8, 12]) == -1
def test_example3():
assert smallest_prime_sum(6, [11, 15, 3, 17, 20, 8]) == 3
def test_single_prime_element():
asse... | [
{
"docstring": "Returns True if the number is prime, else False.",
"function_declaration": "def is_prime(number):",
"function_name": "is_prime",
"parameter_list": "(number)"
},
{
"docstring": "Finds the smallest prime number sum of a subset of gemstones values, or -1 if no such prime sum exi... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\nfrom typing import List\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00037548",
"row_id": 37548,
"seed_ids": "[2024]"
} | 0.603339 | Code_Contests_37548 | I | [
"is_prime",
"smallest_prime_sum"
] | 2 | [
[
"smallest_prime_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 724419dd83bcc09dce0f899321a746d8b7471d13 | ab5b301224755716b761a68cce08e29baf930f27 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37552_I | A company has a hierarchy of employees working under a strict reporting structure. Each employee has a unique identification number, with the company CEO having the ID 1. Every other employee reports to exactly one manager, directly or indirectly, creating a hierarchical (tree-like) structure.
You are tasked with dete... | from collections import defaultdict, deque
def preprocess(n, edges):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Depth and parent tracking
depth = {}
parent = {}
def bfs(root):
queue = deque([(root, 0)]) # (node, curre... | from solution import find_lcm
def test_example_case():
n = 7
relations = [
(1, 2),
(1, 3),
(2, 4),
(2, 5),
(3, 6),
(3, 7),
(2, 8)
]
queries = [(5, 8)]
assert find_lcm(n, relations, queries) == [2]
def test_single_node():
n = 1
relatio... | [
{
"docstring": null,
"function_declaration": "def preprocess(n, edges):",
"function_name": "preprocess",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def lca(parent, depth):",
"function_name": "lca",
"parameter_list": "(parent, depth)"
},
{
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass LowestCommonManagerFinder:\n def __init__(self, n, edges):\n self.n = n\n self.tree = ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037552",
"row_id": 37552,
"seed_ids": "[12847]"
} | 0.57455 | Code_Contests_37552 | I | [
"preprocess",
"lca",
"find_lcm"
] | 3 | [
[
"find_lcm",
"lca"
],
[
"find_lcm",
"preprocess"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | be0cf8a22500f606b33ffd2f9a4b0d6f9c8e2814 | 2658995583756281a36c6bc6b2e980b4694d0e0b | |||
v1.0 | instruct | Code_Contests | Code_Contests_37685_I | Given a matrix of size M x N filled with either 0's or 1's, find the largest square containing all 1's and return its area. The square can be of any size between 1 x 1 and the entire matrix.
Input: First line contains two integers M and N denoting the size of the matrix. Each of the next M lines contains N integers (e... | def maximal_square(matrix):
if not matrix:
return 0
M = len(matrix)
N = len(matrix[0])
dp = [[0] * N for _ in range(M)]
max_square_len = 0
for i in range(M):
for j in range(N):
if matrix[i][j] == 1:
if i == 0 or j == 0:
... | def test_maximal_square_empty_input():
assert parse_and_solve("0 0\n") == 0
def test_maximal_square_single_1():
input_str = "1 1\n1"
assert parse_and_solve(input_str) == 1
def test_maximal_square_single_0():
input_str = "1 1\n0"
assert parse_and_solve(input_str) == 0
def test_maximal_square_2x2_a... | [
{
"docstring": null,
"function_declaration": "def maximal_square(matrix):",
"function_name": "maximal_square",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def parse_and_solve(input_str):",
"function_name": "parse_and_solve",
"parameter_list": "(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 maximal_square(matrix):\n if not matrix:\n return 0\n \n M = len(matrix)\n N = len(matrix[0])\n \n dp = [[0] * N for _ in rang... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037685",
"row_id": 37685,
"seed_ids": "[4659]"
} | 0.679987 | Code_Contests_37685 | I | [
"maximal_square",
"parse_and_solve"
] | 2 | [
[
"parse_and_solve",
"maximal_square"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f8badc88e13b599fef3f70ae117b9a270fa41272 | a5bc9ae09c127261e133a85c74fa30d1326d3a24 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37710_I | A spaceship is preparing for a mission to Mars, and it needs to optimize the fuel consumption for its journey. The spaceship has several sections, each with different fuel consumption rates. Each section consumes fuel at a constant rate, but in each section, fuel consumption can vary based on distance traveled.
Luckil... | def can_partition(fuel_rates, n, k, max_sum):
current_sum = 0
segments = 1 # Start with one segment
for fuel in fuel_rates:
if current_sum + fuel > max_sum:
# We need to start a new segment
segments += 1
current_sum = fuel
if segments > k:
... | from solution import process_input, minimize_maximum_sum
def test_example_case():
input_string = "9\n10 20 30 40 50 60 70 80 90\n3"
assert process_input(input_string) == 170
def test_single_section():
input_string = "1\n5\n1"
assert process_input(input_string) == 5
def test_two_sections_one_partition... | [
{
"docstring": null,
"function_declaration": "def can_partition(fuel_rates, n, k, max_sum):",
"function_name": "can_partition",
"parameter_list": "(fuel_rates, n, k, max_sum)"
},
{
"docstring": null,
"function_declaration": "def minimize_maximum_sum(fuel_rates, k):",
"function_name":... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_partition(fuel_rates, n, k, max_sum):\n current_sum = 0\n segments = 1 # Start with one segment\n \n for fuel in fuel_rates:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037710",
"row_id": 37710,
"seed_ids": "[11105]"
} | 0.718703 | Code_Contests_37710 | I | [
"can_partition",
"minimize_maximum_sum",
"process_input"
] | 3 | [
[
"minimize_maximum_sum",
"can_partition"
],
[
"process_input",
"minimize_maximum_sum"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d80baee1fdaa7939dbbb590f9b9ecbff861804b4 | f1e193dfc546ae1fffed1b2b122f946549b1d1f1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37721_I | A sequence of integers is called a "special sequence" if it satisfies the following conditions:
1. Every pair of consecutive integers in the sequence have a difference of either 1 or -1.
2. The sequence does not contain a positive integer followed immediately by a different positive integer.
3. The sequence does not co... | def generate_special_sequence(N):
if N == 1:
return [0]
elif N == 2:
return [0, -1]
elif N < 1 or N > 1000:
return -1 # This should never happen given the problem constraints.
special_sequence = []
# For odd and even length
base_pattern_odd = [-1, 0, 1]
base_pattern... | from solution import generate_special_sequence
def test_generate_special_sequence_1():
assert generate_special_sequence(1) == [0]
def test_generate_special_sequence_2():
assert generate_special_sequence(2) == [0, -1]
def test_generate_special_sequence_3():
assert generate_special_sequence(3) == [-1, 0, 1... | [
{
"docstring": null,
"function_declaration": "def generate_special_sequence(N):",
"function_name": "generate_special_sequence",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def format_sequence(sequence):",
"function_name": "format_sequence",
"parameter... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_special_sequence(N):\n if N == 1:\n return [1]\n \n sequence = []\n for i in range(N):\n if i % 2 == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037721",
"row_id": 37721,
"seed_ids": "[12991]"
} | 0.757567 | Code_Contests_37721 | I | [
"generate_special_sequence",
"format_sequence",
"process_input"
] | 3 | [
[
"process_input",
"format_sequence"
],
[
"process_input",
"generate_special_sequence"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 5dbcbd393d1855cbb2cb60f4168334937b37f028 | e7db71f0f34a67ec14bb9a959f35d93fc9e82f0b | |||
v1.0 | instruct | Code_Contests | Code_Contests_37848_I | Pasha is fascinated with prime numbers and has decided to play a game involving primes and sequences. He starts with a sequence of integers S of length n. He wants to create a new sequence T of the same length where each element Ti is derived from Si as follows:
- If Si is a prime number, Ti should be equal to the sum... | def sieve(n):
"""
Return array of smallest prime factor (spf) for every number <= n.
spf[i] will return the smallest prime factor of i.
"""
spf = list(range(n + 1)) # initialize spf array
for i in range(2, int(n**0.5) + 1):
if spf[i] == i: # i is a prime number
for j in range... | from solution import process_sequence
def test_sample_input1():
assert process_sequence([4, 5, 12, 11, 25]) == [2, 10, 6, 22, 5]
def test_sample_input2():
assert process_sequence([3, 8, 6, 2]) == [6, 4, 3, 4]
def test_prime_numbers():
assert process_sequence([13, 17, 19]) == [26, 34, 38]
def test_non_pr... | [
{
"docstring": "Return array of smallest prime factor (spf) for every number <= n.\nspf[i] will return the smallest prime factor of i.",
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": "Return the largest prime number which <= n us... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037848",
"row_id": 37848,
"seed_ids": "[12857]"
} | 0.611658 | Code_Contests_37848 | I | [
"sieve",
"largest_prime_leq",
"construct_sequence_t",
"process_sequence"
] | 4 | [
[
"construct_sequence_t",
"largest_prime_leq"
],
[
"construct_sequence_t",
"sieve"
],
[
"process_sequence",
"construct_sequence_t"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 9dd6f2e610268c614bfa30a66e13d725461d80bf | 3c8cb3f6b692c67fcf454cd08468b4059909d104 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37851_I | Given a list of cities and distances between some pairs of them, your task is to determine the shortest path between two specified cities using Dijkstra's algorithm.
### Input
The input starts with a line containing an integer `n` (2 ≤ n ≤ 1000), the number of cities. The next `n` lines each contain the name of a ci... | import heapq
def dijkstra(graph, start, end):
"""
Determines the shortest path between two cities using Dijkstra's Algorithm.
"""
queue = [(0, start)]
distances = {node: float('infinity') for node in graph}
distances[start] = 0
while queue:
current_distance, current_node = heapq.he... | from solution import find_shortest_path
def test_case_1():
n = 5
cities = ['CityA', 'CityB', 'CityC', 'CityD', 'CityE']
m = 6
paths = [
('CityA', 'CityB', 4),
('CityA', 'CityC', 2),
('CityB', 'CityC', 5),
('CityB', 'CityD', 10),
('CityC', 'CityE', 3),
('C... | [
{
"docstring": "Determines the shortest path between two cities using Dijkstra's Algorithm.",
"function_declaration": "def dijkstra(graph, start, end):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, end)"
},
{
"docstring": null,
"function_declaration": "def find_shortes... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(n, cities, m, paths, source, destination):\n # Creating an adjacency list for the cities and paths\n graph = {city: [] f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037851",
"row_id": 37851,
"seed_ids": "[5613]"
} | 0.719724 | Code_Contests_37851 | I | [
"dijkstra",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 07fd430e2c41429bf242d0bdba2c1d4e5008d36a | c4c0fb14b9c072b67ee9659f8325ae10b16b7a35 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37906_I | John loves playing with numbers, especially finding interesting properties among them. His math teacher recently introduced him to the concept of Fibonacci prime numbers. A Fibonacci prime is a number that is both a Fibonacci number and a prime number. John gets really excited by this and wants to find all such numbers... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def fibonacci_primes(limit):
... | from solution import is_prime, fibonacci_primes, precompute_fibonacci_primes, solve_fibonacci_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
asse... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def fibonacci_primes(limit):",
"function_name": "fibonacci_primes",
"parameter_list": "(limit)"
},
{
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def sieve(n):\n \"\"\"Returns a list of primes ≤ n using the Sieve of Eratosthenes.\"\"\"\n is_prime = [True] * (n + 1)\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00037906",
"row_id": 37906,
"seed_ids": "[2051]"
} | 0.633115 | Code_Contests_37906 | I | [
"is_prime",
"fibonacci_primes",
"precompute_fibonacci_primes",
"solve_fibonacci_primes",
"main"
] | 5 | [
[
"fibonacci_primes",
"is_prime"
],
[
"precompute_fibonacci_primes",
"fibonacci_primes"
],
[
"solve_fibonacci_primes",
"precompute_fibonacci_primes"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 4449702d58647e8eb8a17eb520a5c5cd0a8d09ad | aa94051942bdbccd3633d1a83b7226a8e75cc9e6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37907_I | **Problem Statement**
In this problem, you'll implement a primality testing algorithm. A prime number is an integer greater than 1 that has no divisors other than 1 and itself. Efficient primality testing is crucial in various fields such as cryptography, where large prime numbers are used. Your task is to check if a ... | def miller_rabin(n, k=5):
""" Perform Miller-Rabin primality test on n for k iterations. """
# Special cases
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0:
return False
# Write n-1 as 2^s * d with d odd
def get_sd(n):
s = 0
d = n -... | from solution import is_prime
def test_primes():
assert is_prime([17, 19, 23]) == ["YES", "YES", "YES"]
def test_composites():
assert is_prime([4, 6, 8, 9, 10, 12, 15]) == ["NO", "NO", "NO", "NO", "NO", "NO", "NO"]
def test_mixtures():
assert is_prime([1, 2, 4, 17, 18, 19, 20]) == ["NO", "YES", "NO", "YE... | [
{
"docstring": "Perform Miller-Rabin primality test on n for k iterations. ",
"function_declaration": "def miller_rabin(n, k=5):",
"function_name": "miller_rabin",
"parameter_list": "(n, k=5)"
},
{
"docstring": null,
"function_declaration": "def is_prime(numbers):",
"function_name": ... | [
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": "def miller_rabin(n, k=5):\n \"\"\"\n Perform the Miller-Rabin primality test on a given integer n.\n \"\"\"\n import r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037907",
"row_id": 37907,
"seed_ids": "[5307]"
} | 0.619904 | Code_Contests_37907 | I | [
"miller_rabin",
"is_prime"
] | 2 | [
[
"is_prime",
"miller_rabin"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87bba58fa01d8aba0af19015fdc17757e580f23d | 67a105c75bb784213e889e2ca9d9c9d5d49b2ea9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_37919_I | Maria has a list of integers and she wants to know the sum of the prime numbers in the list. Can you help her find the answer for each list she provides?
INPUT:
The first line contains the number of testcases T, followed by T sections. Each section starts with an integer L representing the length of the list, followe... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, sum_of_primes_in_list, sum_of_primes_in_testcases
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == F... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers in the given list.",
"function_declaration": "def sum_of_primes_in_... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00037919",
"row_id": 37919,
"seed_ids": "[10691]"
} | 0.614659 | Code_Contests_37919 | I | [
"is_prime",
"sum_of_primes_in_list",
"sum_of_primes_in_testcases"
] | 3 | [
[
"sum_of_primes_in_list",
"is_prime"
],
[
"sum_of_primes_in_testcases",
"sum_of_primes_in_list"
]
] | 2 | [
"sum_of_primes_in_testcases"
] | false | [] | false | pytest | true | [] | true | 477b2f5c86889465c9cebd90ec3f525a5e066176 | 0573c41b73989c2382207c72045d1706d23f412d | |||
v1.0 | instruct | Code_Contests | Code_Contests_38001_I | You are given an array of positive integers B of length M. You are required to find the sum of all odd prime numbers present in the array.
Constraints:
* All values in the input are integers.
* 1 \leq M \leq 10^5
* 1 \leq B_i \leq 10^6
Input:
Input is given from Standard Input in the following format:
M
B_1 B_2 \c... | def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n == 2:
return False # 2 is not an odd prime number
if n % 2 == 0:
return False
sqrt_n = int(n**0.5) + 1
for i in range(3, sqrt_n, 2):
if n % i == 0:
return False
... | from solution import is_prime, sum_odd_primes
def test_is_prime():
assert is_prime(11) == True
assert is_prime(24) == False
assert is_prime(9) == False
assert is_prime(7) == True
assert is_prime(10) == False
assert is_prime(5) == True
assert is_prime(2) == False # 2 is not an odd prime
... | [
{
"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 sum of all odd prime numbers in the array.",
"function_declaration": "def sum_odd_primes(arr):",
"fun... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return n % 2 != 0 and n % 3 != 0\n if n % 2 =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038001",
"row_id": 38001,
"seed_ids": "[6639]"
} | 0.583511 | Code_Contests_38001 | I | [
"is_prime",
"sum_odd_primes"
] | 2 | [
[
"sum_odd_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 86180553f6ff0c4a71d704b7fb53b43e71aad9f0 | d97874e69ac7d51c2b85e4a6690b3e652eb07ad2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38023_I | You are given a binary tree. The task is to find the minimum and maximum depth of the tree, where:
- Minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
- Maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf n... | from collections import defaultdict, deque
# Function to create the adjacency list for the tree
def create_tree(edges):
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
return tree
# Function to calculate the minimum depth using Breadth-First Search
def find_... | def test_min_and_max_depth():
test_cases = [
(1, [(1, 2), (1, 3), (2, 4)]), # Minimum depth: 2 (1 -> 3), Maximum depth: 3 (1 -> 2 -> 4)
(2, [(2, 1), (2, 3)]), # Minimum depth: 2 (2 -> 1), Maximum depth: 2 (2 -> 3)
]
t = 2
results = find_min_and_max_depth(t, test_cases)
asse... | [
{
"docstring": null,
"function_declaration": "def create_tree(edges):",
"function_name": "create_tree",
"parameter_list": "(edges)"
},
{
"docstring": null,
"function_declaration": "def find_min_depth(root, tree):",
"function_name": "find_min_depth",
"parameter_list": "(root, 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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(root_val, edges):\... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00038023",
"row_id": 38023,
"seed_ids": "[6526]"
} | 0.670942 | Code_Contests_38023 | I | [
"create_tree",
"find_min_depth",
"find_max_depth",
"find_min_and_max_depth"
] | 4 | [
[
"find_min_and_max_depth",
"create_tree"
],
[
"find_min_and_max_depth",
"find_max_depth"
],
[
"find_min_and_max_depth",
"find_min_depth"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 28df50b9e261a0fd78f86a28a1324ce2319f0f22 | ace46aa09ee98152c6ef4deadfcdfaa46f0a2135 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38101_I | In a certain country, there are N cities connected by M bidirectional roads. Each road connects two cities and has a certain travel cost associated with it. The government has decided to improve the connectivity of the cities by turning them into a more connected network. They have decided to achieve this by ensuring t... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < rank[root_y]:
parent... | from solution import minimum_spanning_tree
def test_example_1():
n = 4
edges = [
(0, 1, 1),
(0, 2, 2),
(0, 3, 3),
(1, 2, 4),
(2, 3, 5),
]
assert minimum_spanning_tree(n, edges) == 6
def test_example_2():
n = 3
edges = [
(0, 1, 2),
(0, 2, ... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00038101",
"row_id": 38101,
"seed_ids": "[9145]"
} | 0.80265 | Code_Contests_38101 | I | [
"find",
"union",
"minimum_spanning_tree",
"main"
] | 4 | [
[
"minimum_spanning_tree",
"find"
],
[
"minimum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 754726291c2a3dba788170401a5978d5f8300378 | e11d427746e3c8e24f2a0eadce3739e9f343360b | |||
v1.0 | instruct | Code_Contests | Code_Contests_38153_I | Farmer John needs to build a new barn on his farm, but he has some constraints. The farm is represented as an n x m grid, with each cell either containing a rock or being empty. Farmer John wants to build the barn in such a way that it forms a rectangular area on the grid which is free of any rocks.
Given the layout o... | def maximalRectangleArea(grid):
if not grid or not grid[0]:
return 0
n = len(grid)
m = len(grid[0])
heights = [0] * m
max_area = 0
for row in grid:
for j in range(m):
heights[j] = heights[j] + 1 if row[j] == '.' else 0
max_area = max(max_area, largestRectan... | from solution import maximalRectangleArea
def test_simple_case():
grid = [
"..#",
".#."
]
assert maximalRectangleArea(grid) == 2
def test_larger_case():
grid = [
"....",
"..#.",
"....",
"#..."
]
assert maximalRectangleArea(grid) == 6
def test_fu... | [
{
"docstring": null,
"function_declaration": "def maximalRectangleArea(grid):",
"function_name": "maximalRectangleArea",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleInHistogram(heights):",
"function_name": "largestRectangleInHistogr... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_rectangle_area(grid):\n def max_histogram_area(heights):\n stack = []\n max_area = 0\n i = 0\n while i < len(hei... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038153",
"row_id": 38153,
"seed_ids": "[8686]"
} | 0.63712 | Code_Contests_38153 | I | [
"maximalRectangleArea",
"largestRectangleInHistogram"
] | 2 | [
[
"maximalRectangleArea",
"largestRectangleInHistogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87b0558f7abf3d283c08c1724c90f135e8ac2793 | 5be06853408e053f3da1f8fc4c4e9f2e1bb54320 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38180_I | Chris is a robotics enthusiast who programs his robot to move around a grid. Chris's robot is initially located at the bottom-left corner of a grid, which is represented as (0, 0). The grid has obstacles in the form of certain cells that the robot cannot step on. The robot can only move up or right to navigate from the... | def unique_paths_with_obstacles(grid):
n = len(grid)
m = len(grid[0])
if grid[0][0] == 1 or grid[n - 1][m - 1] == 1:
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == 1:
dp... | from solution import unique_paths_with_obstacles, solve
def test_example_1():
grid = [
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
]
assert unique_paths_with_obstacles(grid) == 2
def test_example_2():
grid = [
[0, 1, 0],
[0, 1, 0],
[0, 0, 0]
]
assert unique_... | [
{
"docstring": null,
"function_declaration": "def unique_paths_with_obstacles(grid):",
"function_name": "unique_paths_with_obstacles",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(data):",
"function_name": "solve",
"parameter_list": "(data... | [
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 unique_paths_with_obstacles(grid):\n n = len(grid)\n m = len(grid[0])\n \n # Create a DP table initialized to zero\n dp = [[0]*m for _ i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038180",
"row_id": 38180,
"seed_ids": "[12799]"
} | 0.712356 | Code_Contests_38180 | I | [
"unique_paths_with_obstacles",
"solve"
] | 2 | [
[
"solve",
"unique_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7de5ca58335226fda641714fc7968088d82c83ba | 5ec3b2a3ffdae9429f080561f67c41f8e06cc08e | |||
v1.0 | instruct | Code_Contests | Code_Contests_38291_I | Create a program that determines the smallest palindrome greater than a given integer.
A palindrome is a number that reads the same backward as forward. Given a positive integer N, your task is to find the smallest integer greater than N that is also a palindrome.
Input
The input consists of a single integer N (1 ≤ ... | def is_palindrome(n):
"""
Check if a given integer n is a palindrome.
"""
return str(n) == str(n)[::-1]
def next_palindrome(n):
"""
Find the smallest palindrome greater than the given integer n.
"""
while True:
n += 1
if is_palindrome(n):
return n | from solution import is_palindrome, next_palindrome
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(131) == True
assert is_palindrome(11) == True
assert is_palindrome(12321) == True
assert is_palindrome(123321) == True
def tes... | [
{
"docstring": "Check if a given integer n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest palindrome greater than the given integer n.",
"function_declaration": "def next_p... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n \"\"\"\n Check if a number is a palindrome\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef next_palindrome(N):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038291",
"row_id": 38291,
"seed_ids": "[3111]"
} | 0.821049 | Code_Contests_38291 | I | [
"is_palindrome",
"next_palindrome"
] | 2 | [
[
"next_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1f5b756c12db2e9b890328d613b90e51ae1907be | bc9d49b08465797b5deaedec264f4c1350032554 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38299_I | Marc loves playing with numbers, especially finding interesting sequences. He recently stumbled upon the Fibonacci sequence and now wants your help to determine specific values from it!
Your task is to find the n-th Fibonacci number for multiple test cases. Since the Fibonacci numbers can get large, return the result ... | MOD = 1000000007
def compute_fibonacci_up_to(n):
"""Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007."""
fib = [0] * (n + 1)
if n > 0:
fib[1] = 1
for i in range(2, n + 1):
fib[i] = (fib[i-1] + fib[i-2]) % MOD
return fib
def get_nth_fibonacci(numbers):
... | from solution import get_nth_fibonacci
def test_single_case():
assert get_nth_fibonacci([0]) == [0]
assert get_nth_fibonacci([1]) == [1]
def test_multiple_cases():
assert get_nth_fibonacci([0, 1, 2, 3, 10]) == [0, 1, 1, 2, 55]
def test_large_number():
result = get_nth_fibonacci([1000000])
# We wo... | [
{
"docstring": "Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007.",
"function_declaration": "def compute_fibonacci_up_to(n):",
"function_name": "compute_fibonacci_up_to",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_nth_fib... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef compute_fibonacci_up_to(n):\n \"\"\"Pre-computes the Fibonacci sequence up to n and stores them modulo 1000000007.\"\"\"\n fi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038299",
"row_id": 38299,
"seed_ids": "[525]"
} | 0.66362 | Code_Contests_38299 | I | [
"compute_fibonacci_up_to",
"get_nth_fibonacci"
] | 2 | [
[
"get_nth_fibonacci",
"compute_fibonacci_up_to"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04d4fdc949d1576d150703b61c03d1fb1d042632 | 2b19a78ba8fb99af74a9f66171759d2e73203c9a | |||
v1.0 | instruct | Code_Contests | Code_Contests_38312_I | Vasily has a 2D rectangular grid of dimensions n x m (1 ≤ n, m ≤ 10^3). Each cell in the grid either contains an obstacle or is empty. Vasily wants to find the number of distinct paths from the top-left corner of the grid to the bottom-right corner, moving only right or down at each step, and not passing through any ob... | def count_paths(grid, n, m):
MOD = 998244353
# dp array - number of ways to reach each cell
dp = [[0] * m for _ in range(n)]
if grid[0][0] == '.' and grid[n-1][m-1] == '.':
dp[0][0] = 1
# Fill dp array
for i in range(n):
for j in range(m):
if grid[i][j]... | from solution import count_paths_from_input
def test_simple_case():
input_data = "4 4\n....\n..#.\n....\n#...\n"
assert count_paths_from_input(input_data) == 10
def test_no_path_case():
input_data = "3 3\n...\n.#.\n..#\n"
assert count_paths_from_input(input_data) == 0
def test_blocked_start():
in... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid, n, m):",
"function_name": "count_paths",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def count_paths_from_input(input_string):",
"function_name": "count_paths_from_input",
"p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def num_paths(n, m, grid):\n MOD = 998244353\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [[0] * m for _ in ran... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038312",
"row_id": 38312,
"seed_ids": "[3770]"
} | 0.809366 | Code_Contests_38312 | I | [
"count_paths",
"count_paths_from_input"
] | 2 | [
[
"count_paths_from_input",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d97508205d844d321048b906478d0e084762b8d6 | d7d343b625034be2f41cf639f9c614915cc12f2c | |||
v1.0 | instruct | Code_Contests | Code_Contests_38322_I | Miranda has a fascination with prime numbers. She recently came up with a game where she tries to find the smallest prime number greater than a given number. However, she wants your help to automate this process, as the game becomes tedious when dealing with large numbers.
Your task is to write a function that takes a... | import math
def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import is_prime, find_smallest_prime_greater_than, smallest_primes_greater_than_cases
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(29)
assert not is_prime(35)
def test_find_smallest_prime_greater_than():
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest prime number greater than n.",
"function_declaration": "def find_smallest_prime_greater_than(n):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038322",
"row_id": 38322,
"seed_ids": "[9915]"
} | 0.619367 | Code_Contests_38322 | I | [
"is_prime",
"find_smallest_prime_greater_than",
"smallest_primes_greater_than_cases"
] | 3 | [
[
"find_smallest_prime_greater_than",
"is_prime"
],
[
"smallest_primes_greater_than_cases",
"find_smallest_prime_greater_than"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 66e2a9602fbd8e604e2fa61d6f36c1fae010440e | bcf6e1b5c5c4262bdcf4810d798cd4b730f027dd | |||
v1.0 | instruct | Code_Contests | Code_Contests_38361_I | You are given a directed graph with N nodes and M edges. Each edge has a weight indicating the cost to travel from one node to another. You are asked to determine the minimum cost to travel from a given start node S to a given end node T.
If there is no path from S to T, your program should return -1.
Constraints:
*... | import heapq
def find_min_cost(N, M, S, T, edges):
graph = [[] for _ in range(N + 1)]
for u, v, w in edges:
graph[u].append((v, w))
# Dijkstra's algorithm to find shortest path
min_heap = [(0, S)]
distances = {i: float('inf') for i in range(1, N + 1)}
distances[S] = 0
whil... | def test_minimum_cost_to_travel():
assert minimum_cost_to_travel(5, 6, 1, 5, ["1 2 10", "2 3 10", "3 4 10", "4 5 10", "1 3 40", "2 5 50"]) == 40
assert minimum_cost_to_travel(4, 4, 1, 4, ["1 2 5", "1 3 10", "2 3 2", "3 4 1"]) == 8
assert minimum_cost_to_travel(3, 3, 1, 3, ["1 2 5", "2 1 5", "1 3 20"]) == 20... | [
{
"docstring": null,
"function_declaration": "def find_min_cost(N, M, S, T, edges):",
"function_name": "find_min_cost",
"parameter_list": "(N, M, S, T, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_cost_to_travel(N, M, S, T, edge_list):",
"function_name": "mini... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom typing import List, Tuple\n\ndef find_min_cost(N: int, M: int, S: int, T: int, edges: List[Tuple[int, int, int]]) -> int:\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038361",
"row_id": 38361,
"seed_ids": "[5809]"
} | 0.847153 | Code_Contests_38361 | I | [
"find_min_cost",
"minimum_cost_to_travel"
] | 2 | [
[
"minimum_cost_to_travel",
"find_min_cost"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a624c578bc259a15db2e3c4b28ac238e8341f35d | 591ea5a14400a721c730d0deff88eecabb6b99a7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38365_I | In a distant kingdom, there exists an ancient calculator that only performs operations on arrays. The calculator has two special operations: Invert and Rotate. Given an initial array of numbers, you must perform these operations for M days according to specified rules before reporting the sum of the array after M days.... | def invert_array(array):
"""Inverts the elements of the array by multiplying by -1"""
return [-x for x in array]
def rotate_array(array, k):
"""Rotates the array k positions to the right"""
n = len(array)
k = k % n # To adapt the rotation within the array bounds
return array[-k:] + array[:-k]
... | def test_invert_array():
assert invert_array([1, 2, 3, 4]) == [-1, -2, -3, -4]
assert invert_array([-1, -2, -3, -4]) == [1, 2, 3, 4]
def test_rotate_array():
assert rotate_array([1, 2, 3, 4], 1) == [4, 1, 2, 3]
assert rotate_array([1, 2, 3, 4], 2) == [3, 4, 1, 2]
assert rotate_array([1, 2, 3, 4], 4... | [
{
"docstring": "Inverts the elements of the array by multiplying by -1",
"function_declaration": "def invert_array(array):",
"function_name": "invert_array",
"parameter_list": "(array)"
},
{
"docstring": "Rotates the array k positions to the right",
"function_declaration": "def rotate_ar... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_array_sum_after_operations(arr, M):\n \"\"\"\n Calculate the sum of the array after M days of operations.\n \"\"\"\n # Helper fun... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00038365",
"row_id": 38365,
"seed_ids": "[12043]"
} | 0.601097 | Code_Contests_38365 | I | [
"invert_array",
"rotate_array",
"array_after_M_days",
"process_test_cases"
] | 4 | [
[
"array_after_M_days",
"invert_array"
],
[
"array_after_M_days",
"rotate_array"
],
[
"process_test_cases",
"array_after_M_days"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | b1de845686e4fb3d303dc609eccd7c84be136778 | 4b2ac30b8375315d5f7068ad026e81fd1158d051 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38385_I | Given an integer N, find the smallest integer greater than or equal to N that is both a palindrome and a prime number.
A palindrome is a number that reads the same forwards and backwards. For example, 121, 1331, and 12321 are palindromes.
A prime number is a number greater than 1 that has no positive divisors other t... | def is_palindrome(x):
"""
Checks if a given integer is a palindrome.
"""
return str(x) == str(x)[::-1]
def is_prime(x):
"""
Checks if a given integer is a prime number.
"""
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return... | def test_is_palindrome():
assert is_palindrome(121)
assert is_palindrome(1331)
assert not is_palindrome(123)
assert not is_palindrome(10)
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert is_prime(5)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(... | [
{
"docstring": "Checks if a given integer is a palindrome.",
"function_declaration": "def is_palindrome(x):",
"function_name": "is_palindrome",
"parameter_list": "(x)"
},
{
"docstring": "Checks if a given integer is a prime number.",
"function_declaration": "def is_prime(x):",
"funct... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(num):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef is_prime(num):\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038385",
"row_id": 38385,
"seed_ids": "[3206]"
} | 0.773813 | Code_Contests_38385 | I | [
"is_palindrome",
"is_prime",
"find_smallest_palindromic_prime"
] | 3 | [
[
"find_smallest_palindromic_prime",
"is_palindrome"
],
[
"find_smallest_palindromic_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | bd1c2ad210ee0b9f4f993dd7bb6119b36a37b8c0 | ce21a330a4c472288799821473fab71a3da88ea4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38428_I | You are given a string `s` and an integer `k`. You need to split the string into exactly `k` non-empty substrings such that the sum of lengths of the longest increasing subsequence (LIS) among all substrings is maximized.
Recall that a subsequence is a sequence that can be derived from the given sequence by deleting ... | import bisect
def length_of_LIS(s):
"""
Finds length of longest increasing subsequence in a string, s.
"""
lis = []
for char in s:
pos = bisect.bisect_left(lis, char)
if pos == len(lis):
lis.append(char)
else:
lis[pos] = char
return len(lis)
def ... | from solution import length_of_LIS, max_sum_of_LIS
def test_length_of_LIS():
assert length_of_LIS("abc") == 3
assert length_of_LIS("abacaba") == 3
assert length_of_LIS("a") == 1
assert length_of_LIS("edcba") == 1
def test_max_sum_of_LIS_example():
assert max_sum_of_LIS(7, 3, "abacaba") == 5
def t... | [
{
"docstring": "Finds length of longest increasing subsequence in a string, s.",
"function_declaration": "def length_of_LIS(s):",
"function_name": "length_of_LIS",
"parameter_list": "(s)"
},
{
"docstring": "Finds the maximum possible sum of lengths of LIS among all k substrings.",
"funct... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def length_of_lis(s):\n \"\"\" Helper function to calculate the length of the longest increasing subsequence in s \"\"\"\n if not s:\n return ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038428",
"row_id": 38428,
"seed_ids": "[10231]"
} | 0.707909 | Code_Contests_38428 | I | [
"length_of_LIS",
"max_sum_of_LIS"
] | 2 | [
[
"max_sum_of_LIS",
"length_of_LIS"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3f5003e51651cdc230ab503f97fd2b122114ce4b | 0240fe32481faed29ae764e33c9e1a3a78df5e73 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38438_I | Problem Description:
You are given an integer array `arr` representing stock prices on different days. You need to follow a single rule: you can only buy and sell the stock once, but you are allowed to complete the transaction on the same day. Your task is to find the maximum profit that can be achieved by buying and s... | def max_profit(arr):
"""
Returns the maximum profit that can be achieved from the given stock prices.
"""
if not arr or len(arr) < 2:
return 0
min_price = arr[0]
max_profit = 0
for price in arr:
min_price = min(min_price, price)
max_profit = max(max_profit, price - ... | def test_max_profit_single_case():
assert max_profit([7, 1, 5, 3, 6, 4]) == 5
assert max_profit([7, 6, 4, 3, 1]) == 0
def test_max_profit_case_with_no_prices():
assert max_profit([]) == 0
def test_max_profit_case_with_single_price():
assert max_profit([7]) == 0
def test_max_profit_identical_prices():... | [
{
"docstring": "Returns the maximum profit that can be achieved from the given stock prices.",
"function_declaration": "def max_profit(arr):",
"function_name": "max_profit",
"parameter_list": "(arr)"
},
{
"docstring": "Processes multiple test cases and returns the results.",
"function_de... | [
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_profit(prices):\n \"\"\"\n Returns the maximum profit that can be achieved from buying and selling stock.\n If no profit can be made, retu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038438",
"row_id": 38438,
"seed_ids": "[1043]"
} | 0.711766 | Code_Contests_38438 | I | [
"max_profit",
"process_test_cases",
"solve"
] | 3 | [
[
"process_test_cases",
"max_profit"
],
[
"solve",
"process_test_cases"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | 471b42803844f4ab3538710e3965c3f0532fbe43 | 976fa2da0cd47eb25f74302f899d06963145c778 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38440_I | Your team at BrainyBots Inc. is tasked with developing an advanced text editing feature within an application. The feature involves automatic text correction based on predefined rules. You need to write a function that processes a piece of text, identifying and correcting specific patterns of words according to given t... | def apply_transformation_rules(n, rules, text):
"""
Applies a number of text transformation rules on the given text and returns the corrected text.
:param int n: Number of transformation rules
:param list rules: List of tuples where each tuple contains a pattern and corresponding replacement
:param... | import pytest
from solution import parse_input, apply_transformation_rules, transform_text
def test_parse_input():
input_str = """2
hello world,hi Earth
good bye,see you later
hello world it is a good world."""
n, rules, text = parse_input(input_str)
assert n == 2
assert rules == ... | [
{
"docstring": "Applies a number of text transformation rules on the given text and returns the corrected text.\n\n:param int n: Number of transformation rules\n:param list rules: List of tuples where each tuple contains a pattern and corresponding replacement\n:param str text: Original text to be corrected\n:r... | [
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 apply_transformation_rules(n, rules, text):\n \"\"\"\n Applies a series of transformation rules to a text.\n\n Parameters:\n n (int): The n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038440",
"row_id": 38440,
"seed_ids": "[11602]"
} | 0.624815 | Code_Contests_38440 | I | [
"apply_transformation_rules",
"parse_input",
"transform_text"
] | 3 | [
[
"transform_text",
"apply_transformation_rules"
],
[
"transform_text",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 076ff51658d41ae3292eb8f9b2e3906e0dc8b0e8 | 77be361cd4b8fb7fd1735e9fabf8e4e4d654c2fb | |||
v1.0 | instruct | Code_Contests | Code_Contests_38443_I | You are given a rectangular grid with dimensions $ H \times W $. In the grid, some cells are blocked, and some are open. The task is to move from the top-left corner to the bottom-right corner of the grid. You can move only to the right or down at each step. Determine the number of distinct paths from the top-left corn... | MOD = 10**9 + 7
def num_paths(grid, H, W):
# Initialize a DP table with 0
dp = [[0] * W for _ in range(H)]
# Start at dp[0][0]
if grid[0][0] == '.':
dp[0][0] = 1
# Fill the DP table
for i in range(H):
for j in range(W):
if grid[i][j] == '.':
... | def test_example_case():
H = 3
W = 3
grid_input = "...\n.#.\n..."
assert distinct_paths(H, W, grid_input) == 2
def test_no_path():
H = 2
W = 2
grid_input = "..\n##"
assert distinct_paths(H, W, grid_input) == 0
def test_single_cell():
H = 1
W = 1
grid_input = "."
ass... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid, H, W):",
"function_name": "num_paths",
"parameter_list": "(grid, H, W)"
},
{
"docstring": null,
"function_declaration": "def distinct_paths(H, W, grid_input):",
"function_name": "distinct_paths",
"parameter_list": ... | [
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 number_of_paths(H, W, grid):\n MOD = 10**9 + 7\n dp = [[0] * W for _ in range(H)]\n \n # If the starting or ending point is blocked, return... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038443",
"row_id": 38443,
"seed_ids": "[5623]"
} | 0.813676 | Code_Contests_38443 | I | [
"num_paths",
"distinct_paths"
] | 2 | [
[
"distinct_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e07b6d48ce3df3dca514e16d7547dc754d657966 | 8d8c79cef76306a13d27588625be7af302e5cacc | |||
v1.0 | instruct | Code_Contests | Code_Contests_38457_I | In a software company, developers are using a version control system that supports branching and merging. Each branch is a sequence of commits represented as strings. Occasionally, a developer may need to merge two branches. During a merge, conflicts may arise if both branches have commits that modify the same file. Th... | def simulate_branching_and_merging(branches, merge_queries):
from collections import defaultdict
def count_conflicts(branch1, branch2):
conflict_count = 0
seen_files = {}
for commit in branch1:
file, id_ = commit[0], commit[1:]
if file not in seen_fi... | from solution import simulate_branching_and_merging
def test_merge_no_conflict():
branches = [
["a1", "b1"],
["c1", "d1"]
]
merge_queries = [(1, 2)]
assert simulate_branching_and_merging(branches, merge_queries) == [0]
def test_merge_with_conflict():
branches = [
["a1", "b1... | [
{
"docstring": null,
"function_declaration": "def simulate_branching_and_merging(branches, merge_queries):",
"function_name": "simulate_branching_and_merging",
"parameter_list": "(branches, merge_queries)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_execute():"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_conflicts(branches, merge_queries):\n \"\"\"\n Returns the number of conflicts during the merging of branches based on the queries.\n \n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038457",
"row_id": 38457,
"seed_ids": "[11174]"
} | 0.496234 | Code_Contests_38457 | I | [
"simulate_branching_and_merging",
"process_input_and_execute"
] | 2 | [
[
"process_input_and_execute",
"simulate_branching_and_merging"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50f9698ce70e777611b70fbe49809e0fcbc1e193 | a0aa323bfc36bba1cf6aa276282ff9ec35d6a632 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38595_I | You are given a string s and two integers p and q. Your task is to find the number of substrings of s of length exactly p that can be rearranged into a palindrome, and the number of substrings of s of length exactly q that cannot be rearranged into a palindrome.
A string is considered to be palindromic if it reads the... | def can_be_rearranged_to_palindrome(s):
"""
Check if a string `s` can be rearranged into a palindrome.
"""
from collections import Counter
count = Counter(s)
odd_count = sum(1 for c in count if count[c] % 2 != 0)
return odd_count <= 1
def count_rearrangeable_and_non_rearrangeable(s, p, q):
... | import pytest
from solution import can_be_rearranged_to_palindrome, count_rearrangeable_and_non_rearrangeable, process_cases
def test_can_be_rearranged_to_palindrome():
assert can_be_rearranged_to_palindrome("aba") == True
assert can_be_rearranged_to_palindrome("abc") == False
assert can_be_rearranged_to_p... | [
{
"docstring": "Check if a string `s` can be rearranged into a palindrome.",
"function_declaration": "def can_be_rearranged_to_palindrome(s):",
"function_name": "can_be_rearranged_to_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Count substrings of length p that can be rearranged i... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef can_form_palindrome(substring):\n \"\"\"\n Check if a given substring can be rearranged into a palindrome.\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00038595",
"row_id": 38595,
"seed_ids": "[1592]"
} | 0.848973 | Code_Contests_38595 | I | [
"can_be_rearranged_to_palindrome",
"count_rearrangeable_and_non_rearrangeable",
"process_cases"
] | 3 | [
[
"count_rearrangeable_and_non_rearrangeable",
"can_be_rearranged_to_palindrome"
],
[
"process_cases",
"count_rearrangeable_and_non_rearrangeable"
]
] | 2 | [
"process_cases"
] | false | [] | false | pytest | true | [] | true | 238e555a3096d06929b2526f4e4112b210f75161 | f48e1febeed8b7463cd2806ce575060f33969492 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38618_I | Arun is a creator of a new social media platform. He wants to implement a feature where users can follow each other. He gave you a directed graph with N nodes and M edges representing users and their follow relationships respectively. Your task is to determine if there is a cycle in the graph, which would indicate a ci... | from collections import defaultdict
def has_cycle(graph, node, visited, recStack):
visited[node] = True
recStack[node] = True
for neighbour in graph[node]:
if not visited[neighbour]:
if has_cycle(graph, neighbour, visited, recStack):
return True
elif recStack[ne... | import pytest
from solution import check_circular_relationships
def test_single_cycle():
T = 1
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)])
]
assert check_circular_relationships(T, test_cases) == ["YES"]
def test_multiple_cycles():
T = 1
test_cases = [
(4, 4, [(1, 2), (2, 3)... | [
{
"docstring": null,
"function_declaration": "def has_cycle(graph, node, visited, recStack):",
"function_name": "has_cycle",
"parameter_list": "(graph, node, visited, recStack)"
},
{
"docstring": null,
"function_declaration": "def detect_cycle(N, M, edges):",
"function_name": "detect... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_cycle_dfs(graph, v, visited, rec_stack):\n visited[v] = True\n rec_stack[v] = True\n \n for neighbor in graph[v]:\n if not visit... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038618",
"row_id": 38618,
"seed_ids": "[10385]"
} | 0.650851 | Code_Contests_38618 | I | [
"has_cycle",
"detect_cycle",
"check_circular_relationships"
] | 3 | [
[
"check_circular_relationships",
"detect_cycle"
],
[
"detect_cycle",
"has_cycle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9c560c5a154b1004f77463f3c8fd0ebde0554c4d | 277fe181af9a689c20b09309f5aba21f40a6e11a | |||
v1.0 | instruct | Code_Contests | Code_Contests_38621_I | Write a program to calculate the sum of all divisors (excluding the number itself) of a given positive integer. If the sum of divisors equals the number, the number is classified as a "perfect number." Otherwise, the program should classify the number as "not a perfect number."
Input
The input consists of a sequence ... | def classify_number(n):
"""
Returns whether a given positive integer n is a 'perfect number'
or 'not a perfect number' based on the sum of its divisors.
"""
if n < 2:
return None
sum_divisors = 0
for i in range(1, n):
if n % i == 0:
sum_divisors += i
... | from solution import classify_number, classify_numbers_from_input
def test_classify_number():
assert classify_number(6) == "perfect number"
assert classify_number(28) == "perfect number"
assert classify_number(12) == "not a perfect number"
assert classify_number(496) == "perfect number"
assert clas... | [
{
"docstring": "Returns whether a given positive integer n is a 'perfect number' \nor 'not a perfect number' based on the sum of its divisors.",
"function_declaration": "def classify_number(n):",
"function_name": "classify_number",
"parameter_list": "(n)"
},
{
"docstring": "Classifies a list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def classify_numbers(numbers):\n \"\"\"\n Classifies each number in the list as a \"perfect number\" or \"not a perfect number\".\n \n Args:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038621",
"row_id": 38621,
"seed_ids": "[7278]"
} | 0.75714 | Code_Contests_38621 | I | [
"classify_number",
"classify_numbers_from_input"
] | 2 | [
[
"classify_numbers_from_input",
"classify_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f96140729eac700c37710f5e7a438720f1861ef5 | 6c78f23131bca1dc02087265ccd2e1bd8307600e | |||
v1.0 | instruct | Code_Contests | Code_Contests_38636_I | Mark is organizing a charity walk event and needs to set up a series of waypoints for participants. Each waypoint is defined by its coordinates on a 2D grid. Due to logistical constraints, some waypoints might need to be adjusted. Mark can move a specific number of waypoints within a rectangular area by a specified amo... | def is_valid_path(waypoints):
# Check if each waypoint is adjacent to the next one
for i in range(1, len(waypoints)):
x1, y1 = waypoints[i-1]
x2, y2 = waypoints[i]
if not (abs(x1 - x2) <= 1 and abs(y1 - y2) <= 1):
return False
return True
def process_queries(n, m, waypoi... | def test_charity_walk():
# Test case with valid initial waypoints and all within bounds
assert charity_walk(
5, 5, 5,
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5],
3,
[1, 1, 3, 3, 1, 1, 2, 2, 4, 4, -1, -1, 1, 1, 5, 5, 0, 1]
) == "NO"
# Test case with no moves
assert charity_wa... | [
{
"docstring": null,
"function_declaration": "def is_valid_path(waypoints):",
"function_name": "is_valid_path",
"parameter_list": "(waypoints)"
},
{
"docstring": null,
"function_declaration": "def process_queries(n, m, waypoints, queries):",
"function_name": "process_queries",
"p... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_path(n, m, k, waypoints, q, queries):\n def apply_query(ai, bi, ci, di, delta_x, delta_y, waypoints):\n new_waypoints = []\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038636",
"row_id": 38636,
"seed_ids": "[11727]"
} | 0.684871 | Code_Contests_38636 | I | [
"is_valid_path",
"process_queries",
"charity_walk"
] | 3 | [
[
"charity_walk",
"process_queries"
],
[
"process_queries",
"is_valid_path"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | a1e88f2a20bbe3af70a5620bbac8aaf9a32515af | e6d74f7d2a789fad79d52047cd33c28d5abfae62 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38674_I | **Robo Delivery:**
A futuristic city uses an autonomous robot to deliver packages across predefined locations. Each location in the city is represented as a coordinate on a Cartesian plane. The robot starts at the origin (0, 0) and needs to deliver packages to a sequence of coordinates provided by the user. The robot ... | def calculate_total_delivery_time(delivery_points):
"""
This function calculates the total delivery time given the delivery points.
"""
return len(delivery_points) * 2
def robot_delivery(D, deliveries, C, changes):
from collections import defaultdict
initial_time = calculate_total_delivery... | from solution import calculate_total_delivery_time, robot_delivery
def test_calculate_total_delivery_time():
assert calculate_total_delivery_time([(3, 4), (-1, -2), (1, 1)]) == 6
assert calculate_total_delivery_time([(0, 0)]) == 2
assert calculate_total_delivery_time([(3, 3), (3, 3)]) == 4
def test_robot_... | [
{
"docstring": "This function calculates the total delivery time given the delivery points.",
"function_declaration": "def calculate_total_delivery_time(delivery_points):",
"function_name": "calculate_total_delivery_time",
"parameter_list": "(delivery_points)"
},
{
"docstring": null,
"fu... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_total_delivery_time(delivery_points):\n \"\"\"\n This function calculates the total delivery time given the delivery points.\n \"\"\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038674",
"row_id": 38674,
"seed_ids": "[1067]"
} | 0.639227 | Code_Contests_38674 | I | [
"calculate_total_delivery_time",
"robot_delivery"
] | 2 | [
[
"robot_delivery",
"calculate_total_delivery_time"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cb6e1493c864299a39e2c14f7d176a976e500481 | a566062fb80ad4a829db881a299dae6763dd70ee | |||
v1.0 | instruct | Code_Contests | Code_Contests_38713_I | A logistics company needs to schedule the deliveries of packages to multiple destinations. For simplicity, the destinations are given as points on a 2D plane, with the company's warehouse located at the origin (0, 0). The company's delivery truck can only carry one package at a time and always returns to the warehouse ... | def distance(point1, point2):
"""
Calculate Euclidean distance between two points.
"""
return ((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)**0.5
def delivery_sequence(n, destinations):
"""
Determine the sequence to minimize total travel distance.
"""
start = (0, 0) # Wareho... | from solution import delivery_sequence, parse_input, parse_output
def test_example_1():
input_str = "3\n2 3\n-1 4\n-2 -2"
n, destinations = parse_input(input_str)
expected_output = [2, 1, 3]
output = delivery_sequence(n, destinations)
assert set(output) == set(expected_output)
def test_example_2()... | [
{
"docstring": "Calculate Euclidean distance between two points.",
"function_declaration": "def distance(point1, point2):",
"function_name": "distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Determine the sequence to minimize total travel distance.",
"function_declarati... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_distance(x, y):\n return (x**2 + y**2)**0.5\n\ndef find_delivery_sequence(n, coordinates):\n distances = [(i, calculate_distance(x, y))... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00038713",
"row_id": 38713,
"seed_ids": "[7009]"
} | 0.708115 | Code_Contests_38713 | I | [
"distance",
"delivery_sequence",
"parse_input",
"parse_output"
] | 4 | [
[
"delivery_sequence",
"distance"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 66b69d3f2afd539ecf0a3812de6a2b4dd64b96db | 9db25155b187253f04b0bc3ae218c67a1ca1016b | |||
v1.0 | instruct | Code_Contests | Code_Contests_38726_I | A space station has n modules connected by m bidirectional tunnels (a tunnel directly connects two different modules). Each module can either be working or non-working.
You need to ensure that there exists a backup route between any two working modules, meaning for every pair of working modules, there should be at le... | def find_connected_components(graph, n):
visited = [False] * n
components = []
def dfs(node):
stack = [node]
component = []
while stack:
u = stack.pop()
if not visited[u]:
visited[u] = True
component.append(u)
... | def test_additional_tunnels_needed_case1():
assert additional_tunnels_needed(4, 3, "1101", [(1, 2), (2, 3), (3, 4)]) == 1
def test_additional_tunnels_needed_case2():
assert additional_tunnels_needed(5, 4, "11110", [(1, 2), (2, 3), (3, 4), (4, 5)]) == 0
def test_additional_tunnels_needed_no_tunnels():
asse... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(graph, n):",
"function_name": "find_connected_components",
"parameter_list": "(graph, n)"
},
{
"docstring": null,
"function_declaration": "def additional_tunnels_needed(n, m, s, tunnels):",
"function_name": "... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport itertools\n\ndef min_additional_tunnels(n, m, s, edges):\n graph = defaultdict(list)\n working_mod... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00038726",
"row_id": 38726,
"seed_ids": "[3685]"
} | 0.591814 | Code_Contests_38726 | I | [
"find_connected_components",
"additional_tunnels_needed"
] | 2 | [
[
"additional_tunnels_needed",
"find_connected_components"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7fcb9326379e46e62cd9de48a114eaf07d788ef7 | a2222f89aa4ebe9b1e2e95d64b01dec18fe8177d | |||
v1.0 | instruct | Code_Contests | Code_Contests_38784_I | A specialized firework company is planning a spectacular show, and they have several fireworks lined up in a field. Each firework can be launched at a specific position and will cover a certain radius upon exploding. The fireworks are carefully designed such that no two fireworks will have overlapping explosion areas.
... | import math
def are_fireworks_overlap(f1, f2):
x1, y1, r1 = f1
x2, y2, r2 = f2
distance_sq = (x1 - x2) ** 2 + (y1 - y2) ** 2
radius_sum_sq = (r1 + r2) ** 2
return distance_sq < radius_sum_sq
def max_fireworks(fireworks):
n = len(fireworks)
max_count = 0
for i in range(1, 1 << n):
... | import pytest
from solution import main
def test_fireworks_example_1():
input_data = "4\n0 0 5\n10 0 5\n0 10 5\n10 10 5\n3\n-5 -5 3\n-5 5 3\n5 5 3\n3\n-5 0 2\n0 5 2\n5 0 2\n2\n0 0 2\n2 2 2\n0"
expected_output = [4, 3, 3, 1]
assert main(input_data) == expected_output
def test_fireworks_minimal_case():
... | [
{
"docstring": null,
"function_declaration": "def are_fireworks_overlap(f1, f2):",
"function_name": "are_fireworks_overlap",
"parameter_list": "(f1, f2)"
},
{
"docstring": null,
"function_declaration": "def max_fireworks(fireworks):",
"function_name": "max_fireworks",
"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": "from math import sqrt\n\ndef max_fireworks(fireworks):\n \"\"\"\n Returns the maximum number of fireworks that can be triggered simultaneously withou... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038784",
"row_id": 38784,
"seed_ids": "[6762]"
} | 0.645213 | Code_Contests_38784 | I | [
"are_fireworks_overlap",
"max_fireworks",
"main"
] | 3 | [
[
"max_fireworks",
"are_fireworks_overlap"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46100f5e5fef1b3c36b6cbb8731581b620a0835c | 7c01af0434afafbceb4c4a0fcf6119522e2451f8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38807_I | In a distant land, there is a kingdom that uses a unique form of currency called "Kimmies". The kingdom has the following denominations of Kimmies: 1, 3, and 4. The king has decreed that every citizen should pay a certain amount, N, in taxes. However, the taxes must be paid using the minimum number of Kimmies possible.... | def min_kimmies(n):
"""
Returns the minimum number of Kimmies required to pay exactly n amount of taxes.
"""
if n == 0:
return 0
denominations = [1, 3, 4]
dp = [float('inf')] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
for coin in denominations:
if i -... | from solution import min_kimmies, process_kimmies_input
def test_min_kimmies():
assert min_kimmies(6) == 2
assert min_kimmies(10) == 3
assert min_kimmies(14) == 4
assert min_kimmies(1) == 1
assert min_kimmies(0) == 0
assert min_kimmies(5) == 2
def test_process_kimmies_input():
assert proce... | [
{
"docstring": "Returns the minimum number of Kimmies required to pay exactly n amount of taxes.",
"function_declaration": "def min_kimmies(n):",
"function_name": "min_kimmies",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of inputs and returns the results for minimum Kimmies ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_kimmies(N):\n \"\"\"\n Returns the minimum number of Kimmies required to pay exactly N amount of taxes.\n \"\"\"\n \n if N == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038807",
"row_id": 38807,
"seed_ids": "[9252]"
} | 0.620372 | Code_Contests_38807 | I | [
"min_kimmies",
"process_kimmies_input"
] | 2 | [
[
"process_kimmies_input",
"min_kimmies"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f123537a4939b004168504b449e1130c0ab706a9 | 05187a9b27c186e3b65fce9f08293b460dec7402 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38823_I | Implement an algorithm to solve the following problem: You are responsible for managing a network of servers in a data center. Each server holds logs of varying sizes that need to be transferred to a central server for analysis.
Due to a limitation in network bandwidth, you can only transfer logs between servers if th... | def can_empty_servers(N, B, logs):
"""
Determines if all servers can be emptied given the bandwidth capacity
:param N: int - number of servers
:param B: int - bandwidth capacity
:param logs: list of int - initial sizes of logs on each server
:return: tuple - (bool, list of str) - whether it is ... | def test_example1():
N = 3
B = 5
logs = [8, 10, 3]
assert can_empty_servers(N, B, logs) == (True, [
"1 5", "1 3", "2 5", "2 5", "3 3"
])
def test_example2():
N = 2
B = 2
logs = [5, 4]
assert can_empty_servers(N, B, logs) == (True, [
"1 2", "1 2", "1 1", "2 2", "2 2"
... | [
{
"docstring": "Determines if all servers can be emptied given the bandwidth capacity\n\n:param N: int - number of servers\n:param B: int - bandwidth capacity\n:param logs: list of int - initial sizes of logs on each server\n:return: tuple - (bool, list of str) - whether it is possible and the sequence of opera... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def possible_to_empty_servers(N, B, log_sizes):\n operations = []\n for i in range(N):\n while log_sizes[i] > 0:\n transfer_size = ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00038823",
"row_id": 38823,
"seed_ids": "[10685]"
} | 0.638621 | Code_Contests_38823 | I | [
"can_empty_servers",
"solve"
] | 2 | [
[
"solve",
"can_empty_servers"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 179f9423ea1e3e8ad2a8932214e9dc3c54957dc8 | 3e51298edce3ef3e9b68b2d71381cdf747007b8e | |||
v1.0 | instruct | Code_Contests | Code_Contests_38861_I | A group of workers is given a number of tasks to complete. Each task has a specific start time, end time, and reward associated with its completion. The workers need to complete as many non-overlapping tasks as possible to maximize their total reward. Each worker can only work on one task at a time, and the tasks can v... | def taskScheduler(tasks):
"""
Determines the maximum total reward the workers can achieve given the list of tasks.
Args:
tasks (list of tuples): A list of tuples where each tuple contains three integers
(start time, end time, reward) representing a task.
Return... | def test_task_scheduler_example_1():
assert wrapper(4, [(1, 3, 10), (2, 5, 10), (4, 6, 5), (6, 7, 7)]) == 22
def test_task_scheduler_example_2():
assert wrapper(3, [(1, 2, 3), (2, 3, 2), (3, 4, 6)]) == 11
def test_task_scheduler_no_overlap():
assert wrapper(3, [(1, 2, 5), (3, 4, 10), (5, 6, 15)]) == 30
d... | [
{
"docstring": "Determines the maximum total reward the workers can achieve given the list of tasks.\n\nArgs:\ntasks (list of tuples): A list of tuples where each tuple contains three integers \n (start time, end time, reward) representing a task.\n\nReturns:\nint: The maximum total rewar... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def taskScheduler(N, tasks):\n \"\"\"\n Determines the maximum total reward by completing non-overlapping tasks.\n \n Parameters:\n N (int):... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00038861",
"row_id": 38861,
"seed_ids": "[786]"
} | 0.709983 | Code_Contests_38861 | I | [
"taskScheduler",
"wrapper"
] | 2 | [
[
"wrapper",
"taskScheduler"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d49335790db094317100d7d0c2831646f1f25f3e | 1cc9dc74ca3035f9b353e3ad31112bab9e5c828c | |||
v1.0 | instruct | Code_Contests | Code_Contests_38892_I | In a universe with infinite grids, there exist different types of blocks. Each type of block occupies a different amount of cells and each type of block can be placed in multiple orientations (rotations). You are tasked with determining if it is possible to completely fill a given rectangular grid using a specific set ... | from itertools import product
def rotate(block):
""" Generates all rotations of the block """
rotations = []
current = block
for _ in range(4):
new_block = ["".join(row) for row in zip(*current[::-1])]
if new_block not in rotations:
rotations.append(new_block)
curren... | import pytest
from solution import fill_grid_task
def test_case_1():
inputs = [
(4, 4, 2, [
{'orientations': [["XX", "XX"], ["XX", "XX"]]},
{'orientations': [["X..", "XXX"], ["X..", "XXX"], ["X..", "XXX"]]}
])
]
expected_output = ["Case 1: No"]
assert fill_grid_t... | [
{
"docstring": "Generates all rotations of the block ",
"function_declaration": "def rotate(block):",
"function_name": "rotate",
"parameter_list": "(block)"
},
{
"docstring": "Generates all unique rotations for all blocks ",
"function_declaration": "def generate_orientations(blocks):",
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import product\n\ndef can_fill_grid(H, W, blocks):\n \"\"\"\n Function to determine if the grid can be completely filled with the give... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00038892",
"row_id": 38892,
"seed_ids": "[1243]"
} | 0.73257 | Code_Contests_38892 | I | [
"rotate",
"generate_orientations",
"can_fill_grid",
"fill_grid_task"
] | 4 | [
[
"fill_grid_task",
"can_fill_grid"
],
[
"fill_grid_task",
"generate_orientations"
],
[
"generate_orientations",
"rotate"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a0cae404b3e95be9988d58c7c4ee05816d7e0e5d | 4098fa6a59f0a1d2a9066406b05524a9557b873f | |||
v1.0 | instruct | Code_Contests | Code_Contests_38898_I | A group of friends love to play Quicksort-inspired card games. One day, they decided to create a simplified version of the Quicksort algorithm to sort their decks faster. They asked you to help them implement it. The goal is to implement a simplified version of Quicksort, where you only need to sort a list of distinct ... | def quicksort(arr):
if len(arr) <= 1:
return arr
else:
mid_index = len(arr) // 2
pivot = arr[mid_index]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + qui... | def test_simplified_quicksort_single_element():
input_data = "1\n5"
assert simplified_quicksort(input_data) == "5"
def test_simplified_quicksort_sorted_order():
input_data = "5\n1 2 3 4 5"
assert simplified_quicksort(input_data) == "1 2 3 4 5"
def test_simplified_quicksort_reverse_order():
input_d... | [
{
"docstring": null,
"function_declaration": "def quicksort(arr):",
"function_name": "quicksort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def simplified_quicksort(input_data):",
"function_name": "simplified_quicksort",
"parameter_list": "(input_... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr):\n if len(arr) <= 1:\n return arr\n else:\n mid_index = len(arr) // 2\n pivot = arr[mid_index]\n left ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038898",
"row_id": 38898,
"seed_ids": "[6630]"
} | 0.549401 | Code_Contests_38898 | I | [
"quicksort",
"simplified_quicksort"
] | 2 | [
[
"simplified_quicksort",
"quicksort"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2a827084265a9528dbb95ea24eeefe4d6d518ab1 | 367d370ffebdc67c192f126729774ed9e81c1af1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38902_I | A transportation company wants to optimize its delivery route to minimize cost and time, taking into account varying cargo sizes and delivery deadlines. The company has a fleet of different types of vehicles, each with different fuel efficiencies, capacities, and maximum allowable distances per trip. Additionally, some... | def parse_input(input_text):
"""
Parses the input text and returns a structured representation of the vehicles, locations, and roads.
"""
lines = input_text.strip().split("\n")
index = 0
number_of_vehicle_types = int(lines[index])
index += 1
vehicles = []
for _ in range(number_of_ve... | from solution import main_process
def test_case_1():
input_text = """\
2
truck 5.0 2000 500
van 10.0 1000 300
3
1 500 6
2 1000 8
3 1500 10
4
0 1 250 50
0 2 300 60 van
1 3 350 70 truck
2 3 400 80
"""
output_text = """\
truck impossible
van impossible"""
assert main_process(input_text).strip() == output... | [
{
"docstring": "Parses the input text and returns a structured representation of the vehicles, locations, and roads.",
"function_declaration": "def parse_input(input_text):",
"function_name": "parse_input",
"parameter_list": "(input_text)"
},
{
"docstring": null,
"function_declaration": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef calculate_optimal_route(vehicle_data, location_data, road_data):\n v = len(vehicle_data)\n l = len(location_data)\n r = len(ro... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038902",
"row_id": 38902,
"seed_ids": "[6237]"
} | 0.630405 | Code_Contests_38902 | I | [
"parse_input",
"calculate_delivery_cost_and_time",
"optimize_delivery_route",
"main_process"
] | 4 | [
[
"main_process",
"optimize_delivery_route"
],
[
"optimize_delivery_route",
"calculate_delivery_cost_and_time"
],
[
"optimize_delivery_route",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 62d956c2a94beffcdaa6575e9f88b9f599e4b914 | 8c48cf870137769cad89fa8a1c69134be5868719 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38924_I | Tanya loves prime numbers. She has recently learned about an interesting property of prime numbers in arithmetic progressions and decided to create a problem around it. Given integers a, d, and n, she defines a sequence as follows:
b_1 = a,
b_2 = a + d,
b_3 = a + 2d,
...
In other words, b_i = a + (i-1)d.
For the giv... | import math
def is_prime(num):
"""
Determines if a number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return ... | from solution import is_prime, nth_prime_in_sequence
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) ... | [
{
"docstring": "Determines if a number is a prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines the n-th prime number in the arithmetic sequence defined by a and d.\nReturns -1 if the n-th prime number do... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num < 2:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038924",
"row_id": 38924,
"seed_ids": "[4398]"
} | 0.614852 | Code_Contests_38924 | I | [
"is_prime",
"nth_prime_in_sequence"
] | 2 | [
[
"nth_prime_in_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 137921fb682ca95c061f484572ac404ac500b8c9 | 408be02c0c4e98f93dd92e17511e6b6c682ebf94 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38934_I | ## River Crossing Puzzle
You are given a group of people and animals that need to cross a river using a boat. The boat can carry only two entities at a time (either two people, two animals, or one person and one animal). All entities can row the boat, but there are specific constraints that must be adhered to ensure a... | def river_crossing(entities):
# Given simplified constraints, the minimum crossings problem can be solved by a generic greedy approach.
n = len(entities)
if n <= 2:
return n
return 2 * (n - 1) - 1
def general_river_crossing(n, entity_info):
return river_crossing(entity_info) | from solution import general_river_crossing
def test_single_entity():
assert general_river_crossing(1, ["person1"]) == 1
def test_two_entities():
assert general_river_crossing(2, ["person1", "animal1"]) == 2
def test_three_entities():
assert general_river_crossing(3, ["person1", "animal1", "person2"]) ==... | [
{
"docstring": null,
"function_declaration": "def river_crossing(entities):",
"function_name": "river_crossing",
"parameter_list": "(entities)"
},
{
"docstring": null,
"function_declaration": "def general_river_crossing(n, entity_info):",
"function_name": "general_river_crossing",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def river_crossing(entities):\n # Given simplified constraints, the minimum crossings problem can be solved by a generic greedy approach.\n n = len(e... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038934",
"row_id": 38934,
"seed_ids": "[3539]"
} | 0.617252 | Code_Contests_38934 | I | [
"river_crossing",
"general_river_crossing"
] | 2 | [
[
"general_river_crossing",
"river_crossing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eeaf35eed271e1d7aa440ac8a599042ef76f6fe7 | 1bc9ece26d1fb9078b9d0f0fe1cf76d06cdd48a6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38941_I | Arthur is a lover of prime numbers and their properties. One day, Arthur came across an interesting problem involving prime numbers and divisors. He wants to find the smallest prime number `p` greater than or equal to a given integer `n` such that `p` has exactly `k` divisors.
A prime number is a natural number greate... | import math
def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
... | from solution import smallest_prime_with_k_divisors
def test_smallest_prime_with_k_divisors_case1():
assert smallest_prime_with_k_divisors(10, 2) == 11
def test_smallest_prime_with_k_divisors_case2():
assert smallest_prime_with_k_divisors(20, 2) == 23
def test_smallest_prime_with_k_divisors_case3():
asse... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the smallest prime number greater than or equal to n\nthat has exactly k divisors.",
"function_declaration": "def... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00038941",
"row_id": 38941,
"seed_ids": "[12323]"
} | 0.611117 | Code_Contests_38941 | I | [
"is_prime",
"smallest_prime_with_k_divisors"
] | 2 | [
[
"smallest_prime_with_k_divisors",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5cf1ff4a5e97e52230a1a146295ebf76facb87c0 | f1e22926f2211e580facb4ec0fe8ae8bb431abec | |||
v1.0 | instruct | Code_Contests | Code_Contests_38959_I | A popular game called "Land of Kings" involves leveling up challenges where players traverse through various terrains. Each terrain section has a different difficulty level, represented by integers. Players can level up when moving to a terrain section of a higher difficulty and level down when moving to a terrain sect... | def calculate_levels(t, challenges):
results = []
for challenge in challenges:
n = challenge[0]
terrains = challenge[1]
max_level_up = 0
max_level_down = 0
for i in range(1, n):
if terrains[i] > terrains[i - 1]:
max_level_up = max(max_lev... | from solution import parse_and_calculate_levels
def test_example_case():
input_data = """4
6
15 85 45 70 95 120
3
10 30 5
2
50 20
5
80 80 80 80 80"""
expected_output = [(70, 40), (20, 25), (0, 30), (0, 0)]
assert parse_and_calculate_levels(input_data) == expected_output
def test_all_increasing():
inpu... | [
{
"docstring": null,
"function_declaration": "def calculate_levels(t, challenges):",
"function_name": "calculate_levels",
"parameter_list": "(t, challenges)"
},
{
"docstring": null,
"function_declaration": "def parse_and_calculate_levels(input_data):",
"function_name": "parse_and_cal... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_levels(t, challenges):\n results = []\n \n for challenge in challenges:\n n, terrains = challenge\n max_level_up = 0\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00038959",
"row_id": 38959,
"seed_ids": "[6969]"
} | 0.619636 | Code_Contests_38959 | I | [
"calculate_levels",
"parse_and_calculate_levels"
] | 2 | [
[
"parse_and_calculate_levels",
"calculate_levels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1024baf0630a380248e4411303e55bc7b948d44a | be5e72ea23471883898a84d52f01d871eb516740 | |||
v1.0 | instruct | Code_Contests | Code_Contests_38974_I | A company needs to manage its employee data in a new software system. Each employee has a unique ID, a name, and a salary. The company needs to calculate the total salary budget for a specific department, given a list of employees and their respective department IDs. However, the salary budget should only include the s... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def calculate_salary... | def test_is_prime():
assert is_prime(2)
assert is_prime(11)
assert not is_prime(1)
assert not is_prime(4)
assert is_prime(13)
def test_calculate_salary_budget():
employees = [
(1, 'Alice', 1500, 101),
(2, 'Bob', 1700, 102),
(3, 'Charlie', 1800, 101),
(4, 'David',... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Calculate total salary budget for a department considering only prime salaries.",
"function_declaration": "def calculate_s... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00038974",
"row_id": 38974,
"seed_ids": "[7092]"
} | 0.584022 | Code_Contests_38974 | I | [
"is_prime",
"calculate_salary_budget"
] | 2 | [
[
"calculate_salary_budget",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6c46ab9eff8507b3f4a477efa9f2cda9a1410631 | d8334a5b948921f8786915a9446eba6d740f03c0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.