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_15710_I | John has always been fascinated by prime numbers. One day, he came across a problem that intrigued him. He wants to find the smallest prime number greater than a given number n. Can you help him solve this problem?
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | 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(28) == False
def test_smallest_prime_greater_than():
assert smallest_prime_greater_than(12) == 13
assert smallest... | [
{
"docstring": "Check 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 n.",
"function_declaration": "def smallest_prime_greater_than(n):",
"fu... | [
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_1 | {
"original_instruction": "",
"prompt_id": "00015710",
"row_id": 15710,
"seed_ids": "[9019]"
} | 0.55444 | Code_Contests_15710 | I | [
"is_prime",
"smallest_prime_greater_than"
] | 2 | [
[
"smallest_prime_greater_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4877ad86441fcadd2790675cfa7776606fb48f0d | 9d5ded073cd67a79d2e6aa6af9daba4c81558216 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15741_I | Create a poker hand evaluator that determines the type of poker hand value from given card hands. In poker, certain hand values are ranked higher than others. Here, you need to classify the poker hands into categorized rank.
Cards are represented in the following format:
A♠, A♥, K♦, etc. Here, 'A' stands for Ace, 'K' ... | from collections import Counter
def rank_poker_hand(hand):
ranks_dict = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'T': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14}
def is_flush(hand):
suits = [card[-1] for card in hand]
return len(set(suits)) == 1
def i... | def test_rank_poker_hand():
assert rank_poker_hand('A♠ K♠ Q♠ J♠ T♠'.split()) == 'Straight Flush'
assert rank_poker_hand('9♦ 9♣ 9♥ 9♠ 3♦'.split()) == 'Four of a Kind'
assert rank_poker_hand('3♣ 3♦ 3♠ 6♣ 6♦'.split()) == 'Full House'
assert rank_poker_hand('2♥ 4♥ 6♥ 8♥ T♥'.split()) == 'Flush'
assert ra... | [
{
"docstring": null,
"function_declaration": "def rank_poker_hand(hand):",
"function_name": "rank_poker_hand",
"parameter_list": "(hand)"
},
{
"docstring": null,
"function_declaration": "def rank_all_hands(hands):",
"function_name": "rank_all_hands",
"parameter_list": "(hands)"
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import itertools\n\n# Helper function to determine rank and suit of a card\ndef get_rank(card):\n return card[0]\n\ndef get_suit(card):\n return card... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015741",
"row_id": 15741,
"seed_ids": "[6545]"
} | 0.597184 | Code_Contests_15741 | I | [
"rank_poker_hand",
"rank_all_hands"
] | 2 | [
[
"rank_all_hands",
"rank_poker_hand"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | eabfbb5d3cdad085ef34221de5f23ed72fcf992c | 4ca5b6c4d2633ab33bc2685a117d02476de7fe71 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15875_I | You are given a binary tree with not more than 10^4 nodes. Each node has an integer value associated with it. Your task is to perform the following queries on this binary tree:
1. **u v**: Find the maximum value in the subtree rooted at node `u` and replace it with `v`.
2. **u**: Return the maximum value present in t... | class TreeNode:
def __init__(self, val):
self.val = val
self.children = []
def build_tree(n, node_values, parent_indices):
nodes = {i: TreeNode(node_values[i]) for i in range(n)}
root = None
for i in range(n):
parent = parent_indices[i]
if parent == 0:
root =... | import pytest
from solution import build_tree, process_queries, TreeNode
def test_example():
n = 7
node_values = [5, 3, 6, 8, 7, 2, 4]
parent_indices = [0, 1, 1, 3, 3, 2, 2]
queries = [(1, 10), (1,), (2,), (3, 20), (1,)]
# Building tree
root = build_tree(n, node_values, parent_indices)
... | [] | [
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, val):\n self.val = val\n self.children = []\n\ndef build_tree(n, node_values, parent_indices):\n n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00015875",
"row_id": 15875,
"seed_ids": "[3032]"
} | 0.560521 | Code_Contests_15875 | I | [
"build_tree",
"find_max_val_rooted_at",
"replace_max_val",
"max_in_subtree",
"process_queries"
] | 5 | [
[
"process_queries",
"max_in_subtree"
],
[
"process_queries",
"replace_max_val"
],
[
"replace_max_val",
"max_in_subtree"
]
] | 3 | [
"process_queries"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 25dd4a72071677313a9bb64ec225c8833ab8606c | 889124f8b957d9216765213371f850e6c113f22a | |||
v1.0 | instruct | Code_Contests | Code_Contests_15883_I | Your task is to find the number of distinct prime factors of each integer in an input list.
**Input:**
- The input consists of multiple data sets, each containing a single integer n (2 ≤ n ≤ 100000).
- The end of input is indicated by n = 0.
**Output:**
- For each data set, print the number of distinct prime factor... | def count_distinct_prime_factors(n):
"""
Returns the number of distinct prime factors of the integer n.
"""
distinct_factors = set()
# Check for number of 2s that divide n
while n % 2 == 0:
distinct_factors.add(2)
n = n // 2
# n must be odd at this point so we can ... | from solution import count_distinct_prime_factors, process_numbers_until_zero
def test_count_distinct_prime_factors():
assert count_distinct_prime_factors(12) == 2 # factors are 2 and 3
assert count_distinct_prime_factors(18) == 2 # factors are 2 and 3
assert count_distinct_prime_factors(29) == 1 # fact... | [
{
"docstring": "Returns the number of distinct prime factors of the integer n.",
"function_declaration": "def count_distinct_prime_factors(n):",
"function_name": "count_distinct_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Processes a list of numbers and returns the number of d... | [
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 math import isqrt\n\ndef count_distinct_prime_factors(n):\n \"\"\"\n Returns the number of distinct prime factors of the integer n.\n \"\"\"\... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00015883",
"row_id": 15883,
"seed_ids": "[10197]"
} | 0.645276 | Code_Contests_15883 | I | [
"count_distinct_prime_factors",
"process_numbers_until_zero"
] | 2 | [
[
"process_numbers_until_zero",
"count_distinct_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46666f3064ed9752f3d723571c9db8e2ec30a9da | eae004c1ac1904ac8929c47bf64e15811b72c363 | |||
v1.0 | instruct | Code_Contests | Code_Contests_15937_I | Write a function to simulate the stock market trading process with limited trade transactions and given market trends.
### Description
You are given a list of daily stock prices for a particular stock over a period of `n` days. Based on these prices, your goal is to maximize profit by performing at most `k` transactio... | def max_profit(n: int, k: int, prices: list[int]) -> int:
if n == 0:
return 0
# If k is greater than n//2, it's equivalent to an unlimited transaction problem
if k >= n // 2:
return unlimited_transactions(prices)
# Create a 3D DP array
dp = [[0] * (k + 1) for _ in range(n)]... | from solution import max_profit
def test_max_profit_example():
assert max_profit(6, 2, [3, 2, 6, 5, 0, 3]) == 7
def test_max_profit_no_transactions():
assert max_profit(5, 0, [1, 2, 3, 4, 5]) == 0
def test_max_profit_no_profit():
assert max_profit(5, 1, [5, 4, 3, 2, 1]) == 0
def test_max_profit_single_d... | [
{
"docstring": null,
"function_declaration": "def max_profit(n, k, prices):",
"function_name": "max_profit",
"parameter_list": "(n, k, prices)"
},
{
"docstring": null,
"function_declaration": "def unlimited_transactions(prices):",
"function_name": "unlimited_transactions",
"param... | [
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 max_profit(n, k, prices):\n if not prices or k == 0:\n return 0\n\n # If k is greater than n // 2, it's essentially the same as an infinit... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00015937",
"row_id": 15937,
"seed_ids": "[1210]"
} | 0.736454 | Code_Contests_15937 | I | [
"max_profit",
"unlimited_transactions"
] | 2 | [
[
"max_profit",
"unlimited_transactions"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc264f50e84b33a6182e31d91635b4fcb85a9907 | 1ef1cbdf3fc2f1a765ec0d73eba73ea6039382dd | |||
v1.0 | instruct | Code_Contests | Code_Contests_15989_I | You are given an array of n elements consisting of integers ranging from 1 to n inclusive. You are required to rearrange the elements of the array into a permutation that maximizes the product of the following sum:
sum = (absolute difference between 1st element and 2nd element) +
(absolute difference be... | def max_sum_permutation(arr):
"""
Rearranges the elements of the array to maximize the sum of absolute differences between consecutive elements.
Parameters:
arr (list): A list of integers.
Returns:
list: The rearranged list to achieve the maximum possible sum.
"""
#... | from solution import max_sum_permutation, max_sum_value
def test_max_sum_permutation():
assert max_sum_permutation([2, 1, 4, 3]) == [4, 1, 3, 2]
def test_max_sum_value():
assert max_sum_value([2, 1, 4, 3]) == 6
def test_max_sum_permutation_with_large_input():
n = 100000
arr = list(range(1, n + 1)... | [
{
"docstring": "Rearranges the elements of the array to maximize the sum of absolute differences between consecutive elements.\n\nParameters:\n arr (list): A list of integers.\n \nReturns:\n list: The rearranged list to achieve the maximum possible sum.",
"function_declaration": "def max_sum_permut... | [
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 maximize_sum_of_absolute_differences(arr):\n \"\"\"\n Rearranges the elements of the array into a permutation that maximizes the sum\n of the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00015989",
"row_id": 15989,
"seed_ids": "[5638]"
} | 0.71966 | Code_Contests_15989 | I | [
"max_sum_permutation",
"max_sum_value"
] | 2 | [
[
"max_sum_value",
"max_sum_permutation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a195024659b77ec81c3ba19d5fadd05da2549b35 | 28b28350f09f8cda601690c5ad355be0b57a0f28 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16025_I | You are given a grid of size n x m filled with non-negative integers. You need to find a rectangle within this grid such that the sum of the elements of the rectangle is as large as possible. The rectangle can be of any size, but must have at least one element.
Input
The first line contains two integers n and m (1 ≤ ... | def find_max_sum_rectangle(n, m, grid):
"""
Finds the maximum sum of any rectangle within the grid.
:param n: Number of rows in the grid
:param m: Number of columns in the grid
:param grid: 2D list representing the grid
:return: Maximum sum of any rectangle in the grid
"""
max_sum = flo... | from solution import find_max_sum_rectangle
def test_case_1():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
assert find_max_sum_rectangle(3, 3, grid) == 45
def test_case_2():
grid = [
[1, 2, 3],
[4, 5, 6]
]
assert find_max_sum_rectangle(2, 3, grid) == 21
... | [
{
"docstring": "Finds the maximum sum of any rectangle within the grid.\n\n:param n: Number of rows in the grid\n:param m: Number of columns in the grid\n:param grid: 2D list representing the grid\n:return: Maximum sum of any rectangle in the grid",
"function_declaration": "def find_max_sum_rectangle(n, m, ... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_sum_subrectangle(grid):\n \"\"\"\n Finds the maximum possible sum of any subrectangle within the given grid.\n \"\"\"\n def max_subarra... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00016025",
"row_id": 16025,
"seed_ids": "[6939]"
} | 0.713485 | Code_Contests_16025 | I | [
"find_max_sum_rectangle",
"kadane_algorithm"
] | 2 | [
[
"find_max_sum_rectangle",
"kadane_algorithm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 716df094f15322269a6f8d6e477cddd71f88ec78 | dc9f07f8e8bfc49350d7b0bef654dedaa4426911 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16053_I | Write a program that reads a sequence of integers and determines whether each number is a prime number. Each input set will be terminated by a zero, which should not be processed. The program should read input until a zero is encountered and then output "Prime" or "Not Prime" for each number in the sequence indicating ... | def is_prime(n):
"""
Determines if a number is a prime number.
:param n: An integer to check for primality.
:return: True if the number is prime, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in rang... | from solution import is_prime, check_prime_sequence
def test_is_prime():
# Test known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(11) == True
# Test known non-prime numbers
assert is_prime... | [
{
"docstring": "Determines if a number is a prime number.\n\n:param n: An integer to check for primality.\n:return: True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a sequ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016053",
"row_id": 16053,
"seed_ids": "[3630]"
} | 0.704314 | Code_Contests_16053 | I | [
"is_prime",
"check_prime_sequence"
] | 2 | [
[
"check_prime_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6aa647974300d4e47187c5feede68fcd958cd77d | 9cd7d13b8615b57b5a26de8cb97fc50650c399e7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16060_I | You are given a set of firewall rules and a list of access requests. Each firewall rule specifies a range of IP addresses that are allowed, and each access request contains an IP address. You need to determine whether each access request will be allowed based on the given rules.
Input
The first line contains two inte... | def ip_to_int(ip):
"""
Convert a dotted-quad IP address to a 32-bit integer.
"""
octets = map(int, ip.split('.'))
return sum(o << (8 * i) for i, o in enumerate(reversed(list(octets))))
def firewall_rules(n, q, rules, requests):
allowed_ranges = []
for rule in rules:
start, end = map... | from solution import firewall_rules
def test_firewall_rules():
rules = [
("192.168.1.1", "192.168.1.10"),
("10.0.0.1", "10.0.0.255"),
("172.16.4.5", "172.16.4.10")
]
requests = [
"192.168.1.5",
"10.0.0.200",
"172.16.4.11",
"8.8.8.8"
]
... | [
{
"docstring": "Convert a dotted-quad IP address to a 32-bit integer.",
"function_declaration": "def ip_to_int(ip):",
"function_name": "ip_to_int",
"parameter_list": "(ip)"
},
{
"docstring": null,
"function_declaration": "def firewall_rules(n, q, rules, requests):",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def ip_to_int(ip):\n \"\"\"\n Converts a dotted-quad IP address to a 32-bit integer.\n \"\"\"\n parts = list(map(int, ip.split('.')))\n retu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016060",
"row_id": 16060,
"seed_ids": "[984]"
} | 0.567878 | Code_Contests_16060 | I | [
"ip_to_int",
"firewall_rules"
] | 2 | [
[
"firewall_rules",
"ip_to_int"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fc566e03f696a121a6a25707bbfd40c39a41a16b | 60f779df22a6759697bf3d3cdb9acf2e9df163f9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16085_I | You are given a grid of size n x m filled with '.' and '#' characters, where '.' represents an empty cell and '#' represents an obstacle. The objective is to determine the length of the longest path of consecutive empty cells that the robot can travel on without touching any obstacle, starting from the top-left corner ... | from collections import deque
def longest_path(grid):
n = len(grid)
m = len(grid[0])
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return -1
queue = deque([(0, 0, 0)])
visited = set((0, 0))
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while queue:
x, ... | from solution import longest_path_from_input
def test_case_1():
n = 3
m = 3
grid = [
"..#",
".#.",
"..."
]
assert longest_path_from_input(n, m, grid) == 4
def test_case_2():
n = 4
m = 4
grid = [
"....",
"##..",
"..#.",
"..##"
... | [
{
"docstring": null,
"function_declaration": "def longest_path(grid):",
"function_name": "longest_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def longest_path_from_input(n, m, matrix):",
"function_name": "longest_path_from_input",
"parameter... | [
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 longest_path(n, m, grid):\n \"\"\"\n Find the longest path from (0,0) to (n-1,m-1) in an n x m grid filled with ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016085",
"row_id": 16085,
"seed_ids": "[6479]"
} | 0.741057 | Code_Contests_16085 | I | [
"longest_path",
"longest_path_from_input"
] | 2 | [
[
"longest_path_from_input",
"longest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1323e42235c66dc785474cb53d848d43a965c58c | 31d62e1040d5d5c9d5f14e045802829f63e2daf7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16111_I | A genealogist is tracing the lineage of a famous dynasty. As part of their research, they need to analyze the family tree to determine the closest common ancestor (CCA) of two given members. The family tree is represented as a series of parent-child relationships.
You are given the family tree as a set of relationship... | def find_ancestors(tree, individual):
ancestors = set()
while individual in tree:
individual = tree[individual]
ancestors.add(individual)
return ancestors
def find_cca(tree, individual1, individual2):
ancestors1 = find_ancestors(tree, individual1)
ancestors2 = find_ancestors(tree, i... | def test_find_ancestors():
tree = {'Bob': 'Adam', 'Charlie': 'Adam', 'David': 'Bob', 'Ellen': 'Bob',
'Frank': 'Charlie', 'Grace': 'Charlie', 'Henry': 'Ellen', 'Isaac': 'Ellen'}
assert find_ancestors(tree, 'David') == {'Bob', 'Adam'}
assert find_ancestors(tree, 'Henry') == {'Ellen', 'Bob', 'Adam... | [
{
"docstring": null,
"function_declaration": "def find_ancestors(tree, individual):",
"function_name": "find_ancestors",
"parameter_list": "(tree, individual)"
},
{
"docstring": null,
"function_declaration": "def find_cca(tree, individual1, individual2):",
"function_name": "find_cca"... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_closest_common_ancestor(n, relationships, person1, person2):\n from collections import defaultdict, deque\n\n # Build the parent dictionary\... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00016111",
"row_id": 16111,
"seed_ids": "[6731]"
} | 0.569073 | Code_Contests_16111 | I | [
"find_ancestors",
"find_cca",
"closest_common_ancestor"
] | 3 | [
[
"closest_common_ancestor",
"find_cca"
],
[
"find_cca",
"find_ancestors"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | fc41d0026c43af2577cc6252651f005e1201b438 | e17840c317957bf7f7d353be3c72cc3a0bfedda5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16134_I | Write a function that takes as input a list of integers which represents the vertices of a graph, and a list of pairs of integers which represents the edges of the graph. The task is to determine if the graph is a bipartite graph.
A graph is bipartite if it is possible to divide its vertices into two disjoint sets suc... | from collections import deque, defaultdict
def is_bipartite(adj_list, n):
"""
Determines if the given graph is bipartite.
adj_list: Adjacency list representation of the graph
n: Number of vertices
"""
colors = [-1] * (n + 1)
for i in range(1, n + 1):
if colors[i] == -1: #... | def test_is_bipartite_empty_graph():
input_data = "1\n0 0"
assert is_bipartite_graph(input_data) == "Yes"
def test_is_bipartite_small_graph():
input_data = "1\n3 2\n1 2\n2 3"
assert is_bipartite_graph(input_data) == "Yes"
def test_is_bipartite_cycle_of_four():
input_data = "1\n4 4\n1 2\n2 3\n3 4\n... | [
{
"docstring": "Determines if the given graph is bipartite.\n\nadj_list: Adjacency list representation of the graph\nn: Number of vertices",
"function_declaration": "def is_bipartite(adj_list, n):",
"function_name": "is_bipartite",
"parameter_list": "(adj_list, n)"
},
{
"docstring": null,
... | [
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_bipartite_graph(n, adj):\n color = [-1] * n\n\n def dfs(node, c):\n color[node] = c\n for neighbor in adj[node]:\n if... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016134",
"row_id": 16134,
"seed_ids": "[6346]"
} | 0.612172 | Code_Contests_16134 | I | [
"is_bipartite",
"process_input",
"is_bipartite_graph"
] | 3 | [
[
"is_bipartite_graph",
"process_input"
],
[
"process_input",
"is_bipartite"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 2f796fd2099d04ad0e76e3b4dd388c08ed49ca52 | bd1b7e44128b6eafce774d6b193ca10501c6b377 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16179_I | You are given a grid with n rows and m columns. Each cell in the grid can either be empty or occupied by an obstacle. You are asked to determine the number of ways to traverse from the top-left corner of the grid to the bottom-right corner, moving only right or down at each step, while avoiding obstacles.
**Input**
T... | def num_ways_to_traverse(n, m, grid):
MOD = 1000000007
dp = [[0]*m for _ in range(n)]
if grid[0][0] == '#':
return 0
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '#':
dp[i][j] = 0
else:
if i... | def test_example_1():
input_str = "2 3\n...\n.#."
expected_output = 1
assert grid_ways_from_input(input_str) == expected_output
def test_example_2():
input_str = "3 3\n...\n.#.\n..."
expected_output = 2
assert grid_ways_from_input(input_str) == expected_output
def test_blocked_start():
inp... | [
{
"docstring": null,
"function_declaration": "def num_ways_to_traverse(n, m, grid):",
"function_name": "num_ways_to_traverse",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def grid_ways_from_input(input_str):",
"function_name": "grid_ways_from_inp... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1_000_000_007\n\ndef count_paths(n, m, grid):\n # Initialize the dp table with zeros\n dp = [[0] * m for _ in range(n)]\n \n # If the sta... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00016179",
"row_id": 16179,
"seed_ids": "[684]"
} | 0.783888 | Code_Contests_16179 | I | [
"num_ways_to_traverse",
"grid_ways_from_input"
] | 2 | [
[
"grid_ways_from_input",
"num_ways_to_traverse"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 22d809e48ecfe2ab0e259a7160acde31b1fd78c7 | d3eec35f58151d356c899813948ba3b9c0965046 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16200_I | Problem D: Password Validator
Alice, an IT security expert, has been tasked with implementing a password validation module for a new application. The program takes multiple user-input passwords and validates them based on the following criteria:
1. The password must be at least 8 characters long.
2. It must contain a... | import re
def validate_password(password):
"""
Validates the given password based on the specified criteria.
Parameters:
password (str): The password to validate.
Returns:
str: "Valid" if the password meets all the criteria, otherwise "Invalid".
"""
if len(password) < 8:
... | from solution import validate_password, process_passwords
def test_validate_password():
assert validate_password("Passw0rd!") == "Valid"
assert validate_password("WeakPass") == "Invalid"
assert validate_password("Str0ngPass!") == "Valid"
assert validate_password("Sh0rt1!") == "Invalid"
assert valid... | [
{
"docstring": "Validates the given password based on the specified criteria.\n\nParameters:\npassword (str): The password to validate.\n\nReturns:\nstr: \"Valid\" if the password meets all the criteria, otherwise \"Invalid\".",
"function_declaration": "def validate_password(password):",
"function_name"... | [
0,
0,
0,
0,
0,
0,
1,
0,
1,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef validate_password(password):\n \"\"\"\n Validate a password based on the given criteria:\n 1. At least 8 characters long.\n 2.... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00016200",
"row_id": 16200,
"seed_ids": "[6138]"
} | 0.61896 | Code_Contests_16200 | I | [
"validate_password",
"process_passwords"
] | 2 | [
[
"process_passwords",
"validate_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4301dd80463234ab9938ac371415c59c01a3b44c | d94a2e0c7aefb4ecad69ba198c8390471b5bb4cd | |||
v1.0 | instruct | Code_Contests | Code_Contests_16208_I | Mr. A is designing a software to shuffle a list of integers. However, he wants to ensure the shuffle is fair and every sequence of integers produced is unique along with its position. To implement this, he comes up with a function to find all unique permutations of a list of integers in lexicographic order. Your task i... | from itertools import permutations
def unique_permutations(arr):
"""
Generate all unique permutations of a list of integers in sorted order.
"""
# Generate permutations and use a set to remove duplicates
perms = sorted(set(permutations(arr)))
return perms
def generate_all_permutations(test_cas... | from solution import process_input
def test_unique_permutations_case1():
T = 1
cases = [
(3, [1, 2, 3])
]
expected_output = [
"1 2 3\n1 3 2\n2 1 3\n2 3 1\n3 1 2\n3 2 1"
]
assert process_input(T, cases) == expected_output
def test_unique_permutations_case2():
T = 1
cases... | [
{
"docstring": "Generate all unique permutations of a list of integers in sorted order.",
"function_declaration": "def unique_permutations(arr):",
"function_name": "unique_permutations",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def generate_all_permutati... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef unique_permutations(lst):\n \"\"\"\n Returns all unique permutations of a list of integers in lexicographic... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016208",
"row_id": 16208,
"seed_ids": "[2920]"
} | 0.72039 | Code_Contests_16208 | I | [
"unique_permutations",
"generate_all_permutations",
"process_input"
] | 3 | [
[
"generate_all_permutations",
"unique_permutations"
],
[
"process_input",
"generate_all_permutations"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d7234b02f77dda8767e697d3dc3161d01bef61b3 | b6e940c894aabaac6db9682cc1f9aa05b4c8dd04 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16242_I | **Task:** Implement a function that determines whether the sequences of daily temperatures for different cities are periodically repeating. Given a number of cities and for each city the sequence of daily temperatures, determine if the sequence follows a periodic pattern and, if so, return the length of the smallest pe... | def find_smallest_period(sequence):
"""
Determine the smallest period of the sequence if it is periodic.
If the sequence is not periodic, return -1.
:param sequence: List of integers representing daily temperatures
:return: Integer representing the smallest period or -1 if not periodic
"""
... | from solution import smallest_periods
def test_periodic_pattern():
n = 3
sequences = [
[1, 2, 3, 1, 2, 3, 1, 2, 3], # Period of 3
[5, 5, 5, 5, 5, 5, 5], # Period of 1
[1, 2, 3, 4, 5, 6, 7] # Not periodic
]
expected_output = [3, 1, -1]
assert smallest_periods(... | [
{
"docstring": "Determine the smallest period of the sequence if it is periodic.\nIf the sequence is not periodic, return -1.\n\n:param sequence: List of integers representing daily temperatures\n:return: Integer representing the smallest period or -1 if not periodic",
"function_declaration": "def find_smal... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_period(sequence):\n \"\"\"\n Determine the smallest period of the given sequence of daily temperatures.\n If no period exists, return -1.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016242",
"row_id": 16242,
"seed_ids": "[7244]"
} | 0.55894 | Code_Contests_16242 | I | [
"find_smallest_period",
"smallest_periods"
] | 2 | [
[
"smallest_periods",
"find_smallest_period"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c37d42996faa6ff31cb181ad80989a57360148d9 | 1dd527d8ac473c39803913e3f19f8cc3c370f5ef | |||
v1.0 | instruct | Code_Contests | Code_Contests_16335_I | You are a software engineer working on optimizing the operations for a delivery drone. The drone operates in a 3D grid space where each position can be described by three coordinates (x, y, z). The drone can execute a sequence of movements to navigate through the grid: "up" (increase z), "down" (decrease z), "north" (i... | def final_drone_position(n, movements):
"""
Given a number of commands `n` and a list of `movements`,
return the final coordinates of the drone.
"""
x, y, z = 0, 0, 0
for movement in movements:
if movement == "up":
z += 1
elif movement == "down":
z -... | def test_final_drone_position():
# Test case 1
n = 3
movements = ["up", "north", "east"]
assert final_drone_position(n, movements) == (1, 1, 1)
# Test case 2
n = 4
movements = ["up", "up", "down", "west"]
assert final_drone_position(n, movements) == (-1, 0, 1)
def test_process_move... | [
{
"docstring": "Given a number of commands `n` and a list of `movements`, \nreturn the final coordinates of the drone.",
"function_declaration": "def final_drone_position(n, movements):",
"function_name": "final_drone_position",
"parameter_list": "(n, movements)"
},
{
"docstring": "Given a l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def drone_navigation(movements):\n results = []\n idx = 0\n \n while idx < len(movements):\n n = int(movements[idx])\n if n == 0:... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016335",
"row_id": 16335,
"seed_ids": "[12276]"
} | 0.60423 | Code_Contests_16335 | I | [
"final_drone_position",
"process_movements"
] | 2 | [
[
"process_movements",
"final_drone_position"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 61a1649e075915a5eecd49d5c56dcbfcb6c3ab9a | ab8c9bb98202bab64363f701aedf9755a4938853 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16417_I | problem
In a certain institute, students are given the opportunity to take additional courses during the summer. Each student can select from a list of available summer courses, with the constraint that they must attend exactly one course in each of the given time slots. Courses are offered in multiple time slots and ... | def count_course_combinations(datasets):
results = []
for dataset in datasets:
time_slots = {}
for course, slot in dataset:
if slot not in time_slots:
time_slots[slot] = 0
time_slots[slot] += 1
if len(time_slots) < max(time_s... | def test_process_input():
input_data = "2\n4\n101 1\n102 2\n103 1\n104 2\n0 0\n5\n201 1\n202 1\n203 2\n204 2\n205 3\n0 0\n0\n"
expected_output = [
[(101, 1), (102, 2), (103, 1), (104, 2)],
[(201, 1), (202, 1), (203, 2), (204, 2), (205, 3)]
]
assert process_input(input_data) == expected_o... | [
{
"docstring": null,
"function_declaration": "def count_course_combinations(datasets):",
"function_name": "count_course_combinations",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def process_input(data):",
"function_name": "process_input",
"par... | [
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 count_course_selections(datasets):\n from collections import defaultdict\n results = []\n \n for dataset in datasets:\n slot_courses... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00016417",
"row_id": 16417,
"seed_ids": "[13314]"
} | 0.648667 | Code_Contests_16417 | I | [
"count_course_combinations",
"process_input",
"solution"
] | 3 | [
[
"solution",
"count_course_combinations"
],
[
"solution",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 6a0ee7dde716b3d799b6676973a2e254f071a4d2 | 77702af393eb4a7f86609074267711c5879d3b57 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16444_I | You are given an array of positive integers arr of length n. You can perform the following operation on the array:
- Pick any two elements arr[i] and arr[j] where \(1 \leq i, j \leq n\) and \(i \neq j\), replace arr[i] and arr[j] with the greatest common divisor (GCD) of these two numbers, denoted as gcd(arr[i], arr[... | import math
from functools import reduce
def gcd_of_array(arr):
"""
Returns the GCD of all elements in the array.
"""
return reduce(math.gcd, arr)
def max_possible_min_element(n, arr):
"""
Given an array of positive integers, returns the maximum possible value
that the smallest element of... | from solution import max_possible_min_element
def test_example_1():
assert max_possible_min_element(5, [2, 10, 6, 14, 8]) == 2
def test_example_2():
assert max_possible_min_element(4, [3, 9, 15, 27]) == 3
def test_example_3():
assert max_possible_min_element(3, [5, 10, 15]) == 5
def test_example_4():
... | [
{
"docstring": "Returns the GCD of all elements in the array.",
"function_declaration": "def gcd_of_array(arr):",
"function_name": "gcd_of_array",
"parameter_list": "(arr)"
},
{
"docstring": "Given an array of positive integers, returns the maximum possible value \nthat the smallest element ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef max_possible_minimal_value(n, arr):\n \"\"\"\n Returns the maximum possible value that the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016444",
"row_id": 16444,
"seed_ids": "[396]"
} | 0.732439 | Code_Contests_16444 | I | [
"gcd_of_array",
"max_possible_min_element"
] | 2 | [
[
"max_possible_min_element",
"gcd_of_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cfc4d20f360f7c3bc96baf64ac0913aeff7047ba | 6d215db5902c151ce344dc84c0a4d2cdf16dddca | |||
v1.0 | instruct | Code_Contests | Code_Contests_16450_I | Background
You are tasked with developing a program to authenticate passwords based on specific rules devised by a security firm. They have identified that a secure password must meet certain criteria to be considered strong. Additionally, they need the program to provide suggestions for improving weak passwords. The ... | def check_password(password):
"""
Checks if a password is secure based on given criteria and provides suggestions if not.
"""
criteria = [
("length", lambda x: len(x) >= 8, "At least 8 characters long"),
("uppercase", lambda x: any(c.isupper() for c in x), "At least one uppercase letter"... | from solution import check_password, check_passwords
def test_secure_password():
assert check_password("Password123@") == "Secure"
def test_short_password():
assert check_password("Pass1@") == "Not Secure\nAt least 8 characters long\nSuggestion: Add more characters."
def test_no_uppercase():
assert check... | [
{
"docstring": "Checks if a password is secure based on given criteria and provides suggestions if not.",
"function_declaration": "def check_password(password):",
"function_name": "check_password",
"parameter_list": "(password)"
},
{
"docstring": "Checks a list of passwords and reports if th... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_password(password):\n errors = []\n\n if len(password) < 8:\n errors.append(\"At least 8 characters long\")\n\n if not any(c.isup... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00016450",
"row_id": 16450,
"seed_ids": "[1868]"
} | 0.641292 | Code_Contests_16450 | I | [
"check_password",
"check_passwords"
] | 2 | [
[
"check_passwords",
"check_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fcb57bf5398e1d73b4b93d1724fb6ecb3cef244b | 03ac833bfbd03ecf5a5ee127979a0bb3512e3659 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16470_I | Kapil loves palindromes and he wants to count them in different ranges. For a given range [L, R], help Kapil to find how many numbers in this range are palindromes. A number is a palindrome if it reads the same backward as forward. For example, 121 and 1331 are palindromes, whereas 123 and 100 are not.
INPUT:
First l... | def is_palindrome(n):
"""
Checks if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def count_palindromes(L, R):
"""
Returns the count of palindrome numbers in the range [L, R].
"""
count = 0
for num in range(L, R + 1):
if is_palindrome(num):
count +=... | from solution import is_palindrome, count_palindromes, process_cases
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1331) == True
assert is_palindrome(100) == False
def test_count_palindromes():
assert count_palindromes(1, 10) ==... | [
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of palindrome numbers in the range [L, R].",
"function_declaration": "def count_palindrome... | [
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_palindrome(n):\n \"\"\"\n Checks if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef count_palindromes(L, R):\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016470",
"row_id": 16470,
"seed_ids": "[8922]"
} | 0.696019 | Code_Contests_16470 | I | [
"is_palindrome",
"count_palindromes",
"process_cases"
] | 3 | [
[
"count_palindromes",
"is_palindrome"
],
[
"process_cases",
"count_palindromes"
]
] | 2 | [
"process_cases"
] | false | [] | false | pytest | true | [] | true | 1f0bc0c5d12944c15532503b00d61d462316a3d1 | 178098616a6a590bcf5c3c4b2915b990299586d6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16490_I | An n-sided polygon can be defined by its vertices, each represented in a two-dimensional plane by coordinates (x, y). A vertex belongs to the polygon if it is connected by an edge, i.e., a straight line, to two other vertices. The polygon is said to be simple if its edges do not intersect except at their endpoints.
Wr... | def polygon_area(n, vertices):
"""
Calculate the area of an n-sided polygon using the shoelace formula.
Args:
n (int): The number of vertices of the polygon.
vertices (List[Tuple[int, int]]): The coordinates of the vertices in counter-clockwise order.
Returns:
float: The area of the po... | import pytest
from solution import polygon_area, string_to_polygon_area
def test_polygon_area():
assert polygon_area(4, [(0, 0), (4, 0), (4, 3), (0, 3)]) == 12.000000
assert polygon_area(3, [(1, 1), (2, 3), (3, 1)]) == 2.000000
def test_polygon_area_large_coordinates():
assert polygon_area(4, [(1000000, 1... | [
{
"docstring": "Calculate the area of an n-sided polygon using the shoelace formula.\n\nArgs:\nn (int): The number of vertices of the polygon.\nvertices (List[Tuple[int, int]]): The coordinates of the vertices in counter-clockwise order.\n\nReturns:\nfloat: The area of the polygon rounded to six decimal places.... | [
0,
0,
0,
0,
0,
1,
0,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def polygon_area(n, coordinates):\n \"\"\"\n Calculate the area of a polygon using the shoelace formula.\n \n Arguments:\n n : int : Number ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016490",
"row_id": 16490,
"seed_ids": "[6293]"
} | 0.597475 | Code_Contests_16490 | I | [
"polygon_area",
"string_to_polygon_area"
] | 2 | [
[
"string_to_polygon_area",
"polygon_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1e2ed933fee19aba94a05eaf40276fc6adede2cb | fd0c6412cf39e2b54eba4a3475551035e00b0c76 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16501_I | MatrixZigzag
Problem Statement
You are given a matrix M of size N x M, where M_i,j denotes the element at i-th row and j-th column of the matrix.
You need to create a zigzag traversal of the matrix. Starting from the top-left element, the traversal should move right until the end of the row, then move downwards to t... | def zigzag_traversal(matrix):
"""
Returns the elements of the matrix in zigzag order.
"""
N = len(matrix)
M = len(matrix[0])
result = []
for i in range(N):
if i % 2 == 0:
result.extend(matrix[i])
else:
result.extend(matrix[i][::-1])
retur... | def test_matrix_zigzag_sample():
input_str = "3 4\n1 2 3 4\n5 6 7 8\n9 10 11 12"
expected_output = "1 2 3 4 8 7 6 5 9 10 11 12"
assert matrix_zigzag(input_str) == expected_output
def test_matrix_zigzag_single_row():
input_str = "1 4\n1 2 3 4"
expected_output = "1 2 3 4"
assert matrix_zigzag(inp... | [
{
"docstring": "Returns the elements of the matrix in zigzag order.",
"function_declaration": "def zigzag_traversal(matrix):",
"function_name": "zigzag_traversal",
"parameter_list": "(matrix)"
},
{
"docstring": "Parse the input string, extract the matrix, and return the zigzag traversal.",
... | [
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 zigzag_traversal(matrix):\n \"\"\"\n This function returns the elements of the matrix\n in a zigzag traversal order.\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016501",
"row_id": 16501,
"seed_ids": "[12285]"
} | 0.588331 | Code_Contests_16501 | I | [
"zigzag_traversal",
"matrix_zigzag"
] | 2 | [
[
"matrix_zigzag",
"zigzag_traversal"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 858de192e88e75edeb1dd03288f1e727d0feebae | 4a5b9bd8ced59c6e7fdd2a58f37b6d1a938ffbe8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16524_I | Cluster Groups
In a newly discovered dataset, you are given a list of numbers. To perform data simplification, you will create a "Cluster Group Number" (CGN) for each number in the list. The CGN is calculated as follows:
1. Split the number into individual digits.
2. Calculate the sum of these digits repeatedly unti... | def get_cgn_cluster_group(number):
"""
Calculate the cluster group number for a given number.
"""
while number >= 10:
number = sum(int(digit) for digit in str(number))
cluster_groups = "ABCDEFGHIJ"
return cluster_groups[number]
def distinct_cluster_groups(numbers):
"""
Calc... | from solution import get_cgn_cluster_group, distinct_cluster_groups, process_test_cases
def test_get_cgn_cluster_group():
assert get_cgn_cluster_group(128) == 'C'
assert get_cgn_cluster_group(35) == 'I'
assert get_cgn_cluster_group(467) == 'I'
assert get_cgn_cluster_group(50) == 'F'
def test_distinct_... | [
{
"docstring": "Calculate the cluster group number for a given number.",
"function_declaration": "def get_cgn_cluster_group(number):",
"function_name": "get_cgn_cluster_group",
"parameter_list": "(number)"
},
{
"docstring": "Calculate and return the sorted distinct cluster groups for the giv... | [
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 digital_root(n):\n while n >= 10:\n n = sum(int(digit) for digit in str(n))\n return n\n\ndef cluster_groups(numbers):\n cluster_map = ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00016524",
"row_id": 16524,
"seed_ids": "[12915]"
} | 0.596151 | Code_Contests_16524 | I | [
"get_cgn_cluster_group",
"distinct_cluster_groups",
"process_test_cases"
] | 3 | [
[
"distinct_cluster_groups",
"get_cgn_cluster_group"
],
[
"process_test_cases",
"distinct_cluster_groups"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 894cf4c90e0232d62bf5a041a2b5c7108f7c1334 | b977a5ce99b4544ae474509156d545e41c368677 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16531_I | Olivia is fascinated by prime numbers and recently she encountered a new problem. She needs to find the K-th prime number that is greater than a given number M. Help Olivia find this K-th prime number.
Input:
The first line contains a number T, the number of test cases.
The next T lines each contain 2 integers M and K... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def kth_prime_greater_than_m(m, k):
count ... | from solution import is_prime, kth_prime_greater_than_m, find_kth_primes
def test_is_prime():
assert not is_prime(1)
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(30)
def test_kth_prime_greater_than_m():
assert k... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def kth_prime_greater_than_m(m, k):",
"function_name": "kth_prime_greater_than_m",
"parameter_list": "(m, k)"
}... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016531",
"row_id": 16531,
"seed_ids": "[2887]"
} | 0.588258 | Code_Contests_16531 | I | [
"is_prime",
"kth_prime_greater_than_m",
"find_kth_primes"
] | 3 | [
[
"find_kth_primes",
"kth_prime_greater_than_m"
],
[
"kth_prime_greater_than_m",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | db911ee1f20ad649bcaefaffa234216a6e5bdef9 | 8b8e720d76a96d6ee5ea7ff62184eac57e475450 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16579_I | A detective is trying to track the location history of a suspect based on GPS data that shows the suspect's position at different times of the day. The data is provided as a sequence of positions on a 2D plane. However, to make it easier to analyze, the detective needs to know if at any point the suspect was within a s... | def is_within_square(x, y, cx, cy, k):
"""
Checks if point (x, y) lies within or on the border of a square with side length k
centered at (cx, cy).
"""
half_side = k / 2
return (cx - half_side <= x <= cx + half_side) and (cy - half_side <= y <= cy + half_side)
def track_suspect_positions(n, k, ... | from solution import track_suspect_positions
def test_case_1():
n = 5
k = 2
q = 3
positions = [(1, 2), (2, 2), (3, 3), (4, 4), (5, 5)]
queries = [(2, 2), (5, 5), (0, 0)]
assert track_suspect_positions(n, k, positions, queries) == ["YES", "YES", "NO"]
def test_case_2():
n = 4
k = 4
... | [
{
"docstring": "Checks if point (x, y) lies within or on the border of a square with side length k\ncentered at (cx, cy).",
"function_declaration": "def is_within_square(x, y, cx, cy, k):",
"function_name": "is_within_square",
"parameter_list": "(x, y, cx, cy, k)"
},
{
"docstring": "For each... | [
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_inside_square(x, y, cx, cy, k):\n \"\"\"\n Checks if the point (x, y) is within or on the boundary\n of a square centered at (cx, cy) with ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016579",
"row_id": 16579,
"seed_ids": "[1079]"
} | 0.648791 | Code_Contests_16579 | I | [
"is_within_square",
"track_suspect_positions"
] | 2 | [
[
"track_suspect_positions",
"is_within_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0210d6c38e0583fe6f10d0554f086c74012b2025 | 93487c3d79bc18a7ba8aa17d3d0aa4771ec31653 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16596_I | Farmer Bob has a rectangular farm represented as an MxN grid, where each cell is either planted with a crop or is an empty patch. Farmer Bob is interested in finding out the largest rectangular area within his farm that is completely made up of crops.
Your task is to write a program that takes the farm information as ... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of... | import pytest
from solution import main
def test_example_case():
input_data = "4 5\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0\n" \
"4 4\n0 1 1 1\n1 1 1 1\n1 0 0 1\n0 1 1 0\n" \
"2 2\n1 1\n1 0\n0 0"
expected_result = [6, 6, 2]
assert main(input_data) == expected_result
de... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle_area(matrix):",
"function_name": "max_rectangle_area",
"paramet... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def maximalRectangle(matrix):\n if not matrix:\n return 0\n\n max_area = 0\n n = len(matrix[0])\n height = [0] * (n + 1)\n \n for ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016596",
"row_id": 16596,
"seed_ids": "[9774]"
} | 0.629537 | Code_Contests_16596 | I | [
"max_histogram_area",
"max_rectangle_area",
"largest_rectangle_of_crops",
"parse_input",
"main"
] | 5 | [
[
"largest_rectangle_of_crops",
"max_rectangle_area"
],
[
"max_rectangle_area",
"max_histogram_area"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f5af8659b2b0a9a295d99ed32c12009f003f1d61 | e45d976297da72fb8f1758a364cf24544a5a3be5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16597_I | Given a list of words, you need to find the longest common prefix among all the words in the list. If there is no common prefix, return an empty string.
Input:
The first line contains an integer n (1 ≤ n ≤ 100), the number of words in the list. Each of the next n lines contains a single word consisting of lowercase L... | def longest_common_prefix(words):
"""
Function to find the longest common prefix among a list of words.
Args:
words (list of str): The list of words to analyze.
Returns:
str: The longest common prefix among the words.
"""
if not words:
return ""
# The longest c... | from solution import longest_common_prefix
def test_longest_common_prefix_example1():
words = ["flower", "flow", "flight"]
assert longest_common_prefix(words) == "fl"
def test_longest_common_prefix_example2():
words = ["dog", "racecar", "car", "cat"]
assert longest_common_prefix(words) == ""
def test... | [
{
"docstring": "Function to find the longest common prefix among a list of words.\n\nArgs:\nwords (list of str): The list of words to analyze.\n\nReturns:\nstr: The longest common prefix among the words.",
"function_declaration": "def longest_common_prefix(words):",
"function_name": "longest_common_pref... | [
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 longest_common_prefix(words):\n \"\"\"\n Returns the longest common prefix among all the words in the given list.\n If there is no common pref... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016597",
"row_id": 16597,
"seed_ids": "[792]"
} | 0.841462 | Code_Contests_16597 | I | [
"longest_common_prefix",
"is_common_prefix"
] | 2 | [
[
"longest_common_prefix",
"is_common_prefix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2470d3b56b6d6985114c0af484c3b824eeb889d3 | 9735a16d52aa82919dceda24b2b2355d50651489 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16668_I | ### Problem Statement
Alex has recently become interested in exploring number theory, specifically in factoring positive integers. He wants to write a program that determines if a given number is a "quasi-prime." A number is considered quasi-prime if it has exactly three distinct prime factors. For example, 30 is quas... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import check_quasi_prime
def test_quasi_prime_yes():
assert check_quasi_prime(30) == "Yes" # 2 * 3 * 5
def test_quasi_prime_no_two_primes():
assert check_quasi_prime(100) == "No" # 2 * 2 * 5 * 5
def test_quasi_prime_no_non_prime():
assert check_quasi_prime(1) == "No" # 1 is not quasi-pri... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Helper function to count distinct prime factors of a number.",
"function_declaration": "def prime_facto... | [
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 is_quasi_prime(n):\n \"\"\"\n Determine if a given number `n` is a quasi-prime. A number is quasi-prime if it has exactly three distinct prime fa... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00016668",
"row_id": 16668,
"seed_ids": "[4830]"
} | 0.616045 | Code_Contests_16668 | I | [
"is_prime",
"prime_factors_count",
"is_quasi_prime",
"check_quasi_prime"
] | 4 | [
[
"check_quasi_prime",
"is_quasi_prime"
],
[
"is_quasi_prime",
"prime_factors_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 05fe230b59cee408994c28b87fd92b55fb99fe98 | fe1f8964d8e471a5ac14201d8885b4c69432d250 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16682_I | Problem: C - Path Navigation
In this problem, you are tasked with creating a system that helps navigate through a complex system of paths. The system is represented as a directed graph where each node denotes a location and each edge represents a one-way path between the locations.
### Task:
Write a program that han... | from collections import defaultdict, deque
def build_graph(V, E, edges):
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
return graph
def bfs(graph, start, goal):
visited = set()
queue = deque([start])
while queue:
node = queue.popleft()
if node == ... | from solution import path_navigation
def test_path_navigation_direct_paths():
V = 5
E = 5
edges = [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)]
Q = 3
queries = [(1, 3), (2, 5), (4, 1)]
expected = ["YES", "YES", "NO"]
assert path_navigation(V, E, edges, Q, queries) == expected
def test_path_navi... | [
{
"docstring": null,
"function_declaration": "def build_graph(V, E, edges):",
"function_name": "build_graph",
"parameter_list": "(V, E, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs(graph, start, goal):",
"function_name": "bfs",
"parameter_list": "(graph, start... | [
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 sys\nsys.setrecursionlimit(20000)\n\ndef build_graph(V, edges):\n graph = defaultdict(list)\n for u, v in... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016682",
"row_id": 16682,
"seed_ids": "[6557]"
} | 0.696501 | Code_Contests_16682 | I | [
"build_graph",
"bfs",
"handle_queries",
"path_navigation"
] | 4 | [
[
"handle_queries",
"bfs"
],
[
"path_navigation",
"build_graph"
],
[
"path_navigation",
"handle_queries"
]
] | 3 | [
"handle_queries"
] | false | [] | false | pytest | true | [] | true | 9fb5944d87b177de7f018756903509dcbb5479a9 | 57453b4ed2b32be3f1d62e12fe885529be1335f2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16693_I | You are given a data network consisting of N nodes and M bi-directional edges. Each edge connects two nodes and has an associated positive integer weight. Your task is to determine the minimum possible total weight of a spanning tree for this network. The network may have disconnected components, and in that case, you ... | def find(parent, i):
"""
A utility function to find the subset a particular element i belongs to.
"""
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
"""
A function that does union of two sets of x... | import pytest
from solution import minimum_spanning_tree
def test_minimum_spanning_tree_example_input():
N = 4
M = 5
edges = [(1, 2, 1), (1, 3, 4), (2, 3, 2), (2, 4, 5), (3, 4, 3)]
assert minimum_spanning_tree(N, M, edges) == 6
def test_minimum_spanning_tree_no_edges():
N = 4
M = 0
edges =... | [
{
"docstring": "A utility function to find the subset a particular element i belongs to.",
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": "A function that does union of two sets of x and y based on rank.",
"funct... | [
0,
0,
0,
0,
1,
0,
1,
0,
0
] | 2 | hard | 0.222 | {
"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):... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016693",
"row_id": 16693,
"seed_ids": "[10698]"
} | 0.810211 | Code_Contests_16693 | I | [
"find",
"union",
"kruskal_mst",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"minimum_spanning_tree",
"kruskal_mst"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 92a096144fd89416bdccab56b7db783b08fcd843 | 9d3d751c75449b4a0e6dddda80f6e52dddc8f710 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16720_I | You are given an array of n integers and a series of m queries. Each query consists of two integers l and r, and you need to output the sum of the elements from index l to r in the array.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100000) — the number of elements in the array and the number of que... | def prefix_sums(array):
"""
Returns the prefix sums of the input array.
"""
n = len(array)
prefix = [0] * (n + 1)
for i in range(1, n + 1):
prefix[i] = prefix[i - 1] + array[i - 1]
return prefix
def range_sum(prefix, l, r):
"""
Returns the sum of the elements from index l to... | from solution import prefix_sums, range_sum, process_queries
def test_prefix_sums():
assert prefix_sums([10, 20, 30, 40, 50]) == [0, 10, 30, 60, 100, 150]
assert prefix_sums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
def test_range_sum():
prefix = prefix_sums([10, 20, 30,... | [
{
"docstring": "Returns the prefix sums of the input array.",
"function_declaration": "def prefix_sums(array):",
"function_name": "prefix_sums",
"parameter_list": "(array)"
},
{
"docstring": "Returns the sum of the elements from index l to r in the array using the prefix sums.",
"functio... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def array_query_sums(n, m, array, queries):\n \"\"\"\n Given an array and a set of queries, returns the sums of elements from index l to r for each q... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016720",
"row_id": 16720,
"seed_ids": "[6212]"
} | 0.711582 | Code_Contests_16720 | I | [
"prefix_sums",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"prefix_sums"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | c8ccdd349aca9339c3a050a6eac5de489367d377 | e7ef5975aedf00d5334c990cf92eb987b0b1f7f7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16724_I | Henry loves trees, especially binary trees. He has a collection of integers which he wants to insert into an initially empty binary search tree (BST). After building the tree by inserting all integers from his collection (in the given order), he's interested in computing the height of the tree.
The height of a binary ... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def insert_into_bst(root, value):
if root is None:
return TreeNode(value)
if value < root.value:
root.left = insert_into_bst(root.left, value)
else:
root.righ... | from solution import compute_bst_heights
def test_single_case():
test_cases = [(5, 10, 5, 15, 3, 7)]
assert compute_bst_heights(test_cases) == [2]
def test_multiple_cases():
test_cases = [
(5, 10, 5, 15, 3, 7),
(6, 3, 2, 8, 5, 1, 7, 4),
(4, 6, 10, 4, 8)
]
assert compute_bst... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n \ndef insert(root, key)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016724",
"row_id": 16724,
"seed_ids": "[8983]"
} | 0.623907 | Code_Contests_16724 | I | [
"insert_into_bst",
"bst_height",
"compute_bst_heights"
] | 3 | [
[
"compute_bst_heights",
"bst_height"
],
[
"compute_bst_heights",
"insert_into_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | d3a9412c8988235e23681b8c27d43761ec5dfd3c | 95a35c8c0aafb385a968005f45e54da10e9008ef | |||
v1.0 | instruct | Code_Contests | Code_Contests_16776_I | You are given an undirected connected graph with n nodes and m edges. Each edge has a weight associated with it, which is a positive integer. Your task is to compute the minimum spanning tree (MST) of this graph. Additionally, if the MST is unique, you should output "UNIQUE", otherwise output "AMBIGUOUS".
A minimum sp... | import heapq
def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
parent[rootY] = rootX
... | def test_example_1():
n = 4
m = 5
edges = [(0, 1, 1), (1, 2, 2), (2, 3, 1), (3, 0, 2), (0, 2, 2)]
minimum_spanning_tree(n, m, edges) # should print 5 and UNIQUE
def test_example_2():
n = 3
m = 3
edges = [(0, 1, 1), (1, 2, 1), (2, 0, 2)]
minimum_spanning_tree(n, m, edges) # should prin... | [
{
"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 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import defaultdict\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(pa... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016776",
"row_id": 16776,
"seed_ids": "[11153]"
} | 0.795883 | Code_Contests_16776 | I | [
"find",
"union",
"kruskal",
"minimum_spanning_tree"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_spanning_tree",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 8cd10f23e5e518ee089d9858f811854250588960 | 885684489e0d3806ec74e398161bc0917024ebc9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16791_I | A group of science students is conducting an experiment on a rare and unique type of plant. Each plant is characterized by its unique growth index number (an integer). The students are interested in observing how the plants grow over several days. For each plant, they compute a "growth pattern" score, which is the prod... | def growth_pattern_score(n):
"""
Calculates the growth pattern score of a number.
"""
while n >= 10:
product = 1
while n > 0:
product *= n % 10
n //= 10
n = product
return n
def sum_growth_pattern_scores(A, B):
"""
Calculates the sum of growth... | from solution import growth_pattern_score, sum_growth_pattern_scores, process_test_cases
def test_growth_pattern_score():
assert growth_pattern_score(345) == 0
assert growth_pattern_score(10) == 0
assert growth_pattern_score(49) == 8
assert growth_pattern_score(81) == 8
assert growth_pattern_score(... | [
{
"docstring": "Calculates the growth pattern score of a number.",
"function_declaration": "def growth_pattern_score(n):",
"function_name": "growth_pattern_score",
"parameter_list": "(n)"
},
{
"docstring": "Calculates the sum of growth pattern scores for corrected growth index numbers [A, B]... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_growth_pattern_score(num):\n while num > 9:\n product = 1\n while num > 0:\n product *= num % 10\n num //= 1... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00016791",
"row_id": 16791,
"seed_ids": "[591]"
} | 0.636282 | Code_Contests_16791 | I | [
"growth_pattern_score",
"sum_growth_pattern_scores",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"sum_growth_pattern_scores"
],
[
"sum_growth_pattern_scores",
"growth_pattern_score"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 19ab06517dd2d58e5421a60b06bcaec18f8a7607 | 50d01f5b9f20561a96a017e96af17f344076ab0c | |||
v1.0 | instruct | Code_Contests | Code_Contests_16801_I | Given an array of integers, you need to find the minimum length of a contiguous subarray of which the sum is greater than or equal to a given target number `s`. If there isn't one, return 0 instead.
### Input
- The first line of the input contains a single integer `n` (1 ≤ n ≤ 10^5), the length of the array.
- The sec... | def min_subarray_len(s, nums):
"""
Returns the minimum length of a contiguous subarray of which the sum is greater than or equal to s.
If there isn't one, return 0.
"""
n = len(nums)
if n == 0:
return 0
left = 0
sum_current = 0
min_length = float('inf')
for righ... | from solution import find_min_length_subarray
def test_example_case_1():
assert find_min_length_subarray(8, [2, 3, 1, 2, 4, 3, 7, 1], 7) == 1
def test_example_case_2():
assert find_min_length_subarray(6, [1, 2, 3, 4, 5, 6], 15) == 3
def test_no_valid_subarray():
assert find_min_length_subarray(5, [1, 1, ... | [
{
"docstring": "Returns the minimum length of a contiguous subarray of which the sum is greater than or equal to s.\nIf there isn't one, return 0.",
"function_declaration": "def min_subarray_len(s, nums):",
"function_name": "min_subarray_len",
"parameter_list": "(s, nums)"
},
{
"docstring": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_subarray_len(nums, target):\n n = len(nums)\n min_len = float('inf')\n current_sum = 0\n start = 0\n\n for end in range(n):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016801",
"row_id": 16801,
"seed_ids": "[7198]"
} | 0.851615 | Code_Contests_16801 | I | [
"min_subarray_len",
"find_min_length_subarray"
] | 2 | [
[
"find_min_length_subarray",
"min_subarray_len"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 40035ba263cdd5aef67f79774fa3270cdcfd9cab | cfb9aa99a0662d1af4d0fd1b5d091a1c46fc362d | |||
v1.0 | instruct | Code_Contests | Code_Contests_16809_I | Ina, a high school student, is participating in a school coding competition. To prepare, she needs to practice solving problems by computing the shortest paths in weighted graphs.
Ina is given a directed weighted graph with $ N $ nodes and $ M $ directed edges. Each edge has a certain weight. She needs to determine th... | import heapq
import sys
from collections import defaultdict
def dijkstra(N, M, S, edges):
graph = defaultdict(list)
for u, v, w in edges:
graph[u].append((w, v))
inf = sys.maxsize
distances = [inf] * (N + 1)
distances[S] = 0
priority_queue = [(0, S)]
while priority_queue:
... | from solution import shortest_paths
def test_shortest_paths_example1():
N = 6
M = 9
S = 1
edges = [
(1, 2, 7),
(1, 3, 9),
(1, 6, 14),
(2, 3, 10),
(2, 4, 15),
(3, 4, 11),
(3, 6, 2),
(6, 5, 9),
(4, 5, 6)
]
result = short... | [
{
"docstring": null,
"function_declaration": "def dijkstra(N, M, S, edges):",
"function_name": "dijkstra",
"parameter_list": "(N, M, S, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_paths(N, M, S, edges):",
"function_name": "shortest_paths",
"parameter_lis... | [
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, M, S, edges):\n # Convert to 0-based index\n S -= 1\n graph = [[] for _ in range(N)]\n for u, v, w in edges:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016809",
"row_id": 16809,
"seed_ids": "[2602]"
} | 0.828203 | Code_Contests_16809 | I | [
"dijkstra",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4e4bbc802720c9942af3a8053568d1ef1651790 | c4a575badd5b23d98c5a3378a9b11ad22ff7feab | |||
v1.0 | instruct | Code_Contests | Code_Contests_16810_I | Anna and Zoe are on a mission to explore alien artifacts. They've stumbled upon a series of ancient alien runes, and each rune is associated with a unique numerical value. Anna and Zoe's goal is to understand the pattern of these runes.
The runes are arranged in a sequence, and they want to find the smallest positive ... | def smallest_missing_positive_integer(test_cases):
results = []
for n, runes in test_cases:
num_set = set(runes)
smallest_missing = 1
while smallest_missing in num_set:
smallest_missing += 1
results.append(smallest_missing)
return resul... | from solution import alien_runes
def test_case_1():
input_str = "3\n3\n1 2 0\n5\n3 4 -1 1 0\n4\n7 8 9 11"
expected_output = "3\n2\n1"
assert alien_runes(input_str) == expected_output
def test_case_2():
input_str = "1\n6\n2 3 7 6 8 -10"
expected_output = "1"
assert alien_runes(input_str) == exp... | [
{
"docstring": null,
"function_declaration": "def smallest_missing_positive_integer(test_cases):",
"function_name": "smallest_missing_positive_integer",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "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 smallest_missing_positive_integer(T, test_cases):\n results = []\n for n, runes in test_cases:\n # Remove all non-positive numbers from th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016810",
"row_id": 16810,
"seed_ids": "[8865]"
} | 0.638708 | Code_Contests_16810 | I | [
"smallest_missing_positive_integer",
"parse_input",
"format_output",
"alien_runes"
] | 4 | [
[
"alien_runes",
"format_output"
],
[
"alien_runes",
"parse_input"
],
[
"alien_runes",
"smallest_missing_positive_integer"
]
] | 3 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 7843b9260c4f6c3a77ca48986167e3dc3d630d83 | fbb1d8b9cee2aea86d8132b6cf09e8534250956c | |||
v1.0 | instruct | Code_Contests | Code_Contests_16811_I | Given an array of size N consisting of N distinct integers, write a program to handle the following operations:
1. 0 x y: Update the xth element of the array to y.
2. 1 l r k: Find the k-th smallest element within the subarray from index l to index r (inclusive). If there is no k-th smallest element, return -1.
Input... | def update_element(arr, x, y):
"""
Updates the xth element of the array to y.
"""
arr[x-1] = y
def find_kth_smallest(arr, l, r, k):
"""
Finds the k-th smallest element in the subarray from index l to r (inclusive).
If there is no k-th smallest element, returns -1.
"""
subarray = arr... | from solution import update_element, find_kth_smallest, process_operations
def test_update_element():
arr = [10, 20, 30, 40, 50]
update_element(arr, 3, 35)
assert arr == [10, 20, 35, 40, 50]
update_element(arr, 1, 100)
assert arr == [100, 20, 35, 40, 50]
def test_find_kth_smallest():
arr = [10... | [
{
"docstring": "Updates the xth element of the array to y.",
"function_declaration": "def update_element(arr, x, y):",
"function_name": "update_element",
"parameter_list": "(arr, x, y)"
},
{
"docstring": "Finds the k-th smallest element in the subarray from index l to r (inclusive).\nIf ther... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def update_element(array, x, y):\n \"\"\"\n Updates the element at index x of the array to y.\n \"\"\"\n array[x - 1] = y\n\ndef kth_smallest_e... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016811",
"row_id": 16811,
"seed_ids": "[5802]"
} | 0.745455 | Code_Contests_16811 | I | [
"update_element",
"find_kth_smallest",
"process_operations"
] | 3 | [
[
"process_operations",
"find_kth_smallest"
],
[
"process_operations",
"update_element"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | e705b615680fdc6bc42e6b4c1c84b23eed86defd | f2a1c2f5ce430c194e6b7942122fea9d3ae4c2b9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16847_I | **Picking and Placing Crates**
Kael runs a warehouse and has a robot that helps him move around crates. The warehouse is represented by a grid of n rows and m columns. Each cell in the grid can either be empty, contain a crate, or contain an obstacle. Kael wants to use the robot to move crates to specified target posi... | from collections import deque
from itertools import permutations
def parse_input(input_lines):
n, m = map(int, input_lines[0].strip().split())
grid = [list(input_lines[i+1].strip()) for i in range(n)]
return grid, n, m
def find_positions(grid, n, m):
crates = []
targets = []
for i in range(n):... | def test_example_1():
input_lines = [
"5 5",
".....",
".C#T.",
"..C..",
"...T.",
"....."
]
assert picking_and_placing_crates(input_lines) == 6
def test_example_2():
input_lines = [
"3 3",
".C.",
"###",
".T."
]
asser... | [
{
"docstring": null,
"function_declaration": "def parse_input(input_lines):",
"function_name": "parse_input",
"parameter_list": "(input_lines)"
},
{
"docstring": null,
"function_declaration": "def find_positions(grid, n, m):",
"function_name": "find_positions",
"parameter_list": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef minimum_moves(n, m, grid):\n def bfs(start, end):\n queue = deque([(start[0], start[1], 0)])\n visite... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016847",
"row_id": 16847,
"seed_ids": "[9507]"
} | 0.695657 | Code_Contests_16847 | I | [
"parse_input",
"find_positions",
"valid_position",
"bfs",
"minimum_moves",
"picking_and_placing_crates"
] | 6 | [
[
"bfs",
"valid_position"
],
[
"minimum_moves",
"bfs"
],
[
"minimum_moves",
"find_positions"
],
[
"picking_and_placing_crates",
"minimum_moves"
],
[
"picking_and_placing_crates",
"parse_input"
]
] | 5 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 2ae5fab3ba297904ed93fe89161cc19af843d86d | 41c4d811c9ffce0e348539df8605178cdfe92cc1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16874_I | You are given an array of integers. Your task is to determine if there exists a contiguous subarray whose sum is a perfect square. If such a subarray exists, output "YES", otherwise output "NO".
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of elements in the array.
The second line contains n... | import math
def is_perfect_square(x):
if x < 0:
return False
s = int(math.sqrt(x))
return s * s == x
def contiguous_subarray_has_perfect_square_sum(arr):
n = len(arr)
for start in range(n):
curr_sum = 0
for end in range(start, n):
curr_sum += arr[end]
... | from solution import contiguous_subarray_has_perfect_square_sum
def test_example_case_1():
array = [1, 2, 3, 4, 5]
assert contiguous_subarray_has_perfect_square_sum(array) == "YES"
def test_example_case_2():
array = [-1, -2, -3]
assert contiguous_subarray_has_perfect_square_sum(array) == "NO"
def tes... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def contiguous_subarray_has_perfect_square_sum(arr):",
"function_name": "contiguous_subarray_has_pe... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(num):\n if num < 0:\n return False\n root = int(math.isqrt(num))\n return root * root == num\n\ndef ex... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016874",
"row_id": 16874,
"seed_ids": "[1628]"
} | 0.648303 | Code_Contests_16874 | I | [
"is_perfect_square",
"contiguous_subarray_has_perfect_square_sum"
] | 2 | [
[
"contiguous_subarray_has_perfect_square_sum",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 10fb918ca14d4a74b4b210627f9e9fb1514dd0c1 | 04a6104fc6f25083f57fd2d84521c50cb2a8fc4c | |||
v1.0 | instruct | Code_Contests | Code_Contests_16937_I | In a given binary tree, each node has a value associated with it. We need to find the maximum sum of values from the root to any leaf. The root is defined as the topmost node, and a leaf is any node that does not have any children.
Input
The input consists of multiple lines where each line contains three space-separa... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(nodes):
tree_dict = {val: TreeNode(val) for val, left, right in nodes}
root = tree_dict[nodes[0][0]]
for val, left, right in nodes:
i... | def test_single_node():
input_data = "5 -1 -1"
assert max_sum_from_input(input_data) == 5
def test_tree_with_left_child():
input_data = "10 7 -1\n7 -1 -1"
assert max_sum_from_input(input_data) == 17
def test_complete_binary_tree():
input_data = "1 2 3\n2 4 5\n3 -1 6\n4 -1 -1\n5 -1 -1\n6 -1 -1"
... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016937",
"row_id": 16937,
"seed_ids": "[5167]"
} | 0.659914 | Code_Contests_16937 | I | [
"build_tree",
"max_sum_root_to_leaf",
"max_sum_from_input"
] | 3 | [
[
"max_sum_from_input",
"build_tree"
],
[
"max_sum_from_input",
"max_sum_root_to_leaf"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 225e7a4cf11d499cfeed7e1b79870d5c723f3ddf | 4550ad387e8ec28e67f1a6dcf43bc8f74b64e9a3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16938_I | Mohan loves prime numbers and has recently learned about prime number intervals. To impress his friend Sohan, he wants to create an interesting puzzle using prime number intervals.
A prime number interval from L to R (inclusive) is a sequence of integers {L, L+1, ..., R}, and we only consider the prime numbers in this... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def sum_of_digits(n):
return sum(int(digit... | from solution import is_prime, sum_of_digits, find_max_digit_sum_prime, solve_intervals
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(20) == False
assert is_prime(23) == True
assert is_prime... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00016938",
"row_id": 16938,
"seed_ids": "[2678]"
} | 0.614771 | Code_Contests_16938 | I | [
"is_prime",
"sum_of_digits",
"find_max_digit_sum_prime",
"solve_intervals",
"main"
] | 5 | [
[
"find_max_digit_sum_prime",
"is_prime"
],
[
"find_max_digit_sum_prime",
"sum_of_digits"
],
[
"solve_intervals",
"find_max_digit_sum_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 34113d04f8981bdf75b513bbbecf3b30560d55e4 | ed82e5424b6f2bfe64755d16145e95c77a7c1f37 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16957_I | Catherine is designing a new navigation system for a city with n intersections and m one-way streets connecting them. The streets are represented as directed edges and there may be multiple one-way streets connecting the same pair of intersections.
Catherine has identified k critical intersections that should be monit... | import heapq
from collections import defaultdict, deque
import sys
INF = sys.maxsize
def dijkstra(graph, start, nodes):
dist = {node: INF for node in nodes}
dist[start] = 0
pq = [(0, start)]
while pq:
current_distance, current_node = heapq.heappop(pq)
if current_distance > dis... | from solution import monitor_critical_paths
def test_example1():
n = 6
m = 7
k = 2
streets = [
(1, 2, 10),
(2, 3, 20),
(1, 3, 50),
(3, 4, 10),
(4, 5, 30),
(2, 5, 30),
(5, 6, 10)
]
critical_intersections = [3, 5]
queries = [(1, 5, 55), ... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, nodes):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, nodes)"
},
{
"docstring": null,
"function_declaration": "def monitor_critical_paths(n, m, k, streets, critical_intersections, queries):",
... | [
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 collections import defaultdict, deque\n\ndef find_shortest_paths(graph, start):\n \"\"\"\n Uses Dijkstra's algorithm to find the s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00016957",
"row_id": 16957,
"seed_ids": "[5854]"
} | 0.710809 | Code_Contests_16957 | I | [
"dijkstra",
"monitor_critical_paths"
] | 2 | [
[
"monitor_critical_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e65634a6c547859211d2c7d7353e6dfa1d7705e1 | 0335f4f8dd6720518edb5aa122d7d9b4f88150a8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16960_I | Analyze the number of occurrences of a specific word in multiple text documents.
You are given multiple documents, each containing a series of lines of text. You need to analyze these documents to find out how many times a specific word appears in each document. The word match should be case-sensitive and must exactly... | def count_word_occurrences(docs, word_to_count):
"""
Counts occurrences of a specific word in each document.
Args:
docs: List of documents where each document is represented as list of lines.
word_to_count: The word to count in the documents.
Returns:
A list containing the count of... | from solution import analyze_documents
def test_analyze_documents_case_sensitive():
inputs = [
"2",
"4",
"Hello world",
"The world is beautiful",
"Hello again",
"world",
"3",
"This is a test",
"Test the code",
"test your skills... | [
{
"docstring": "Counts occurrences of a specific word in each document.\n\nArgs:\ndocs: List of documents where each document is represented as list of lines.\nword_to_count: The word to count in the documents.\n\nReturns:\nA list containing the count of occurrences for each document.",
"function_declaratio... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_word_occurrences(documents, word):\n \"\"\"\n Counts the number of occurrences of the specified word in each document.\n\n :param docume... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00016960",
"row_id": 16960,
"seed_ids": "[11650]"
} | 0.606505 | Code_Contests_16960 | I | [
"count_word_occurrences",
"analyze_documents"
] | 2 | [
[
"analyze_documents",
"count_word_occurrences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e62969f7c6e1633127a51fe8e5b899e7b08931d0 | eb790e16e0d755c5128c411cd7e7d82c3606b6c4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_16961_I | Bob is studying a new sequence of binary strings. The sequence starts with a single character '0'. Each subsequent string is generated by flipping each bit of the previous string (changing all '0's to '1's and all '1's to '0's) and then appending this flipped string to the original. Thus, the sequence evolves as follow... | def generate_sequence(n):
"""
Generate the n-th sequence in Bob's study.
"""
if n == 1:
return "0"
prev_sequence = generate_sequence(n - 1)
flipped_sequence = ''.join('1' if bit == '0' else '0' for bit in prev_sequence)
return prev_sequence + flipped_sequence
def find_kth_character(... | from solution import generate_sequence, find_kth_character, solve_sequence_queries
def test_generate_sequence():
assert generate_sequence(1) == "0"
assert generate_sequence(2) == "01"
assert generate_sequence(3) == "0110"
assert generate_sequence(4) == "01101001"
def test_find_kth_character():
ass... | [
{
"docstring": "Generate the n-th sequence in Bob's study.",
"function_declaration": "def generate_sequence(n):",
"function_name": "generate_sequence",
"parameter_list": "(n)"
},
{
"docstring": "Find the k-th character in the n-th sequence of binary strings.",
"function_declaration": "de... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def kth_character_in_nth_string(n, k):\n def generate_nth_string(n):\n if n == 1:\n return \"0\"\n prev_string = generate_nth_s... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00016961",
"row_id": 16961,
"seed_ids": "[1305]"
} | 0.711949 | Code_Contests_16961 | I | [
"generate_sequence",
"find_kth_character",
"solve_sequence_queries"
] | 3 | [
[
"find_kth_character",
"generate_sequence"
],
[
"solve_sequence_queries",
"find_kth_character"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ee8fb37264e3bb07b7f3592d3b48ca68e029a1f5 | d126e42acc77ba423b2f4756baf17a0c023ce012 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17134_I | You are given a grid with n rows and m columns, where each cell of the grid is either empty, represented by '.', or contains an obstacle, represented by '#'. You can move from one cell to another in the grid if they share an edge and the destination cell is empty. However, you can only move right or down. Your task is ... | def count_paths(grid):
n = len(grid)
m = len(grid[0])
# If the start or end point is an obstacle, return 0 as no path is possible
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
# Initialize DP table
dp = [[0] * m for _ in range(n)]
# Starting point
dp[0][0... | from solution import number_of_distinct_paths
def test_paths_simple():
grid = [
['.', '.', '.'],
['.', '#', '.'],
['.', '.', '.']
]
assert number_of_distinct_paths(3, 3, grid) == 2
def test_paths_no_path():
grid = [
['.', '#', '.'],
['#', '.', '#'],
['.'... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_distinct_paths(n, m, grid):",
"function_name": "number_of_distinct_paths",
"parameter_l... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_paths(grid):\n n = len(grid)\n m = len(grid[0])\n \n # If the start or end point is an obstacle, return 0 as no path is possible\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017134",
"row_id": 17134,
"seed_ids": "[10320]"
} | 0.80297 | Code_Contests_17134 | I | [
"count_paths",
"number_of_distinct_paths"
] | 2 | [
[
"number_of_distinct_paths",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 079946e54adb1979b32eb7a715489263127ea1f6 | 24eef8f23575078d07cf41d5d8aee9a43c62daa7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17172_I | Write a program that determines the minimum number of coins needed to make a certain amount of money using any combination of given coin denominations.
You are given n different coin denominations and a value x to make. Your task is to determine the minimum number of coins required to sum up to x.
If it is not possib... | def min_coins(n, x, denominations):
"""
Returns the minimum number of coins needed to make the value x using given denominations.
If it is not possible to form x, returns -1.
"""
# Initialize the DP table with a high value (infinity)
dp = [float('inf')] * (x + 1)
# Base case: 0 coins ne... | from solution import min_coins
from solution import min_coins_input_parser
def test_min_coins_example_case():
assert min_coins(3, 11, [1, 2, 5]) == 3
def test_min_coins_impossible_case():
assert min_coins(2, 7, [2, 4]) == -1
def test_min_coins_large_value():
assert min_coins(3, 1000, [1, 50, 100]) == 10
... | [
{
"docstring": "Returns the minimum number of coins needed to make the value x using given denominations.\nIf it is not possible to form x, returns -1.",
"function_declaration": "def min_coins(n, x, denominations):",
"function_name": "min_coins",
"parameter_list": "(n, x, denominations)"
},
{
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_coins(n, x, denominations):\n \"\"\"\n Returns the minimum number of coins needed to make value x using given coin denominations.\n If it ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00017172",
"row_id": 17172,
"seed_ids": "[11126]"
} | 0.769381 | Code_Contests_17172 | I | [
"min_coins",
"min_coins_input_parser"
] | 2 | [
[
"min_coins_input_parser",
"min_coins"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b377d1628c7fe871437ba5b479186ea45fc4da4f | 60ed225a8836716c545b4e0f9e621e3317493cbf | |||
v1.0 | instruct | Code_Contests | Code_Contests_17252_I | In a certain kingdom, there are several towns connected by bidirectional roads. Each road has a specific time taken to travel between towns. The Kingdom's ruler wants to enhance the infrastructure by paving some of the roads while minimizing the cost. However, some roads must remain unpaved due to historical reasons. T... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import minimum_paving_cost
def test_minimum_paving_cost():
cases = [
(4, 5, [(1, 2, 1), (2, 3, 2), (3, 4, 3), (4, 1, 4), (1, 3, 10)]),
(3, 3, [(1, 2, 1), (2, 3, 3), (1, 3, 2)])
]
assert minimum_paving_cost(2, cases) == [6, 3]
def test_single_case():
cases = [
(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,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i]) # path compression\n return p... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00017252",
"row_id": 17252,
"seed_ids": "[2502]"
} | 0.746036 | Code_Contests_17252 | I | [
"find",
"union",
"minimum_paving_cost"
] | 3 | [
[
"minimum_paving_cost",
"find"
],
[
"minimum_paving_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ecce9fb4870366c2be6fa585494f3edde2f0369f | 9392c4d036ce1bf68a3f1d47cc9bc7765c0566dd | |||
v1.0 | instruct | Code_Contests | Code_Contests_17271_I | You are given a grid with n rows and m columns, where each cell contains a non-negative integer. You are allowed to perform the following operation any number of times: choose a rectangular subgrid and increase every element in that subgrid by 1.
Your task is to make all cells in the grid equal using the minimum numbe... | def min_operations_to_equalize(grid):
n = len(grid)
m = len(grid[0])
max_val = max(max(row) for row in grid)
min_val = min(min(row) for row in grid)
operations = max_val - min_val
return operations
def get_grid_and_solve(n, m, values):
grid = []
for i in range(n):
grid.appe... | from solution import get_grid_and_solve
def test_example1():
assert get_grid_and_solve(2, 3, [1, 2, 3, 4, 5, 6]) == 5
def test_example2():
assert get_grid_and_solve(1, 4, [2, 2, 2, 2]) == 0
def test_example3():
assert get_grid_and_solve(3, 3, [1, 1, 1, 2, 2, 2, 4, 4, 4]) == 3
def test_single_cell():
... | [
{
"docstring": null,
"function_declaration": "def min_operations_to_equalize(grid):",
"function_name": "min_operations_to_equalize",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def get_grid_and_solve(n, m, values):",
"function_name": "get_grid_and_solv... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_operations_to_equal_cells(n, m, grid):\n \"\"\"\n Returns the minimum number of operations needed to make all cells in the grid equal.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017271",
"row_id": 17271,
"seed_ids": "[9280]"
} | 0.786146 | Code_Contests_17271 | I | [
"min_operations_to_equalize",
"get_grid_and_solve"
] | 2 | [
[
"get_grid_and_solve",
"min_operations_to_equalize"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63e5eec1fd679236cc286dc2c43ea3a3b0d027f7 | 6ef119495037ab9c45acec4576ad9707f32b7728 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17300_I | Imagine a vast battlefield represented as a grid of size n x m, where each cell is either an empty cell ('.') or a cell with an obstacle ('#'). You are a general in charge of leading a squad of soldiers, and your task is to move the entire squad from a given starting cell (sx, sy) to a target cell (tx, ty). The squad m... | from collections import deque
def bfs_shortest_path(grid, start, target, n, m):
sx, sy = start
tx, ty = target
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(sx, sy, 0)])
visited = set([(sx, sy)])
while queue:
x, y, d = queue.popleft()
if (x, ... | def test_min_steps_to_reach_target_1():
n = 6
m = 7
k = 1
grid = [
list("......."),
list("...#..."),
list("......."),
list(".#....."),
list("......."),
list("......."),
]
sx, sy, tx, ty = 1, 1, 6, 7
bombs = [(3, 3, 2)]
result = min_steps_to... | [
{
"docstring": null,
"function_declaration": "def bfs_shortest_path(grid, start, target, n, m):",
"function_name": "bfs_shortest_path",
"parameter_list": "(grid, start, target, n, m)"
},
{
"docstring": null,
"function_declaration": "def apply_bombs(grid, bombs, n, m):",
"function_nam... | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_target(n, m, k, grid, sx, sy, tx, ty, bombs):\n def in_bounds(x, y):\n return 0 <= x < n and 0 ... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00017300",
"row_id": 17300,
"seed_ids": "[6174]"
} | 0.676134 | Code_Contests_17300 | I | [
"bfs_shortest_path",
"apply_bombs",
"min_steps_to_reach_target",
"main"
] | 4 | [
[
"min_steps_to_reach_target",
"apply_bombs"
],
[
"min_steps_to_reach_target",
"bfs_shortest_path"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 94928f0ffeacc3d3fad5eb16ae9deb09dc880665 | 60b2a4d2d30d902a4173563b7c2c1b1d178d63ff | |||
v1.0 | instruct | Code_Contests | Code_Contests_17370_I | Longest Subsequence
Given a sequence of integers, you are to find the length of the longest subsequence that is first non-decreasing and then non-increasing.
The non-decreasing part of the subsequence is a contiguous subarray where each element is greater than or equal to its previous element. Similarly, the non-inc... | def longest_mountain(arr):
n = len(arr)
if n < 3:
return 0
longest = 0
for i in range(1, n - 1):
if arr[i-1] < arr[i] > arr[i+1]: # Peak is found
# Find the length of the increasing part
left = i - 1
while left > 0 and arr[left - 1] < arr[left]:
... | from solution import longest_mountain
def test_example_1():
assert longest_mountain([2, 1, 4, 7, 3, 2, 5, 1]) == 5
def test_example_2():
assert longest_mountain([2, 2, 2, 2]) == 0
def test_example_3():
assert longest_mountain([1, 2, 3, 4, 5, 6]) == 0
def test_all_same_elements():
assert longest_moun... | [
{
"docstring": null,
"function_declaration": "def longest_mountain(arr):",
"function_name": "longest_mountain",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_solve():",
"function_name": "read_input_and_solve",
"parameter_list": "()"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_mountain(arr):\n n = len(arr)\n if n < 3:\n return 0\n\n longest = 0\n\n for i in range(1, n - 1):\n if arr[i-1] < ar... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017370",
"row_id": 17370,
"seed_ids": "[4363]"
} | 0.778633 | Code_Contests_17370 | I | [
"longest_mountain",
"read_input_and_solve"
] | 2 | [
[
"read_input_and_solve",
"longest_mountain"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c2e81502916e67b8cf7f2c91d2630dc5ffe648f1 | 3c836d2887bb961c4d30cd936025c8da59d1f7e0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17405_I | You are given a binary tree with n nodes, where each node has a value and a level. The root node has level 1, its children have level 2, and so on. You need to answer queries about the sum of values at different levels and changing the values of nodes.
The binary tree is represented as a list of values. The order impl... | def sum_level_query(tree, level):
"""
Calculates the sum of the values of all nodes at the specified level.
"""
level_sum = 0
current_level = 1
start_index = 0
while start_index < len(tree):
end_index = start_index + 2**(current_level - 1)
if current_level == level:
... | import pytest
from solution import sum_level_query, change_value, process_queries
def test_sum_level_query():
assert sum_level_query([3, 5, -1, 6, -1, -1, 9], 1) == 3
assert sum_level_query([3, 5, -1, 6, -1, -1, 9], 2) == 5
assert sum_level_query([3, 5, -1, 6, -1, -1, 9], 3) == 15
def test_change_value():... | [
{
"docstring": "Calculates the sum of the values of all nodes at the specified level.",
"function_declaration": "def sum_level_query(tree, level):",
"function_name": "sum_level_query",
"parameter_list": "(tree, level)"
},
{
"docstring": "Changes the value of the specified node in the tree.",... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def parse_tree_and_queries(input_list):\n \"\"\"\n Parse the input list and extract tree values and queries.\n \"\"\"\n t = int(input_list[0])\... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00017405",
"row_id": 17405,
"seed_ids": "[1617]"
} | 0.610188 | Code_Contests_17405 | I | [
"sum_level_query",
"change_value",
"process_queries"
] | 3 | [
[
"process_queries",
"change_value"
],
[
"process_queries",
"sum_level_query"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 91a3b1ed0111dbef5c944653546d43e803858285 | 6ccb6fed43f4a51a5af93083e78b8f4a2cc380cc | |||
v1.0 | instruct | Code_Contests | Code_Contests_17410_I | You are given a string that contains a series of arithmetic operations involving addition, subtraction, multiplication, and division. The string can also contain parentheses to specify the order of operations. Your task is to evaluate the string and return the result as a floating-point number.
The input string may co... | def evaluate_expression(expression):
"""
Evaluates a given arithmetic expression string and returns the result as a floating-point number.
Handles +, -, *, / operators and parentheses.
"""
try:
result = eval(expression)
return float(result)
except Exception as e:
raise Va... | import pytest
from solution import evaluate_expression, evaluate_expressions
def test_evaluate_expression_simple_addition():
assert evaluate_expression("3 + 5") == 8.0
def test_evaluate_expression_subtraction_and_multiplication():
assert evaluate_expression("10 - 2 * 5") == 0.0
def test_evaluate_expression_d... | [
{
"docstring": "Evaluates a given arithmetic expression string and returns the result as a floating-point number.\nHandles +, -, *, / operators and parentheses.",
"function_declaration": "def evaluate_expression(expression):",
"function_name": "evaluate_expression",
"parameter_list": "(expression)"
... | [
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 evaluate_expression(expression):\n \"\"\"\n Evaluates a given arithmetic expression string and returns the result as a floating-point number.\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017410",
"row_id": 17410,
"seed_ids": "[1567]"
} | 0.572212 | Code_Contests_17410 | I | [
"evaluate_expression",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"evaluate_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8314d2c0d8af8ec7d7656b24bba20a921e3e98e0 | 7bb8ba47d062c9927a0a526604a48ee4ad197a97 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17426_I | Julia has a collection of n books, each with a number of pages. She wants to allocate these books to k students such that each student gets at least one book and the maximum number of pages assigned to a student is minimized. Help Julia determine the optimal way to allocate the books to the students to achieve this goa... | def is_possible(books, n, k, max_pages):
student_count = 1
current_pages = 0
for i in range(n):
if books[i] > max_pages:
return False
if current_pages + books[i] > max_pages:
student_count += 1
current_pages = books[i]
if student_count > k... | from solution import find_min_max_pages
def test_example_case_1():
n, k = 4, 2
books = [12, 34, 67, 90]
assert find_min_max_pages(n, k, books) == 113
def test_example_case_2():
n, k = 5, 3
books = [10, 20, 30, 40, 50]
assert find_min_max_pages(n, k, books) == 60
def test_single_book():
n,... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, k, max_pages):",
"function_name": "is_possible",
"parameter_list": "(books, n, k, max_pages)"
},
{
"docstring": null,
"function_declaration": "def find_min_max_pages(n, k, books):",
"function_name": "find_min_max... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_distribution(books, n, k, max_pages_per_student):\n required_students = 1\n current_pages_sum = 0\n \n for pages in books:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017426",
"row_id": 17426,
"seed_ids": "[10423]"
} | 0.689575 | Code_Contests_17426 | I | [
"is_possible",
"find_min_max_pages"
] | 2 | [
[
"find_min_max_pages",
"is_possible"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 250943ef56269aee481f8aef12d1d3a434a2a792 | 217930529982d430f044eac5610253fdc95cc129 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17473_I | Daniel loves challenges involving sequences, especially when it involves prime numbers. He recently stumbled upon a problem and needs your help to solve it.
Given a sequence of n integers, he wants to know the length of the longest contiguous sub-sequence in which the product of its elements is not a prime number.
A ... | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def longest_non_prime_p... | from solution import longest_non_prime_product_subseq_length
def test_example_cases():
assert longest_non_prime_product_subseq_length(7, [1, 2, 3, 4, 5, 6, 7]) == 7
assert longest_non_prime_product_subseq_length(6, [2, 3, 5, 7, 11, 13]) == 1
def test_single_element():
assert longest_non_prime_product_subs... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the length of the longest contiguous sub-sequence whose product is not a prime number.",
"function_declaratio... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return Tr... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017473",
"row_id": 17473,
"seed_ids": "[6380]"
} | 0.641127 | Code_Contests_17473 | I | [
"is_prime",
"longest_non_prime_product_subseq_length"
] | 2 | [
[
"longest_non_prime_product_subseq_length",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 98ca321377bd6b0ba132b235459d5b03ecd45e5c | d39167402f78639375961404f20d3576dddc028a | |||
v1.0 | instruct | Code_Contests | Code_Contests_17495_I | You are given an array of n integers. You need to process q queries, each of which asks you to compute the sum of the elements in a specified range of the array. Formally, each query is represented by two integers l and r, you are to find the sum of elements from al to ar (both inclusive).
Input
The first line contai... | def preprocess_prefix_sums(arr):
prefix_sums = [0] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1]
return prefix_sums
def range_sum(arr, queries):
prefix_sums = preprocess_prefix_sums(arr)
result = []
for l, r in queries:
sum_ra... | from solution import range_sum
def test_small_range():
arr = [1, 2, 3, 4, 5]
queries = [(1, 3), (2, 4), (1, 5)]
expected_output = [6, 9, 15]
assert range_sum(arr, queries) == expected_output
def test_full_range():
arr = [1, -2, 3, -4, 5]
queries = [(1, 5)]
expected_output = [3]
assert ... | [
{
"docstring": null,
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def range_sum(arr, queries):",
"function_name": "range_sum",
"parameter_list": "(... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def range_sums(n, arr, queries):\n \"\"\"\n Computes the sum of the elements in a specified range for each query.\n\n Parameters:\n n (int): Nu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017495",
"row_id": 17495,
"seed_ids": "[8260]"
} | 0.696397 | Code_Contests_17495 | I | [
"preprocess_prefix_sums",
"range_sum"
] | 2 | [
[
"range_sum",
"preprocess_prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c3ea0234f7358eaa3ab8794ce0ddb610d0b8adc | 2faddcd35e86db9f198c046c6829823011496653 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17523_I | Problem
You are given a list of words, and your task is to identify if each word is a palindrome.
A palindrome is a word that reads the same forwards as backwards (e.g., "madam", "racecar").
Constraints
The input satisfies the following conditions:
* $ 1 \le N \lt 10^3 $
* $ 1 \le | s_i | \le 100 $
* The string c... | def is_palindrome(word):
"""
Checks if a given word is a palindrome.
Parameters
----------
word : str
The word to check.
Returns
-------
str
"YES" if the word is a palindrome, "NO" otherwise.
"""
if word == word[::-1]:
return "YES"
else:
... | from solution import check_palindromes
def test_check_palindromes():
assert check_palindromes(["madam", "test", "level", "world"]) == ["YES", "NO", "YES", "NO"]
assert check_palindromes(["abba", "racecar", "apple"]) == ["YES", "YES", "NO"]
assert check_palindromes(["", "a", "radar", "refer", "step on no pe... | [
{
"docstring": "Checks if a given word is a palindrome.\n\nParameters\n----------\nword : str\n The word to check.\n\nReturns\n-------\nstr\n \"YES\" if the word is a palindrome, \"NO\" otherwise.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(word):\n \"\"\"\n Returns 'YES' if the word is a palindrome, otherwise 'NO'.\n \"\"\"\n return \"YES\" if word == word[::-1] ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017523",
"row_id": 17523,
"seed_ids": "[7703]"
} | 0.832264 | Code_Contests_17523 | I | [
"is_palindrome",
"check_palindromes"
] | 2 | [
[
"check_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c8e620c7eeb7063dfd76fe718f6e12e43bb35d1 | 021d3a135013d82496d2111ddde5c3b02919f3c1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17573_I | You are given a list of buildings in a city and the distances between some of these buildings. The city council wants to build a sky bridge network that connects all buildings directly or indirectly. However, the bridges need to be designed in such a way that the longest bridge is as short as possible to ensure safety ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > ... | from solution import min_max_bridge
def test_example_1():
n = 4
m = 5
edges = [
(1, 2, 4),
(1, 3, 2),
(2, 4, 6),
(3, 4, 8),
(3, 2, 3)
]
assert min_max_bridge(n, m, edges) == 6
def test_example_2():
n = 4
m = 2
edges = [
(1, 2, 7),
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017573",
"row_id": 17573,
"seed_ids": "[6822]"
} | 0.671946 | Code_Contests_17573 | I | [
"find",
"union",
"min_max_bridge",
"main"
] | 4 | [
[
"min_max_bridge",
"find"
],
[
"min_max_bridge",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fc9ba590a13abb067b4ab202b621b0d920352bd7 | f39555a03722c9aa1f02291c1d047aca964a3bb6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17605_I | Polycarpus is working on optimizing the performance of his network of servers. He has constructed a data center consisting of n servers, identified by unique integers from 1 to n. Each server has multiple connections to other servers, allowing data to flow between them. However, Polycarpus noticed that the connection p... | def find(parent, u):
"""Find the root of the component containing u with path compression."""
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
"""Union by rank of the components containing u and v."""
root_u = find(parent, u)
root_v ... | from solution import min_operations_to_connect_servers, parse_input
def test_no_operations_needed():
t, test_cases = parse_input("1\n4 3\n1 2\n2 3\n3 4")
results = min_operations_to_connect_servers(t, test_cases)
assert results == [(0, [])]
def test_add_operations_needed():
t, test_cases = parse_input... | [
{
"docstring": "Find the root of the component containing u with path compression.",
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": "Union by rank of the components containing u and v.",
"function_declaration": "... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_operations(t, test_cases):\n \"\"\"\n Determines the minimum number of operations to achieve optimal connectivity for given test cases.\n... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00017605",
"row_id": 17605,
"seed_ids": "[6995]"
} | 0.635364 | Code_Contests_17605 | I | [
"find",
"union",
"min_operations_to_connect_servers",
"parse_input"
] | 4 | [
[
"min_operations_to_connect_servers",
"find"
],
[
"min_operations_to_connect_servers",
"union"
],
[
"union",
"find"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | c6e3ac723f2a9bb7c53ae919bdaa8391dab9cc13 | 185ee3422a75a03a2669d9f95501b1a162b6948c | |||
v1.0 | instruct | Code_Contests | Code_Contests_17610_I | Alice is organizing a fun programming contest for her friends. She wants one of the tasks to involve generating a valid password that follows specific rules. The rules are:
* The password must contain only lowercase letters from 'a' to 'z'.
* The length of the password must be exactly n.
* The password must have at le... | def generate_password(n, v):
"""
Generates a valid password that satisfies the conditions:
- length of the password must be exactly n
- must contain only lowercase letters from 'a' to 'z'
- must have at least one vowel ('a', 'e', 'i', 'o', 'u')
- number of vowels in the password must not exceed ... | def test_generate_password():
assert generate_password(5, 2) == 'aeiou'[:2] + 'bcdfghjklmnpqrstvwxyz'[:3]
assert generate_password(4, 1) == 'aeiou'[:1] + 'bcdfghjklmnpqrstvwxyz'[:3]
assert generate_password(6, 3) == 'aeiou'[:3] + 'bcdfghjklmnpqrstvwxyz'[:3]
def test_generate_passwords():
test_cases = ... | [
{
"docstring": "Generates a valid password that satisfies the conditions:\n- length of the password must be exactly n\n- must contain only lowercase letters from 'a' to 'z'\n- must have at least one vowel ('a', 'e', 'i', 'o', 'u')\n- number of vowels in the password must not exceed v",
"function_declaration... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_password(n, v):\n # Generate a password with exactly n characters and at least one vowel, not exceeding v vowels\n vowe... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017610",
"row_id": 17610,
"seed_ids": "[5861]"
} | 0.680702 | Code_Contests_17610 | I | [
"generate_password",
"generate_passwords",
"solve"
] | 3 | [
[
"generate_passwords",
"generate_password"
],
[
"solve",
"generate_passwords"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 81c59e088c1f3b9bbbb1693bbbc79930b41746a3 | 3cb0ebfa3aa7ac34b00f8f54931b5778cbe53856 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17615_I | Violet is creating a new network for her startup company. This consists of several servers connected via network cables. Each server is represented by a node, and each cable by an edge in an undirected graph. Unfortunately, some of the network cables are already broken.
Violet needs a way to ensure that despite broken... | def find_root(roots, i):
if roots[i] != i:
roots[i] = find_root(roots, roots[i])
return roots[i]
def union(roots, rank, x, y):
rootX = find_root(roots, x)
rootY = find_root(roots, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
roots[rootY] = rootX
elif ... | from solution import minimal_new_cables_to_connect
def test_example_1():
n, m = 6, 3
edges = [(1, 2), (4, 5), (2, 3)]
assert minimal_new_cables_to_connect(n, m, edges) == 2
def test_example_2():
n, m = 5, 0
edges = []
assert minimal_new_cables_to_connect(n, m, edges) == 4
def test_example_3()... | [
{
"docstring": null,
"function_declaration": "def find_root(roots, i):",
"function_name": "find_root",
"parameter_list": "(roots, i)"
},
{
"docstring": null,
"function_declaration": "def union(roots, rank, x, y):",
"function_name": "union",
"parameter_list": "(roots, rank, x, y)"... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017615",
"row_id": 17615,
"seed_ids": "[11470]"
} | 0.694343 | Code_Contests_17615 | I | [
"find_root",
"union",
"minimal_new_cables_to_connect"
] | 3 | [
[
"minimal_new_cables_to_connect",
"find_root"
],
[
"minimal_new_cables_to_connect",
"union"
],
[
"union",
"find_root"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | fd8649688ae914b636c9e38309ad09bfa6d6ecfb | 0f199592f8538d293442d56398613d5daff35139 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17624_I | You are given an undirected graph with `n` nodes and `m` edges. Each node has a unique integer identifier between `1` and `n`.
You are required to determine whether it is possible to assign a binary value (0 or 1) to each node such that the difference between the number of edges connecting nodes with the same value [0... | from collections import deque
def is_bipartite(n, edges):
graph = [[] for _ in range(n + 1)]
# Build the adjacency list
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
# Array to store the color of each node, 0 or 1
color = [-1] * (n + 1)
def bfs(start):
... | def test_bipartite_graph():
assert possible_binary_assignment(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]) == "YES"
def test_non_bipartite_graph():
assert possible_binary_assignment(3, 3, [(1, 2), (2, 3), (3, 1)]) == "NO"
def test_single_node_no_edges():
assert possible_binary_assignment(1, 0, []) == "YES"
de... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(n, edges):",
"function_name": "is_bipartite",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def possible_binary_assignment(n, m, edges):",
"function_name": "possible_binary_assignment",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef is_bipartite(n, edges):\n graph = [[] for _ in range(n + 1)]\n \n # Build the adjacency list\n for u, v in... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00017624",
"row_id": 17624,
"seed_ids": "[6688]"
} | 0.685704 | Code_Contests_17624 | I | [
"is_bipartite",
"possible_binary_assignment"
] | 2 | [
[
"possible_binary_assignment",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 029be6f03287a36627977c28f578d468ec4e4244 | e6c1334f4400de9d3eb111dfd176f8988f267e94 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17646_I | A company is developing a new feature where they need to handle and manipulate IP addresses. Write a function that takes a list of IP addresses and a range of valid IP addresses and returns a sorted list of IP addresses from the input that fall within the specified range. The range, as well as the addresses, are provid... | def ip_to_int(ip):
"""
Convert an IP address to an integer.
"""
parts = ip.split(".")
return int(parts[0]) * 256**3 + int(parts[1]) * 256**2 + int(parts[2]) * 256 + int(parts[3])
def filter_and_sort_ips(start_range, end_range, ip_addresses):
"""
Filters and sorts IP addresses that fall with... | from solution import filter_and_sort_ips
def test_example_case():
start_range = "192.168.1.0"
end_range = "192.168.1.255"
ip_addresses = [
"192.168.1.1",
"192.168.1.200",
"10.0.0.1",
"192.168.1.100",
"192.168.1.10"
]
output = [
"192.168.1.1",
... | [
{
"docstring": "Convert an IP address to an integer.",
"function_declaration": "def ip_to_int(ip):",
"function_name": "ip_to_int",
"parameter_list": "(ip)"
},
{
"docstring": "Filters and sorts IP addresses that fall within the specified range.",
"function_declaration": "def filter_and_so... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def ip_to_int(ip):\n \"\"\"\n Converts a given IP address to an integer.\n \"\"\"\n parts = ip.split('.')\n return (int(parts[0]) << 24) + (... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017646",
"row_id": 17646,
"seed_ids": "[71]"
} | 0.533504 | Code_Contests_17646 | I | [
"ip_to_int",
"filter_and_sort_ips"
] | 2 | [
[
"filter_and_sort_ips",
"ip_to_int"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0e1ee5f29bb3455cc2cbc55b0eecd99d8619c4c9 | 547c8050aef4d8916d47f06012d047f25b468fe0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17659_I | You are given an array of integers representing heights of different buildings in a cityscape. The cityscape can be viewed as a histogram where the width of each bar is 1. You need to find the maximum rectangular area that can be formed in the histogram.
Input
The first line contains an integer n (1 ≤ n ≤ 100000) — th... | def max_histogram_area(heights):
"""
This function returns the maximum rectangular area in a histogram represented
by heights (an array of integers).
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
... | from solution import find_max_rectangle_area
def test_example_1():
assert find_max_rectangle_area(6, [2, 1, 5, 6, 2, 3]) == 10
def test_example_2():
assert find_max_rectangle_area(4, [6, 2, 5, 4]) == 8
def test_example_3():
assert find_max_rectangle_area(5, [5, 4, 3, 2, 1]) == 9
def test_single_building... | [
{
"docstring": "This function returns the maximum rectangular area in a histogram represented\nby heights (an array of integers).",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"fu... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(heights):\n \"\"\"\n Find the maximum rectangular area that can be formed in the histogram.\n \n Arguments:\n heights... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017659",
"row_id": 17659,
"seed_ids": "[1079]"
} | 0.700959 | Code_Contests_17659 | I | [
"max_histogram_area",
"find_max_rectangle_area"
] | 2 | [
[
"find_max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d2330d67847171288b29a3cb2c5cc54f39e3a3e9 | 74656c4293f9337854e1dea532470ca07b7b171e | |||
v1.0 | instruct | Code_Contests | Code_Contests_17695_I | Michelle is an avid gardener who owns a garden consisting of N flower beds in a straight line. Each flower bed can hold a certain number of flowers, but the number of flowers on each bed varies. Michelle wants to plant some new types of flowers but can only plant them in contiguous sets of flower beds.
To keep track o... | def preprocess_flowers(flower_beds):
""" Preprocess the flower beds to create prefix sums. """
prefix_sums = [0] * (len(flower_beds) + 1)
for i in range(1, len(flower_beds) + 1):
prefix_sums[i] = prefix_sums[i - 1] + flower_beds[i - 1]
return prefix_sums
def get_flowers_in_segment(prefix_sums, ... | def test_preprocess_flowers():
flower_beds = [1, 2, 3, 4, 5]
expected_prefix_sums = [0, 1, 3, 6, 10, 15]
assert preprocess_flowers(flower_beds) == expected_prefix_sums
def test_get_flowers_in_segment():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert get_flowers_in_segment(prefix_sums, 1, 3) == 6
ass... | [
{
"docstring": "Preprocess the flower beds to create prefix sums. ",
"function_declaration": "def preprocess_flowers(flower_beds):",
"function_name": "preprocess_flowers",
"parameter_list": "(flower_beds)"
},
{
"docstring": "Calculate number of flowers in the segment from L to R using prefix... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def precompute_prefix_sums(flower_beds):\n \"\"\"\n Precomputes the prefix sums for the given array of flower beds.\n \n Returns an array where... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017695",
"row_id": 17695,
"seed_ids": "[2786]"
} | 0.726711 | Code_Contests_17695 | I | [
"preprocess_flowers",
"get_flowers_in_segment",
"solve"
] | 3 | [
[
"solve",
"get_flowers_in_segment"
],
[
"solve",
"preprocess_flowers"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 38676caad82338bffdbd60debc393574c2f20cf7 | 6dc05b204c202eea528d562609929c1a17b75757 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17696_I | Problem Description
The citizens of a small town have a unique way of organizing their local library. Each book has a unique numeric code and they want to organize the bookshelfs such that books with capicua codes (which read the same forwards and backwards) are placed in a special section.
Can you help the librarian... | def is_capicua(code):
"""
Returns True if the code is a capicua (reads the same forwards and backwards), else False.
"""
return str(code) == str(code)[::-1]
def find_capicuas(codes):
"""
Given a list of integer codes, returns a list of capicuas (codes that read the same forwards and backwards).... | from solution import is_capicua, find_capicuas
def test_is_capicua():
assert is_capicua(12321) == True
assert is_capicua(23432) == True
assert is_capicua(12345) == False
assert is_capicua(1) == True
assert is_capicua(22) == True
assert is_capicua(123) == False
def test_find_capicuas():
ass... | [
{
"docstring": "Returns True if the code is a capicua (reads the same forwards and backwards), else False.",
"function_declaration": "def is_capicua(code):",
"function_name": "is_capicua",
"parameter_list": "(code)"
},
{
"docstring": "Given a list of integer codes, returns a list of capicuas... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_capicua(code):\n \"\"\"\n Check if a given numeric code is a capicua (reads the same forwards and backwards)\n \"\"\"\n code_str = str(c... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017696",
"row_id": 17696,
"seed_ids": "[8297]"
} | 0.558698 | Code_Contests_17696 | I | [
"is_capicua",
"find_capicuas"
] | 2 | [
[
"find_capicuas",
"is_capicua"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 39bb9a1d1ae4a0dedb5941efc63158c10eba8ae3 | 68fe065f45d8dc35d698682a711c38af1ac6d344 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17698_I | Charlotte is working on a project involving a unique type of matrix called a "Mirror Matrix". A Mirror Matrix has an interesting property that it contains mirrored submatrices. Given an integer n, your task is to create an n x n matrix in such a way that the diagonals from the top-left to the bottom-right and from the ... | def mirror_matrix(n):
"""
Creates an n x n Mirror Matrix with specified properties.
Parameters:
n (int): Size of the matrix (1 ≤ n ≤ 100)
Returns:
list: 2D list representing the n x n Mirror Matrix
"""
matrix = [[0]*n for _ in range(n)]
num = 1
for layer in range((n + 1) /... | from solution import mirror_matrix, mirror_matrix_str
def test_mirror_matrix_1():
assert mirror_matrix(1) == [
[1]
]
def test_mirror_matrix_2():
assert mirror_matrix(2) == [
[1, 1],
[1, 1]
]
def test_mirror_matrix_3():
result = mirror_matrix(3)
expected = [
[1,... | [
{
"docstring": "Creates an n x n Mirror Matrix with specified properties.\n\nParameters:\nn (int): Size of the matrix (1 ≤ n ≤ 100)\n\nReturns:\nlist: 2D list representing the n x n Mirror Matrix",
"function_declaration": "def mirror_matrix(n):",
"function_name": "mirror_matrix",
"parameter_list": "... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_mirror_matrix(n):\n \"\"\"\n Generates an n x n Mirror Matrix with given properties.\n \n Args:\n n: int: the size of the matri... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017698",
"row_id": 17698,
"seed_ids": "[2311]"
} | 0.500134 | Code_Contests_17698 | I | [
"mirror_matrix",
"mirror_matrix_str"
] | 2 | [
[
"mirror_matrix_str",
"mirror_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04dfb661e01d381adf1b2e691c73c56e055b41a3 | 915c38b330b939e6726d47c7cb6385599d2c858c | |||
v1.0 | instruct | Code_Contests | Code_Contests_17703_I | In a kingdom far away, there's an annual tournament of wisdom and logic. The tournament hosts numerous challenges, but one in particular stands out. It is known as the "Pathfinder's Maze".
The maze consists of a grid with `N` rows and `M` columns. Each cell in the grid is either passable (represented by '.') or impas... | from collections import deque
def bfs(grid, N, M, is_tweak_allowed):
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
queue = deque([(0, 0, 0 if is_tweak_allowed else -1, 0)]) # (current_row, current_col, tweak_used, distance)
visited = set([(0, 0, 0 if is_tweak_allowed else -1)])
while queue:
r, c,... | def test_sample_input():
N = 5
M = 5
grid = [
".....",
"..#..",
"####.",
"..#..",
"....."
]
assert shortest_path_with_tweak(N, M, grid) == 8
def test_no_path_even_with_tweak():
N = 3
M = 3
grid = [
".#.",
"###",
".#."
]... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, N, M, is_tweak_allowed):",
"function_name": "bfs",
"parameter_list": "(grid, N, M, is_tweak_allowed)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_with_tweak(N, M, grid):",
"function_name": "shortest_pa... | [
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 shortest_path_with_twist(N, M, grid):\n directions = [(1,0), (-1,0), (0,1), (0,-1)]\n \n def bfs(start):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017703",
"row_id": 17703,
"seed_ids": "[12877]"
} | 0.701756 | Code_Contests_17703 | I | [
"bfs",
"shortest_path_with_tweak"
] | 2 | [
[
"shortest_path_with_tweak",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | dec1bba92aab9715dea40fd3f6d42bf8ab7b886f | 5fc6323b519081417a9a6fb093448895584dc7e6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17820_I | You are given a list of sentences. You need to determine if any of the individual words within a given sentence is a palindrome. A palindrome is a word that reads the same backward as forward.
Input:
The first line of the input contains an integer T, the number of sentences. The following T lines each contain one sent... | def is_palindrome(word):
"""
Returns True if word is a palindrome, otherwise False.
"""
return word == word[::-1]
def has_palindrome_sentence(sentence):
"""
Checks if the sentence has at least one word that is a palindrome.
Returns "Yes" if there's at least one palindrome word, otherwise "N... | from solution import is_palindrome, has_palindrome_sentence, check_palindromes_in_sentences, main
def test_is_palindrome():
assert is_palindrome("level") == True
assert is_palindrome("racecar") == True
assert is_palindrome("hello") == False
assert is_palindrome("") == True
assert is_palindrome("a")... | [
{
"docstring": "Returns True if word is a palindrome, otherwise False.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Checks if the sentence has at least one word that is a palindrome.\nReturns \"Yes\" if ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_palindrome(sentence):\n \"\"\"\n Determine if any of the individual words within a given sentence is a palindrome.\n \n Parameters:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017820",
"row_id": 17820,
"seed_ids": "[3961]"
} | 0.764493 | Code_Contests_17820 | I | [
"is_palindrome",
"has_palindrome_sentence",
"check_palindromes_in_sentences",
"main"
] | 4 | [
[
"check_palindromes_in_sentences",
"has_palindrome_sentence"
],
[
"has_palindrome_sentence",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f48d452ddd4ed118e7d5ad93cd9bbbf53ee6149d | f78eb891b20df1ea5c863c6a706a3fd675ca2519 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17832_I | A tree is a graph in which any two vertices are connected by exactly one path. The significance of a tree is that it is minimally connected: removing any edge will break it into multiple components.
In this problem, you are given a tree with N nodes (numbered 1 to N) and N-1 edges, and the goal is to process Q queries... | from collections import defaultdict
def dfs(node, parent, tree, subtree_size):
"""
Perform DFS to compute the size of the subtree for each node.
"""
subtree_size[node] = 1 # Each node is counted as part of its own subtree
for neighbor in tree[node]:
if neighbor != parent: # To avoid revis... | def test_tree_queries():
# Test case 1
N, Q = 7, 3
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]
queries = [1, 2, 3]
expected = [7, 3, 3]
assert process_tree(N, edges, queries) == expected
# Test case 2
N, Q = 5, 1
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
queries = [3... | [
{
"docstring": "Perform DFS to compute the size of the subtree for each node.",
"function_declaration": "def dfs(node, parent, tree, subtree_size):",
"function_name": "dfs",
"parameter_list": "(node, parent, tree, subtree_size)"
},
{
"docstring": "Process the tree and queries to compute the ... | [
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 compute_subtree_sizes(N, edges, queries):\n from collections import defaultdict, deque\n \n tree = defaultdict(list)\n for u, v in edges:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00017832",
"row_id": 17832,
"seed_ids": "[3651]"
} | 0.705806 | Code_Contests_17832 | I | [
"dfs",
"process_tree"
] | 2 | [
[
"process_tree",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f7e21097b721942a5ece150be76c0bb25458b2e7 | 7efd2103a1485b92657e50e741e1e44a3c4f2313 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17980_I | You are part of a delivery system in a city which is represented by a grid of size NxN. There are P parcels that need to be delivered to their respective destinations. The city has many crosswalks where delivery personnel can change their walking direction. The aim is to determine the shortest path for delivering each ... | def manhattan_distance(x1, y1, x2, y2):
"""
Returns the Manhattan distance between two points (x1, y1) and (x2, y2).
"""
return abs(x1 - x2) + abs(y1 - y2)
def shortest_paths(N, P, parcels):
"""
Returns a list of the shortest paths for delivering each parcel as per the Manhattan distance metric... | from solution import manhattan_distance, shortest_paths
def test_manhattan_distance():
assert manhattan_distance(1, 1, 5, 5) == 8
assert manhattan_distance(2, 3, 4, 1) == 4
assert manhattan_distance(0, 0, 0, 0) == 0
assert manhattan_distance(0, 0, 1, 1) == 2
assert manhattan_distance(3, 5, -3, -5) ... | [
{
"docstring": "Returns the Manhattan distance between two points (x1, y1) and (x2, y2).",
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Returns a list of the shortest paths fo... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def manhattan_distance(N, P, parcels):\n \"\"\"\n Returns the Manhattan distances for a list of parcels.\n \n Parameters:\n N (int): the... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00017980",
"row_id": 17980,
"seed_ids": "[85]"
} | 0.686807 | Code_Contests_17980 | I | [
"manhattan_distance",
"shortest_paths"
] | 2 | [
[
"shortest_paths",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f3c244a0a94ac05ebcf9c028e71d07867b83ce29 | 2c9e3a943af51ae16351758793dd5070a33ac455 | |||
v1.0 | instruct | Code_Contests | Code_Contests_17995_I | Manao is also tasked with designing the routes for a network of high-speed trains. The train routes will connect various cities in such a way that every city is connected to at least one other city, and there are no cycles in the network. Additionally, the distances between the cities have to be optimized for the minim... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank... | from solution import min_total_distance
def test_example_case():
n = 4
m = 5
routes = [
(1, 2, 4),
(1, 3, 2),
(2, 3, 1),
(2, 4, 5),
(3, 4, 3)
]
assert min_total_distance(n, m, routes) == 6
def test_minimal_case():
n = 2
m = 1
routes = [
(... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_minimum_total_distance(n, m, routes):\n \"\"\"\n Finds minimum possible total distance required to connect all cities without cycles.\n \... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00017995",
"row_id": 17995,
"seed_ids": "[12953]"
} | 0.761671 | Code_Contests_17995 | I | [
"find",
"union",
"kruskal",
"min_total_distance"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_total_distance",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | c44ad10187d8679c8f5128e2708303e1b5fa60f9 | 01b9ca63306adc0c329b59e77b372e58eb24636f | |||
v1.0 | instruct | Code_Contests | Code_Contests_18058_I | Alex is part of a volunteer group that assists the elderly with computer literacy. One of their projects is to help seniors with basic math exercises using a simple software application. The application generates sequences of numbers and asks the user to identify a certain property of the sequence.
You are tasked to a... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def first_k_primes(k):
primes = []
num... | from solution import first_k_primes
def test_first_five_primes():
assert first_k_primes(5) == [2, 3, 5, 7, 11]
def test_first_ten_primes():
assert first_k_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_single_prime():
assert first_k_primes(1) == [2]
def test_large_input_primes():
assert... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def first_k_primes(k):",
"function_name": "first_k_primes",
"parameter_list": "(k)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018058",
"row_id": 18058,
"seed_ids": "[12200]"
} | 0.642729 | Code_Contests_18058 | I | [
"is_prime",
"first_k_primes"
] | 2 | [
[
"first_k_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf5918dfb4615c5a8fc6407f10967f05503ca0bc | 16889388c6e9e6c54aaeaa4a7bf67da4dc467838 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18073_I | Mr. Anderson is fascinated by prime numbers. He wants to test your ability to recognize and work with prime numbers. Here is what he asks you to solve:
Given an array of integers, determine the K-th prime number that appears in the array. If the K-th prime does not exist, return -1.
INPUT
The first line consists of t... | def is_prime(n):
"""
Determines if n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
retu... | from solution import is_prime, find_kth_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(23) == True
def test_find_kth_prime():
assert find_kth_prime(10, 3, ... | [
{
"docstring": "Determines if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds the K-th prime number in the array if it exists.\nOtherwise, returns -1.",
"function_declaration": "def find_kth_... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00018073",
"row_id": 18073,
"seed_ids": "[10592]"
} | 0.636525 | Code_Contests_18073 | I | [
"is_prime",
"find_kth_prime"
] | 2 | [
[
"find_kth_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2990dd81a2c451d79992c30bc5a8e184b13d68fe | 70c89ef00a1387ae2b6650a927db68bcd1d9db78 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18111_I | You are given a binary tree with n nodes, where each node has a value of either 0 or 1. The two types of nodes represent black (1) or white (0) colors respectively. Your task is to calculate the smallest number of changes required to make the binary tree fully balanced in color distribution.
A fully balanced binary tr... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.children = []
def build_tree(n, edges):
nodes = {i: TreeNode() for i in range(1, n+1)}
for u, v in edges:
nodes[u].children.append(nodes[v])
nodes[v].children.append(nodes[u])
return nodes
def balance_tree(r... | from solution import min_changes
def test_sample_case_1():
n = 3
edges = [(1, 2), (1, 3)]
colors = [1, 0, 1]
assert min_changes(n, edges, colors) == 1
def test_sample_case_2():
n = 4
edges = [(1, 2), (1, 3), (3, 4)]
colors = [0, 1, 0, 1]
assert min_changes(n, edges, colors) == 1
d... | [] | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self):\n self.black = 0 # Number of black nodes in the subtree\n self.white = 0 # Number of whi... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00018111",
"row_id": 18111,
"seed_ids": "[11477]"
} | 0.658021 | Code_Contests_18111 | I | [
"build_tree",
"balance_tree",
"min_changes",
"solve",
"main"
] | 5 | [
[
"min_changes",
"balance_tree"
],
[
"min_changes",
"build_tree"
],
[
"solve",
"min_changes"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 0f9745484f09845cd6cfc78acaaaa0bb9849a7ea | 05aa012e0f758c9e71a2969fdbf66c3317e4fe20 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18127_I | A small city has N intersections connected by M two-way streets. Streets are represented as edges in an undirected graph with positive weights, which indicate the time required to travel along that street. Given Q queries, each asking if there exists a path between two intersections with at most T time, you need to det... | import heapq
def floyd_warshall(n, graph, max_time):
"""
Returns the matrix of shortest paths using Floyd Warshall algorithm with a time constraint.
"""
dist = [[float('inf')] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
dist[i][i] = 0
for u in range(1, n + 1):
... | from solution import analyze_paths
def test_analyze_paths():
N, M = 4, 4
edges = [
(1, 2, 3),
(2, 3, 4),
(1, 3, 8),
(3, 4, 2)
]
queries = [
(1, 3, 7),
(1, 4, 10),
(2, 4, 5)
]
assert analyze_paths(N, M, edges, queries) == ["YES", "YES", "NO... | [
{
"docstring": "Returns the matrix of shortest paths using Floyd Warshall algorithm with a time constraint.",
"function_declaration": "def floyd_warshall(n, graph, max_time):",
"function_name": "floyd_warshall",
"parameter_list": "(n, graph, max_time)"
},
{
"docstring": null,
"function_d... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef dijkstra(graph, start):\n \"\"\"\n Computes the shortest path from start to all other nodes using Dijkstra's algorithm.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018127",
"row_id": 18127,
"seed_ids": "[4031]"
} | 0.75442 | Code_Contests_18127 | I | [
"floyd_warshall",
"analyze_paths"
] | 2 | [
[
"analyze_paths",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 25009627d0f33ea47741b2e14a6b40ce2c507853 | 1402452591540903234861c6021bff073f09ea81 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18155_I | Given a list of integers, you are required to find the sum of the digits of each number in the list and return the number whose sum of digits is the highest. In case of a tie, return the largest number among those with the highest sum of digits.
Constraints
1 ≤ N ≤ 5000
100 ≤ an element of the list ≤ 10^10
Input
T... | def sum_of_digits(num):
return sum(int(digit) for digit in str(num))
def number_with_highest_digit_sum(lst):
max_digit_sum = -1
result = -1
for num in lst:
current_digit_sum = sum_of_digits(num)
if current_digit_sum > max_digit_sum or (current_digit_sum == max_digit_sum and num > result... | from solution import number_with_highest_digit_sum
def test_example1():
assert number_with_highest_digit_sum([123, 456, 789, 987]) == 987
def test_example2():
assert number_with_highest_digit_sum([111, 333, 222, 444, 555]) == 555
def test_single_element():
assert number_with_highest_digit_sum([100]) == 1... | [
{
"docstring": null,
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def number_with_highest_digit_sum(lst):",
"function_name": "number_with_highest_digit_sum",
"parame... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of the number n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\n\ndef ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018155",
"row_id": 18155,
"seed_ids": "[310]"
} | 0.671178 | Code_Contests_18155 | I | [
"sum_of_digits",
"number_with_highest_digit_sum"
] | 2 | [
[
"number_with_highest_digit_sum",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e097e490885c961235530d7c4692743d2f1137f9 | 636a1781e55e0bfb840676c3898524235dfffac5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18201_I | Given a 2D grid of size m x n, where each cell in the grid can either be a land cell (represented by 1) or a water cell (represented by 0). An island is defined as a group of connected land cells (connected horizontally or vertically). The grid is surrounded by water, and islands are separated by water.
Determine the ... | def dfs(grid, visited, x, y):
m, n = len(grid), len(grid[0])
stack = [(x, y)]
visited[x][y] = True
island_size = 0
while stack:
cx, cy = stack.pop()
island_size += 1
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ny = cx + dx, cy + dy
if 0 ... | def test_main():
input_data = "3\n4 5\n1 1 0 0 0\n1 1 0 0 1\n0 0 0 1 1\n0 0 1 1 1\n3 3\n0 0 0\n0 1 0\n0 0 0\n2 2\n0 1\n1 0\n"
output = main(input_data)
assert output == "6\n1\n1"
input_data = "1\n3 3\n1 1 1\n1 0 1\n1 1 1\n"
output = main(input_data)
assert output == "8"
input_data = "1... | [
{
"docstring": null,
"function_declaration": "def dfs(grid, visited, x, y):",
"function_name": "dfs",
"parameter_list": "(grid, visited, x, y)"
},
{
"docstring": null,
"function_declaration": "def largest_island_size(test_cases):",
"function_name": "largest_island_size",
"paramet... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_island(grid):\n if not grid:\n return 0\n \n m = len(grid)\n n = len(grid[0])\n \n def dfs(i, j):\n if i < 0 or... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018201",
"row_id": 18201,
"seed_ids": "[24]"
} | 0.686888 | Code_Contests_18201 | I | [
"dfs",
"largest_island_size",
"process_input",
"main"
] | 4 | [
[
"largest_island_size",
"dfs"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 790c5bfb43c5ee62c230a5c1dca324b8de8045de | 5f23a1c2d53cf395dfa6260df0ba65c116337e9f | |||
v1.0 | instruct | Code_Contests | Code_Contests_18223_I | During his recent math class, Alex learned about prime numbers and Fibonacci numbers. He decided to combine both concepts to create a new sequence which he calls "Prime Fibonacci Numbers".
Prime Fibonacci Numbers are the terms in the Fibonacci sequence that are also prime numbers. The Fibonacci sequence is defined as... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def generate_prime_fibonacci_numbers(N):
i... | from solution import is_prime, generate_prime_fibonacci_numbers, main
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(21) == False
def test_generate_prime_fibonacci_numbers():
assert generate_pri... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def generate_prime_fibonacci_numbers(N):",
"function_name": "generate_prime_fibonacci_numbers",
"parameter_list":... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\" Check if the given number is a prime number \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018223",
"row_id": 18223,
"seed_ids": "[9650]"
} | 0.793325 | Code_Contests_18223 | I | [
"is_prime",
"generate_prime_fibonacci_numbers",
"main"
] | 3 | [
[
"generate_prime_fibonacci_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 09d36401a2a13759223247cbe5dd1c5b200739d8 | 47404a15b4493b78e930bfe69c9e1e81ca24e36c | |||
v1.0 | instruct | Code_Contests | Code_Contests_18274_I | An online retailer is setting up a new system to dynamically adjust the prices of their products based on a demand score. Each product has a set base price and a demand score, which can change over time. The price of a product is adjusted by multiplying the base price by a factor based on the demand score. The adjustme... | def calculate_final_price(base_price, demand_score):
"""
Calculates the final price based on the base price and demand score.
:param base_price: float, the base price of the product
:param demand_score: float, the demand score of the product
:return: float, the final price of the product
""... | from solution import calculate_final_price, adjust_prices
def test_calculate_final_price():
assert calculate_final_price(100, 2) == 90.00
assert calculate_final_price(150, 5) == 150.00
assert calculate_final_price(200, 8) == 240.00
assert calculate_final_price(75, 1) == 67.50
assert calculate_final... | [
{
"docstring": "Calculates the final price based on the base price and demand score.\n\n:param base_price: float, the base price of the product\n:param demand_score: float, the demand score of the product\n:return: float, the final price of the product",
"function_declaration": "def calculate_final_price(ba... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_final_prices(n, products):\n final_prices = []\n\n for p, d in products:\n if d < 3:\n factor = 0.9\n elif 3 <... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018274",
"row_id": 18274,
"seed_ids": "[1913]"
} | 0.695419 | Code_Contests_18274 | I | [
"calculate_final_price",
"adjust_prices"
] | 2 | [
[
"adjust_prices",
"calculate_final_price"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ccabeaac1635ae00197e6fc06ff07475be56432 | d10dadd9394dbeffdd53a83d5b8134f5a91df496 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18299_I | Given a positive integer n, compute the number of ways n can be represented as a sum of exactly two prime numbers. It is guaranteed that the answer always exists for the given constraints.
Recall that an integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.
Input
... | def is_prime(n):
"""
Check if n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return Tr... | from solution import is_prime, count_prime_pairs
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
def test_count_prime_pairs():
assert count_prime_pair... | [
{
"docstring": "Check if n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the number of ways n can be represented as a sum of exactly two prime numbers.",
"function_declaration": "def count_... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_prime_sum_pairs(n):\n \"\"\"\n Returns the number of ways n can be represented as a sum of exactly two prime numbers.\n \"\"\"\n def ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018299",
"row_id": 18299,
"seed_ids": "[1934]"
} | 0.716238 | Code_Contests_18299 | I | [
"is_prime",
"count_prime_pairs"
] | 2 | [
[
"count_prime_pairs",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c1ce4c9d1b834e3cefe0a36152049f96c8c69786 | 601acedf658a94648b7f32b768dc1da021da807c | |||
v1.0 | instruct | Code_Contests | Code_Contests_18354_I | A company is interested in analyzing the performance of its software engineers. They maintain logs of the time spent on various modules by different engineers throughout the day. Each log entry records the start and end times an engineer worked on a specific module, along with the engineer's ID and the module's ID.
T... | from datetime import datetime, timedelta
def parse_time(time_str):
return datetime.strptime(time_str, "%H:%M")
def total_time_in_range(start_log, end_log, start_query, end_query):
start = max(start_log, start_query)
end = min(end_log, end_query)
if start >= end:
return timedelta()
return e... | from solution import analyze_logs
def test_analyze_logs_sample_case():
N = 5
logs = [
(1, 1, "08:00", "12:00"),
(2, 1, "09:00", "10:00"),
(1, 2, "13:00", "17:00"),
(2, 2, "08:00", "09:00"),
(1, 1, "18:00", "20:00")
]
Q = 3
queries = [
(1, 1, "07:00", ... | [
{
"docstring": null,
"function_declaration": "def parse_time(time_str):",
"function_name": "parse_time",
"parameter_list": "(time_str)"
},
{
"docstring": null,
"function_declaration": "def total_time_in_range(start_log, end_log, start_query, end_query):",
"function_name": "total_time... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime, timedelta\n\ndef parse_time(time_str):\n return datetime.strptime(time_str, \"%H:%M\")\n\ndef time_difference(start, end)... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00018354",
"row_id": 18354,
"seed_ids": "[1260]"
} | 0.635773 | Code_Contests_18354 | I | [
"parse_time",
"total_time_in_range",
"analyze_logs"
] | 3 | [
[
"analyze_logs",
"parse_time"
],
[
"analyze_logs",
"total_time_in_range"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bdef052494ca6426b4f3c45899b6653b2d3c959e | c4c54e2796eca1786967aafa191ae673f46984ea | |||
v1.0 | instruct | Code_Contests | Code_Contests_18373_I | Sasha is a passionate coder who loves solving mathematical puzzles. Recently, she came across a fascinating problem involving prime numbers and she needs your help to solve it.
A number is considered to be prime if it is greater than 1 and has no divisors other than 1 and itself. Sasha decided to find out how many pri... | def sieve_of_eratosthenes(max_num):
"""
Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (max_num + 1)
is_prime[0] = is_prime[1] = False # 0 and 1 are not primes
p = 2
while (p * p <= max_num):
if (is_prime[p] == True... | import pytest
from solution import num_of_primes_in_ranges
def test_single_range_with_primes():
assert num_of_primes_in_ranges(1, [(1, 10)]) == [4]
def test_single_range_without_primes():
assert num_of_primes_in_ranges(1, [(0, 1)]) == [0]
def test_multiple_ranges():
assert num_of_primes_in_ranges(5, [(1,... | [
{
"docstring": "Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(max_num):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(max_num)"
},
{
"docstring": "Counts the number of primes w... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Generates a list of prime numbers up to max_num using the Sieve of Eratosthenes algorithm.\n \"\"\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018373",
"row_id": 18373,
"seed_ids": "[530]"
} | 0.675481 | Code_Contests_18373 | I | [
"sieve_of_eratosthenes",
"count_primes_in_range",
"num_of_primes_in_ranges"
] | 3 | [
[
"num_of_primes_in_ranges",
"count_primes_in_range"
],
[
"num_of_primes_in_ranges",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1ee7a425af6404b1d11f117f9803a9334ca40d14 | f83e7a9687b2f551856a2b475ef5f06de243d365 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18386_I | In a fantasy role-playing game, players collect various types of items during their adventures. Each item has an assigned score value, and these scores can be used to determine the player's overall strength in the game. Players can collect multiple items of the same type, and the total score for a type of item is the s... | def determine_rank(total_score):
"""
Determine the performance rank based on the total score.
"""
if total_score <= 1000:
return "Novice"
elif total_score <= 5000:
return "Intermediate"
elif total_score <= 10000:
return "Expert"
else:
return "Master"
def eval... | from solution import determine_rank, evaluate_performance
def test_determine_rank():
assert determine_rank(1000) == "Novice"
assert determine_rank(500) == "Novice"
assert determine_rank(1500) == "Intermediate"
assert determine_rank(5000) == "Intermediate"
assert determine_rank(7000) == "Expert"
... | [
{
"docstring": "Determine the performance rank based on the total score.",
"function_declaration": "def determine_rank(total_score):",
"function_name": "determine_rank",
"parameter_list": "(total_score)"
},
{
"docstring": "Evaluate the performance rank for each player based on their inventor... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_ranks(T, Q, item_scores, players_inventories):\n \"\"\"\n Given the number of different item types T and number of players Q,\n this... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00018386",
"row_id": 18386,
"seed_ids": "[10905]"
} | 0.681583 | Code_Contests_18386 | I | [
"determine_rank",
"evaluate_performance"
] | 2 | [
[
"evaluate_performance",
"determine_rank"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2e2fe4f8bb8fd6f1d4fcb606eb77a5ac9d938cf3 | fb198e071a85f894a7472581f93ac218fbb0e590 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18445_I | You are working on an e-commerce website, and you have been assigned to optimize the new recommendation algorithm. The algorithm suggests products based on purchase history and browsing data. To measure its performance, you will run a series of tests to see how well the algorithm predicts product purchases over time.
... | def calculate_accuracy(purchased, recommended):
"""
Calculates the accuracy of the recommended products against the purchased products.
Accuracy is the ratio of correctly recommended products to the total number of purchased products.
"""
purchased_set = set(purchased)
recommended_set = set(reco... | import pytest
def test_calculate_accuracy():
assert calculate_accuracy([2, 3], [2]) == 0.5
assert calculate_accuracy([3, 5], [3, 4]) == 0.5
assert calculate_accuracy([4], [4, 5]) == 1.0
assert calculate_accuracy([1, 3, 5], [1, 3]) == 2 / 3
assert calculate_accuracy([], []) == 1.0
def test_overall_... | [
{
"docstring": "Calculates the accuracy of the recommended products against the purchased products.\nAccuracy is the ratio of correctly recommended products to the total number of purchased products.",
"function_declaration": "def calculate_accuracy(purchased, recommended):",
"function_name": "calculate... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_accuracy(test_cases):\n results = []\n for t in range(len(test_cases)):\n N, M, K, purchases, recommendations = test_cases[t]\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018445",
"row_id": 18445,
"seed_ids": "[7470]"
} | 0.589012 | Code_Contests_18445 | I | [
"calculate_accuracy",
"overall_accuracy"
] | 2 | [
[
"overall_accuracy",
"calculate_accuracy"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 08900ceefdfbfe4259cba4899737e06eaf50a0bb | cc89f89c9de1563f4f2fbc6633e6849f7c96b41d | |||
v1.0 | instruct | Code_Contests | Code_Contests_18449_I | Alice is exploring a new city laid out in a perfect grid. She's currently located at point (Ax, Ay) and wants to meet her friend Bob, who is at point (Bx, By). The roads in the city are either horizontal or vertical, and Alice can move one block in any of the four directions (north, south, east, or west) in one step. H... | from collections import deque
def bfs(grid, start, end):
"""
Perform BFS to find the shortest path from start to end in the grid.
Returns the number of steps if there is a path, otherwise returns -1.
"""
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
queue = deque([start])
visited = {start... | def test_min_steps():
test_cases = [
(1, 5, 0, 0, 4, 4, [(1, 2, 1, 3)]),
(0, 10, 0, 0, 9, 9, [])
]
T = 2
expected_results = [8, 18]
results = process_grid_paths(T, test_cases)
assert results == expected_results
def test_blocked_path():
test_cases = [
(1, 5, 0, 0, 4, ... | [
{
"docstring": "Perform BFS to find the shortest path from start to end in the grid.\nReturns the number of steps if there is a path, otherwise returns -1.",
"function_declaration": "def bfs(grid, start, end):",
"function_name": "bfs",
"parameter_list": "(grid, start, end)"
},
{
"docstring":... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_meet(T, test_cases):\n results = []\n \n def is_valid(x, y, M, blocked_set, visited):\n r... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00018449",
"row_id": 18449,
"seed_ids": "[2465]"
} | 0.724201 | Code_Contests_18449 | I | [
"bfs",
"min_steps_to_reach",
"process_grid_paths"
] | 3 | [
[
"min_steps_to_reach",
"bfs"
],
[
"process_grid_paths",
"min_steps_to_reach"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 7382fb0659dc91aae05c86cf89555dfa01112649 | 323100e04c085ed7cdd2dde1c7696d35eec823bd | |||
v1.0 | instruct | Code_Contests | Code_Contests_18461_I | You are given a binary tree rooted at node 1. Each node has a unique integer value between 1 and N (inclusive). The parent of each node is provided, except for the root, which has no parent.
Your task is to determine the sum of the values of nodes that are at the maximum depth of the tree.
Input format:
The first li... | def max_depth_sum(N, parents):
if N == 1:
return 1
from collections import defaultdict, deque
# Build the tree
tree = defaultdict(list)
for child_index, parent in enumerate(parents, start=2):
tree[parent].append(child_index)
# BFS to find the maximum depth and the sum
queu... | def test_max_depth_sum_single_node():
assert max_depth_sum(1, []) == 1
def test_max_depth_sum_case1():
assert max_depth_sum(5, [1, 1, 2, 2]) == 9
def test_max_depth_sum_case2():
assert max_depth_sum(8, [1, 2, 2, 4, 4, 5, 5]) == 15
def test_max_depth_sum_balanced_tree():
assert max_depth_sum(7, [1, 1,... | [
{
"docstring": null,
"function_declaration": "def max_depth_sum(N, parents):",
"function_name": "max_depth_sum",
"parameter_list": "(N, parents)"
},
{
"docstring": null,
"function_declaration": "def process_input_and_find_max_depth_sum():",
"function_name": "process_input_and_find_ma... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_deepest_nodes(N, parents):\n if N == 1:\n return 1\n\n from collections import defaultdict, deque\n\n tree = defaultdict(list)\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018461",
"row_id": 18461,
"seed_ids": "[601]"
} | 0.658715 | Code_Contests_18461 | I | [
"max_depth_sum",
"process_input_and_find_max_depth_sum"
] | 2 | [
[
"process_input_and_find_max_depth_sum",
"max_depth_sum"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9b420c5664909d11ca3c7c85b589f916325d6036 | e3c343ee23ba62e2163f14c33e286df67be2ecc1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18464_I | Write a program that reads an integer N, representing the number of students, followed by N sets of student information. Each set consists of a student's name, followed by three floats representing their grades in three subjects. The program should calculate the average grade for each student rounded to two decimal pla... | def calculate_grade(average):
if average >= 90:
return 'A'
elif average >= 80:
return 'B'
elif average >= 70:
return 'C'
elif average >= 60:
return 'D'
else:
return 'F'
def process_student_grades(N, student_info):
results = []
for info in student_info... | from solution import process_student_grades, calculate_grade
def test_calculate_grade():
assert calculate_grade(95) == 'A'
assert calculate_grade(85) == 'B'
assert calculate_grade(75) == 'C'
assert calculate_grade(65) == 'D'
assert calculate_grade(55) == 'F'
def test_process_student_grades():
... | [
{
"docstring": null,
"function_declaration": "def calculate_grade(average):",
"function_name": "calculate_grade",
"parameter_list": "(average)"
},
{
"docstring": null,
"function_declaration": "def process_student_grades(N, student_info):",
"function_name": "process_student_grades",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_grades(num_students, students_info):\n \"\"\"\n Calculate and return each student's average grade and letter grade based on given crite... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018464",
"row_id": 18464,
"seed_ids": "[5419]"
} | 0.689114 | Code_Contests_18464 | I | [
"calculate_grade",
"process_student_grades"
] | 2 | [
[
"process_student_grades",
"calculate_grade"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cc840d734b906c78801e120902b33803e23dfe8a | 51752bdb35e1ef324638c74697813ca280f61229 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18465_I | You are given a list of integers. Your task is to check if there are at least two integers in the list such that their product is a perfect square. If such a pair exists, print "YES"; otherwise, print "NO".
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the list. The secon... | import math
from collections import Counter
def has_pair_with_perfect_square_product(n, elements):
def get_prime_factors(num):
""" Returns the prime factorization of a number as a Counter """
factors = Counter()
d = 2
while d**2 <= num:
while (num % d) == 0:
... | from solution import has_pair_with_perfect_square_product
def test_example_1():
assert has_pair_with_perfect_square_product(5, [1, 2, 3, 4, 6]) == "YES"
def test_example_2():
assert has_pair_with_perfect_square_product(4, [2, 3, 5, 7]) == "NO"
def test_single_element():
assert has_pair_with_perfect_squar... | [
{
"docstring": null,
"function_declaration": "def has_pair_with_perfect_square_product(n, elements):",
"function_name": "has_pair_with_perfect_square_product",
"parameter_list": "(n, elements)"
},
{
"docstring": null,
"function_declaration": "def input_handling():",
"function_name": ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(x, y):\n while y:\n x, y = y, x % y\n return x\n\ndef is_perfect_square(n):\n root = int(n**0.5)\n return n == root * root\n\nde... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018465",
"row_id": 18465,
"seed_ids": "[4199]"
} | 0.667774 | Code_Contests_18465 | I | [
"has_pair_with_perfect_square_product",
"input_handling"
] | 2 | [
[
"input_handling",
"has_pair_with_perfect_square_product"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4a5f0dce44eeec5bca8c52b59de651c8a0880623 | ac40281122ff7184a98507bdff06a225e829d8dd | |||
v1.0 | instruct | Code_Contests | Code_Contests_18479_I | Given a list of integers, your task is to sort the numbers in such a way that all primes in the list appear before all composite numbers. Within the primes, the numbers should be sorted in increasing order. Within the composite numbers, the numbers should also be sorted in increasing order.
Input
* The first line of ... | def is_prime(num):
"""
Returns True if num is a prime number, False otherwise.
"""
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return Tr... | from solution import is_prime, sort_primes_composites
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(22) == False
def test_sort_primes_composites():
assert sort_primes_composites(8, [3, 5, 8, 13... | [
{
"docstring": "Returns True if num is a prime number, False otherwise.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Sorts the numbers such that all primes come before all composite numbers.\nPrimes and composites a... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00018479",
"row_id": 18479,
"seed_ids": "[10851]"
} | 0.620171 | Code_Contests_18479 | I | [
"is_prime",
"sort_primes_composites"
] | 2 | [
[
"sort_primes_composites",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a0b5bbf2599e2e392ed71f791b1ecf0b72af5c68 | 3a1f44d7fe0199fb52458f4759a39b8714c8d180 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18502_I | You are given a simple undirected graph with n nodes and m edges. Each edge has an associated weight. You are also given q queries, where each query consists of two integers u and k. For each query, you need to find the number of nodes that are reachable from node u with a path consisting of k edges, and all edges in t... | def create_adjacency_list(n, edges):
adj = {i: [] for i in range(1, n+1)}
for u, v, w in edges:
adj[u].append((v, w))
adj[v].append((u, w))
return adj
def dfs(adj, u, k, threshold, seen=set()):
if k == 0:
return 1
count = 0
seen.add(u)
for v, w in adj[u]:
if ... | from solution import reachable_nodes
def test_reachable_nodes_example():
n = 4
m = 4
edges = [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 6)
]
q = 3
queries = [
(1, 2),
(3, 1),
(4, 0)
]
threshold = 6
assert reachable_nodes(n, m, e... | [
{
"docstring": null,
"function_declaration": "def create_adjacency_list(n, edges):",
"function_name": "create_adjacency_list",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def dfs(adj, u, k, threshold, seen=set()):",
"function_name": "dfs",
"par... | [
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef process_graph_input(n, m, edges):\n graph = defaultdict(list)\n for u, v, w in edges:\n grap... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00018502",
"row_id": 18502,
"seed_ids": "[9308]"
} | 0.747854 | Code_Contests_18502 | I | [
"create_adjacency_list",
"dfs",
"reachable_nodes"
] | 3 | [
[
"reachable_nodes",
"create_adjacency_list"
],
[
"reachable_nodes",
"dfs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 06ddbb75939ce338ff7e906ca4ea5cd2ca048568 | 1ceac606c7db5d14f6045a99334580d24f560991 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18527_I | In a technical interview, you'll face a problem where you need to rearrange a list of integers into their lexicographically smallest permutation which is a palindrome. If it's not possible, output -1.
## Problem
You will be given a single integer `n` followed by a sequence of `n` integers.
Your task is to determine ... | from collections import Counter
def lexicographically_smallest_palindrome(n, sequence):
"""
Returns the lexicographically smallest palindrome permutation of the given sequence.
If such a permutation doesn't exist, return -1.
"""
# Count the frequency of each number in the sequence
count = Coun... | from solution import lexicographically_smallest_palindrome
def test_palindrome_exists():
assert lexicographically_smallest_palindrome(6, [1, 2, 3, 2, 1, 3]) == [1, 2, 3, 3, 2, 1]
assert lexicographically_smallest_palindrome(5, [1, 1, 2, 2, 3]) == [1, 2, 3, 2, 1]
assert lexicographically_smallest_palindrome... | [
{
"docstring": "Returns the lexicographically smallest palindrome permutation of the given sequence.\nIf such a permutation doesn't exist, return -1.",
"function_declaration": "def lexicographically_smallest_palindrome(n, sequence):",
"function_name": "lexicographically_smallest_palindrome",
"parame... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef lexicographically_smallest_palindrome(n, sequence):\n \"\"\"\n Returns the lexicographically smallest palindro... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00018527",
"row_id": 18527,
"seed_ids": "[6142]"
} | 0.768173 | Code_Contests_18527 | I | [
"lexicographically_smallest_palindrome",
"input_and_solve"
] | 2 | [
[
"input_and_solve",
"lexicographically_smallest_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 764427c5f047835579b7fb33e8317cbcd505943a | 57ac03a95b279d7a97b9b521456ccf7f2fdafa50 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18580_I | A company organizes a daily meeting for its employees. The meeting can start at any time between 9:00 AM and 5:00 PM, and the duration of the meeting is fixed. The meeting organizer prefers a time slot when a minimum number of attendees are already in other meetings to maximize participation.
You are provided with the... | from datetime import datetime, timedelta
def parse_time_interval(interval):
"""
Parses a single time interval string into a tuple of datetime objects.
"""
start_str, end_str = interval.split('-')
start_time = datetime.strptime(start_str, "%H:%M")
end_time = datetime.strptime(end_str, "%H:%M")
... | from solution import optimal_meeting_time
def test_example_1():
m = 60
n = 3
schedules = [
"09:00-10:00 14:00-15:30",
"11:00-12:00 13:00-14:00",
"10:00-11:00 15:00-16:00"
]
assert optimal_meeting_time(m, n, schedules) == "12:00"
def test_example_2():
m = 30
n = 2
... | [
{
"docstring": "Parses a single time interval string into a tuple of datetime objects.",
"function_declaration": "def parse_time_interval(interval):",
"function_name": "parse_time_interval",
"parameter_list": "(interval)"
},
{
"docstring": "Parses a schedule string into a list of time interv... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from datetime import datetime, timedelta\n\ndef parse_time_interval(interval):\n \"\"\"\n Helper function to parse a time in... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018580",
"row_id": 18580,
"seed_ids": "[12652]"
} | 0.736379 | Code_Contests_18580 | I | [
"parse_time_interval",
"parse_schedule",
"find_optimal_meeting_time",
"optimal_meeting_time"
] | 4 | [
[
"find_optimal_meeting_time",
"parse_schedule"
],
[
"optimal_meeting_time",
"find_optimal_meeting_time"
],
[
"parse_schedule",
"parse_time_interval"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | d348589258e7d8e6f80aadc3274065c350fd8bb6 | f7bde5cea09d9ca3825006eba65aef32d947daac | |||
v1.0 | instruct | Code_Contests | Code_Contests_18636_I | Jessica is working with a large array of size up to 10^9 elements where each element at position i is defined as follows:
- b_i = i^2 if i is odd
- b_i = -i^2 if i is even
She has come up with several queries to determine the sum of elements within a specified subarray. Each query consists of two integers l and r, wh... | def element_value(i):
"""
Returns the value of the element at position i based on
whether i is odd or even.
"""
if i % 2 == 0:
return -i * i
else:
return i * i
def query_sum(l, r):
"""
Returns the sum of the elements from index l to index r inclusive.
"""
sum = 0... | def test_element_value():
assert element_value(1) == 1
assert element_value(2) == -4
assert element_value(3) == 9
assert element_value(4) == -16
assert element_value(5) == 25
def test_query_sum_single_element():
assert query_sum(1, 1) == 1
assert query_sum(2, 2) == -4
def test_query_sum_mu... | [
{
"docstring": "Returns the value of the element at position i based on\nwhether i is odd or even.",
"function_declaration": "def element_value(i):",
"function_name": "element_value",
"parameter_list": "(i)"
},
{
"docstring": "Returns the sum of the elements from index l to index r inclusive... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_b_i_sum(l, r):\n \"\"\"\n This function takes two integers l and r,\n and returns the sum of elements in the array defined as:\n ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00018636",
"row_id": 18636,
"seed_ids": "[12297]"
} | 0.675678 | Code_Contests_18636 | I | [
"element_value",
"query_sum",
"solve"
] | 3 | [
[
"query_sum",
"element_value"
],
[
"solve",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | c06a82a5174292b0299623b417bc052f078ec5d9 | cceec4b73163768faa790f2094d56fa3b58d34b8 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18641_I | In a fantasy land, there are n magical islands connected by m bidirectional bridges. The maintenance of these bridges is crucial for the kingdom’s trade and defense. Each bridge has a maintenance cost associated with it. Your task is to ensure that the capital city remains connected to all other islands while minimizin... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i]) # Path compression
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
... | from solution import minimum_maintenance_cost
def test_example_case():
n = 5
m = 6
bridges = [
(1, 2, 3),
(1, 3, 1),
(2, 3, 3),
(2, 4, 6),
(3, 4, 2),
(4, 5, 5)
]
assert minimum_maintenance_cost(n, m, bridges) == 11
def test_single_bridge():
n = 2... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018641",
"row_id": 18641,
"seed_ids": "[6361]"
} | 0.773538 | Code_Contests_18641 | I | [
"find",
"union",
"kruskal",
"minimum_maintenance_cost"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_maintenance_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fd136168b1f63e184cc67ff77428ea40fce2b996 | db2a42715edacb0f3d9b5695b3b4fe6c20523aaa | |||
v1.0 | instruct | Code_Contests | Code_Contests_18656_I | You are given a directed acyclic graph (DAG) with `n` nodes and `m` edges. Each node has a certain value associated with it. You need to perform `q` queries on this graph.
There are two types of queries:
1. Update the value of a node to a new value.
2. Find the maximum value of a node among all possible paths from a ... | from collections import defaultdict, deque
import sys
sys.setrecursionlimit(10**6)
def update_value(node_values, node, new_value):
"""
Update the value of the given node with the new_value.
"""
node_values[node] = new_value
def find_max_value_dfs(node, node_values, adj_list, memo):
"""
Perfor... | from solution import handle_queries
def test_example_case():
n, m = 6, 7
node_values = [0, 3, 2, 5, 1, 4, 6]
edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (4, 6), (5, 6)]
queries = [
(2, 1),
(1, 3, 10),
(2, 1),
(2, 4)
]
expected = [6, 10, 6]
assert handle_... | [
{
"docstring": "Update the value of the given node with the new_value.",
"function_declaration": "def update_value(node_values, node, new_value):",
"function_name": "update_value",
"parameter_list": "(node_values, node, new_value)"
},
{
"docstring": "Perform DFS to find the maximum value rea... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass DAG:\n def __init__(self, n, node_values, edges):\n self.n = n\n self.node_values = no... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018656",
"row_id": 18656,
"seed_ids": "[6051]"
} | 0.76346 | Code_Contests_18656 | I | [
"update_value",
"find_max_value_dfs",
"handle_queries"
] | 3 | [
[
"handle_queries",
"find_max_value_dfs"
],
[
"handle_queries",
"update_value"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | true | [] | true | 73387dc4a3186910daeb7c546a3759bfd48c07d6 | f9919dfa5b99b175e5975060f47cd539be0a6d17 | |||
v1.0 | instruct | Code_Contests | Code_Contests_18722_I | Problem
In a magical forest, there are some animals who love solving puzzles. They recently discovered a number puzzle and need your help to solve it. The puzzle works as follows:
Given two integers $N$ and $M$, generate a sequence of length $N$ where each element is an integer between $1$ and $M$ (inclusive). The se... | def generate_sequences(N, M):
"""
Generate all sequences of length N where each element is between 1 and M (inclusive)
in non-decreasing order.
Parameters:
N (int): Length of each sequence.
M (int): Maximum value of each element in the sequence.
Returns:
List[List[int]]: A lis... | def test_generate_sequences_2_3():
expected = [
(1, 1), (1, 2), (1, 3),
(2, 2), (2, 3),
(3, 3)
]
assert generate_sequences(2, 3) == expected
def test_generate_sequences_3_2():
expected = [
(1, 1, 1), (1, 1, 2),
(1, 2, 2),
(2, 2, 2)
]
assert ge... | [
{
"docstring": "Generate all sequences of length N where each element is between 1 and M (inclusive) \nin non-decreasing order.\n\nParameters:\nN (int): Length of each sequence.\nM (int): Maximum value of each element in the sequence.\n\nReturns:\nList[List[int]]: A list of sequences in non-decreasing lexicogra... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_sequences(N, M):\n def backtrack(start, sequence):\n if len(sequence) == N:\n result.append(sequence[:])\n ret... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00018722",
"row_id": 18722,
"seed_ids": "[11765]"
} | 0.763721 | Code_Contests_18722 | I | [
"generate_sequences",
"format_sequences",
"solve"
] | 3 | [
[
"solve",
"format_sequences"
],
[
"solve",
"generate_sequences"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | f2c4869dbf17bea6efa4d4ac3b0231817e62292b | 9ddc7b82d99128283cf9dd0d77b928d17a1c53da | |||
v1.0 | instruct | Code_Contests | Code_Contests_18770_I | You are given a grid of size n x m where each cell contains a non-negative integer representing the height of that cell. You need to find the maximum area of a rectangle that can be formed with cells of equal height.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the dimensions of the grid.
Ea... | def max_area_of_equal_height(grid):
if not grid:
return 0
n = len(grid)
m = len(grid[0])
max_area = 0
for height in range(101):
heights = [[0] * m for _ in range(n)]
for i in range(n):
for j in range(m):
if grid[i][j] == height:
... | from solution import max_area_of_equal_height
def test_max_area_example1():
grid = [
[1, 1, 1, 2],
[2, 1, 1, 1],
[1, 1, 1, 1]
]
assert max_area_of_equal_height(grid) == 6
def test_max_area_example2():
grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
as... | [
{
"docstring": null,
"function_declaration": "def max_area_of_equal_height(grid):",
"function_name": "max_area_of_equal_height",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(heights):",
"function_name": "largest_rectangle_area... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_equal_height_area(grid):\n if not grid or not grid[0]:\n return 0\n \n n = len(grid)\n m = len(grid[0])\n \n max_area = 0\... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00018770",
"row_id": 18770,
"seed_ids": "[8038]"
} | 0.730268 | Code_Contests_18770 | I | [
"max_area_of_equal_height",
"largest_rectangle_area"
] | 2 | [
[
"max_area_of_equal_height",
"largest_rectangle_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1ce083d6d580c3215dcf96c528b04a6bef715f49 | 7496b91fe58dfb5d408eec4bb45f744b56cc663b | |||
v1.0 | instruct | Code_Contests | Code_Contests_18842_I | #### Input
The input is given from standard input in the following format:
```
N M
x1 y1 z1
x2 y2 z2
:
:
xM yM zM
```
- N is the number of nodes in a forest.
- M is the number of connections between the nodes.
- xi, yi, zi (1 ≤ xi, yi ≤ N) represent a connection between node xi and node yi with cost zi.
#### Constr... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import mst_min_cost
def test_example1():
N = 5
M = 6
connections = [
(1, 2, 3),
(1, 3, 4),
(4, 5, 2),
(2, 4, 1),
(3, 4, 5),
(2, 5, 7),
]
assert mst_min_cost(N, M, connections) == 10
def test_example2():
N = 4
M = 2
connectio... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(pare... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00018842",
"row_id": 18842,
"seed_ids": "[3629]"
} | 0.721913 | Code_Contests_18842 | I | [
"find",
"union",
"kruskal",
"mst_min_cost",
"main"
] | 5 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"mst_min_cost",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 178ebc106ef4dd8dc028e5ae98c6f77d4271bbbf | 9b05deea3aa21699ac4d9b06c5889226c49519f0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.