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_475_I
Grace is working on a schedule management system for a group of lecturers. Each lecturer has a list of lectures they need to give, each associated with a specific start and end time. Grace wants to ensure that each lecturer's schedule does not have any overlapping lectures, meaning a lecturer cannot have two or more le...
def is_schedule_valid(lectures): """ Returns True if there are no overlapping lectures in the list of lectures, False otherwise. """ lectures.sort(key=lambda x: x[0]) # Sort lectures by start time for i in range(1, len(lectures)): if lectures[i][0] < lectures[i-1][1]: return Fal...
from solution import is_schedule_valid, validate_schedules def test_is_schedule_valid(): assert is_schedule_valid([(10, 20), (20, 30), (30, 40)]) == True assert is_schedule_valid([(5, 10), (15, 20)]) == True assert is_schedule_valid([(5, 10), (8, 12)]) == False assert is_schedule_valid([(10, 15), (15, ...
[ { "docstring": "Returns True if there are no overlapping lectures in the list of lectures, False otherwise.", "function_declaration": "def is_schedule_valid(lectures):", "function_name": "is_schedule_valid", "parameter_list": "(lectures)" }, { "docstring": "Validates the schedules for multip...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_lecturer_schedule(lectures):\n \"\"\"\n Checks whether the given lectures' schedule of a lecturer is valid (no overlapping).\n \"\"\"...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00000475", "row_id": 475, "seed_ids": "[3850]" }
0.646962
Code_Contests_475
I
[ "is_schedule_valid", "validate_schedules", "main" ]
3
[ [ "validate_schedules", "is_schedule_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a28e3adf4b9779f1a69c6ba32ad34904a758a63b
a3fad66b61e89daa1292be7e27f7f99fb29d488f
v1.0
instruct
Code_Contests
Code_Contests_499_I
You are given an undirected graph with `n` vertices and `m` edges. Each edge has a weight associated with it. Write a program to find the shortest path from a given start vertex `s` to an end vertex `t`. If there are multiple shortest paths, return any one of them. Input The input consists of multiple datasets. Each ...
import heapq import sys def dijkstra(n, adj_list, start, end): dist = [sys.maxsize] * n dist[start] = 0 prev = [-1] * n pq = [(0, start)] while pq: current_dist, u = heapq.heappop(pq) if current_dist > dist[u]: continue for v, weight in adj...
def test_process_input(): input_string = """5 6 0 1 2 1 2 4 2 3 1 3 0 7 3 4 3 1 4 5 0 4 3 3 0 1 1 1 2 1 0 2 5 0 2 #""" expected_output = [ { 'n': 5, 'm': 6, 'edges': [(0, 1, 2), (1, 2, 4), (2, 3, 1), (3, 0, 7), (3, 4, 3), (1, 4, 5)], 's': 0, 't': 4 }, { ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, adj_list, start, end):", "function_name": "dijkstra", "parameter_list": "(n, adj_list, start, end)" }, { "docstring": null, "function_declaration": "def shortest_paths(datasets):", "function_name": "shortest_paths", "p...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, edges, start, end):\n graph = {i: [] for i in range(n)}\n for u, v, w in edges:\n graph[u].append((v, w))\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000499", "row_id": 499, "seed_ids": "[2810]" }
0.791779
Code_Contests_499
I
[ "dijkstra", "shortest_paths", "process_input", "generate_output", "main" ]
5
[ [ "shortest_paths", "dijkstra" ] ]
1
[ "process_input", "generate_output" ]
false
[]
false
pytest
false
[]
true
f33ecd39fba43a880960063f6969d8a40aa51726
aac30eaf9ddf4ce3ac1445ae397824192dd393fe
v1.0
instruct
Code_Contests
Code_Contests_545_I
In the kingdom of Quadrantland, there is a special grid used for communication. This grid is made up of cells, each containing a non-negative integer. Citizens love to send messages by selecting a subgrid (a rectangular section of the main grid) and calculating its "weight". The weight of a subgrid is defined as the s...
def preprocess_grid(grid): n = len(grid) m = len(grid[0]) prefix_sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): prefix_sum[i][j] = grid[i-1][j-1] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] return pre...
def test_preprocess_grid(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected_prefix_sum = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preprocess_grid(grid) == expected_prefix_sum def test_query_weight(): prefi...
[ { "docstring": null, "function_declaration": "def preprocess_grid(grid):", "function_name": "preprocess_grid", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def query_weight(prefix_sum, r1, c1, r2, c2):", "function_name": "query_weight", "parameter_l...
[ 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 calculate_weight(grid, queries):\n n = len(grid)\n m = len(grid[0])\n \n # Create a prefix sum matrix to optimize the weight calculation\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000545", "row_id": 545, "seed_ids": "[8669]" }
0.671433
Code_Contests_545
I
[ "preprocess_grid", "query_weight", "solve" ]
3
[ [ "solve", "preprocess_grid" ], [ "solve", "query_weight" ] ]
2
[]
false
[]
false
pytest
false
[]
true
706d65059ce60968e320c1c7949279cb38b4c261
fe484f0903104c83997fc3620454012178afd8d7
v1.0
instruct
Code_Contests
Code_Contests_564_I
Palindrome Chain: A palindrome is a sequence that reads the same backward as forward. Sometimes, by reversing the digits of a number and adding it to the original number, we might get a larger number that is a palindrome. If the resulting sum is not a palindrome, we repeat the process until we obtain a palindrome. For...
def reverse_number(n): """ Returns the reverse of integer n. For example, reverse_number(123) returns 321. """ return int(str(n)[::-1]) def is_palindrome(n): """ Checks if integer n is a palindrome. For example, is_palindrome(121) returns True, is_palindrome(123) returns False. """ ...
from solution import reverse_number, is_palindrome, palindrome_chain_length, iterations_to_palindrome def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(4000) == 4 assert reverse_number(1) == 1 assert reverse_number(120) == 21 def test_is_palindrome(): assert is_pal...
[ { "docstring": "Returns the reverse of integer n.\nFor example, reverse_number(123) returns 321.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": "Checks if integer n is a palindrome.\nFor example, is_palindrome(...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef iterations_to_palindr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000564", "row_id": 564, "seed_ids": "[4261]" }
0.716202
Code_Contests_564
I
[ "reverse_number", "is_palindrome", "palindrome_chain_length", "iterations_to_palindrome" ]
4
[ [ "iterations_to_palindrome", "palindrome_chain_length" ], [ "palindrome_chain_length", "is_palindrome" ], [ "palindrome_chain_length", "reverse_number" ] ]
3
[]
false
[]
false
pytest
true
[]
true
220d15388eee23d30983c273e9c612b361d09093
e39ab6d098bb4658d80bece83b527c1b747661bf
v1.0
instruct
Code_Contests
Code_Contests_604_I
A delivery company needs to calculate the minimum cost required to deliver parcels to various cities using different transportation routes. Each route connects two cities and has a certain cost associated with it. To maximize efficiency, the company wants to ensure that the total delivery cost is minimized while coveri...
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[yroot] < rank...
from solution import minimum_delivery_cost def test_example1(): n = 4 m = 5 routes = [ (1, 2, 2), (1, 3, 3), (2, 3, 1), (2, 4, 4), (3, 4, 5), ] assert minimum_delivery_cost(n, m, routes) == 7 def test_example2(): n = 3 m = 1 routes = [ (1...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 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_minimum_spanning_tree(n, edges):\n \"\"\"\n Using Kruskal's algorithm to find the Minimum Spanning Tree (MST) cost for a given graph.\n I...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000604", "row_id": 604, "seed_ids": "[6509]" }
0.751572
Code_Contests_604
I
[ "find", "union", "kruskal", "minimum_delivery_cost" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_delivery_cost", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
6ba0e8b1797ed8f76b055c9b6bea734e624c147c
f0f9164e5fd8f1f5e5e090e034c3c18fc236a41c
v1.0
instruct
Code_Contests
Code_Contests_652_I
Valera is studying trees this time. A tree is a connected graph with no cycles. Valera finds trees particularly interesting because there is exactly one unique path between any two nodes. Valera is given a tree with n nodes labeled from 1 to n. He wants to perform some queries on this tree. Each query consists of spec...
from collections import defaultdict, deque def preprocess_tree(n, edges): """ Preprocess the tree to prepare for efficient path length queries. :param n: Number of nodes in the tree :param edges: List of tuples representing edges in the tree :return: parent, depth arrays used for LCA computati...
from solution import process_queries def test_example_case(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] queries = [(2, 4), (2, 5), (4, 5)] expected_results = [3, 3, 2] assert process_queries(n, edges, queries) == expected_results def test_simple_case(): n = 2 edges = [(1, 2)] quer...
[ { "docstring": "Preprocess the tree to prepare for efficient path length queries.\n\n:param n: Number of nodes in the tree\n:param edges: List of tuples representing edges in the tree\n:return: parent, depth arrays used for LCA computation", "function_declaration": "def preprocess_tree(n, edges):", "fun...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef preprocess_tree(n, edges):\n # create adjacency list\n adj_list = [[] for _ in range(n + 1)]\n for u, v in ed...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000652", "row_id": 652, "seed_ids": "[6809]" }
0.686164
Code_Contests_652
I
[ "preprocess_tree", "lca", "distance", "process_queries" ]
4
[ [ "distance", "lca" ], [ "process_queries", "distance" ], [ "process_queries", "preprocess_tree" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
2994f61b2f9ce7dbf82c474ef5601ad776cfa769
2d72c1b5f1162b719707411f7baef30b774441d5
v1.0
instruct
Code_Contests
Code_Contests_653_I
In a company, each employee is represented by an ID, which is a positive integer. The management wants to schedule meetings based on the seniority of employees. The seniority is determined by the number of divisors of the employee ID; the more divisors an employee ID has, the more senior the employee is. If two employe...
def count_divisors(n): """Returns the number of divisors of n.""" count = 0 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: count += 1 if i != n // i: count += 1 return count def most_senior_employee(T, test_cases): """Returns the ID of the most ...
def test_count_divisors(): assert count_divisors(1) == 1 assert count_divisors(2) == 2 assert count_divisors(3) == 2 assert count_divisors(6) == 4 assert count_divisors(10) == 4 assert count_divisors(16) == 5 def test_most_senior_employee(): assert most_senior_employee(2, [(3, [10, 6, 8]), ...
[ { "docstring": "Returns the number of divisors of n.", "function_declaration": "def count_divisors(n):", "function_name": "count_divisors", "parameter_list": "(n)" }, { "docstring": "Returns the ID of the most senior employee for each test case.", "function_declaration": "def most_senior...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def number_of_divisors(n):\n \"\"\"Returns the number of divisors of a given integer n.\"\"\"\n count = 0\n for i in range(1, int(n**0.5) + 1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000653", "row_id": 653, "seed_ids": "[7084]" }
0.677885
Code_Contests_653
I
[ "count_divisors", "most_senior_employee" ]
2
[ [ "most_senior_employee", "count_divisors" ] ]
1
[]
false
[]
false
pytest
false
[]
true
804c132a1925e54d52b1a23debb6390145a4f7f2
f54e61fded72aa101043bf279cfeec7a0eb4a702
v1.0
instruct
Code_Contests
Code_Contests_664_I
In a distant galaxy, there is a new type of currency called "GalaxyCoins". Each GalaxyCoin has a value represented by a string of lowercase English letters. The value of a GalaxyCoin string "val" is defined as follows: 1. If "val" is a palindrome, then the value is the length of the string. 2. If "val" is not a palind...
def is_palindrome(s): return s == s[::-1] def longest_palindromic_subsequence(s): n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n): dp[i][i] = 1 for cl in range(2, n+1): for i in range(n-cl+1): j = i + cl - 1 if s[i] == s[j] and cl == 2: ...
from solution import galaxy_coin_value, solve def test_galaxy_coin_value(): assert galaxy_coin_value("abba") == 4 assert galaxy_coin_value("abc") == 2 assert galaxy_coin_value("cbbd") == 4 def test_is_palindrome(): assert is_palindrome("abba") == True assert is_palindrome("abc") == False asser...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(s):", "function_name": "longest_palindromic_subsequence", "paramete...
[ 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 longest_palindromic_subsequence(val):\n n = len(val)\n dp = [[0] * n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = 1\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000664", "row_id": 664, "seed_ids": "[3026]" }
0.660317
Code_Contests_664
I
[ "is_palindrome", "longest_palindromic_subsequence", "galaxy_coin_value", "solve" ]
4
[ [ "galaxy_coin_value", "is_palindrome" ], [ "galaxy_coin_value", "longest_palindromic_subsequence" ], [ "solve", "galaxy_coin_value" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f43075d03ad2ec6648a2a18a181c642bce6143fb
74a7690de11f9251976ff6a1ef0be3256aa550cf
v1.0
instruct
Code_Contests
Code_Contests_776_I
A company's HR department wants to generate unique employee IDs for each new hire. Each employee ID is generated using the employee’s full name and a unique number assigned to them. The unique number starts from 1 and increments by 1 for each new hire. The ID format follows these rules: - The ID begins with the first ...
def generate_employee_id(name, number): """ Generates a unique employee ID based on the provided full name and unique number. Parameters: name (str): The full name of the employee in the format "FirstName LastName". number (int): The unique number assigned to the employee. Returns: ...
def test_generate_employee_id(): assert generate_employee_id("John Doe", 1) == "JD-1" assert generate_employee_id("Alice Smith", 2) == "AS-2" assert generate_employee_id("Bob Johnson", 3) == "BJ-3" assert generate_employee_id("Chris Evans", 25) == "CE-25" assert generate_employee_id("Tony Stark", 26...
[ { "docstring": "Generates a unique employee ID based on the provided full name and unique number.\n\nParameters:\nname (str): The full name of the employee in the format \"FirstName LastName\".\nnumber (int): The unique number assigned to the employee.\n\nReturns:\nstr: The generated employee ID.", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_employee_id(full_name, number):\n \"\"\"\n Generates a unique employee ID from the employee's full name and the unique number.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000776", "row_id": 776, "seed_ids": "[10885]" }
0.604905
Code_Contests_776
I
[ "generate_employee_id", "process_new_hires" ]
2
[ [ "process_new_hires", "generate_employee_id" ] ]
1
[]
false
[]
false
pytest
false
[]
true
80f39b98b4b5c0ca54c64fb4cac9242cfe56310d
a908e1a7c648289081177b31775c4afe877dad25
v1.0
instruct
Code_Contests
Code_Contests_783_I
You are given an array of integers and some queries. For each query, you will be given two integers L and R (1 ≤ L ≤ R ≤ n), and you need to find the sum of elements in the array from index L to R (both inclusive). The array is 1-indexed. Input The first line of the input contains two integers, n and q (1 ≤ n, q ≤ 10...
def prefix_sum(array): """ Computes the prefix sum of the given array. """ prefix = [0] * (len(array) + 1) for i in range(1, len(array) + 1): prefix[i] = prefix[i - 1] + array[i - 1] return prefix def range_sum(prefix, L, R): """ Computes the range sum using the prefix sum array...
def test_prefix_sum(): assert prefix_sum([1, 2, 3, 4, 5]) == [0, 1, 3, 6, 10, 15] def test_range_sum(): prefix = [0, 1, 3, 6, 10, 15] assert range_sum(prefix, 1, 3) == 6 assert range_sum(prefix, 2, 4) == 9 assert range_sum(prefix, 1, 5) == 15 def test_sum_queries(): array = [1, 2, 3, 4, 5] ...
[ { "docstring": "Computes the prefix sum of the given array.", "function_declaration": "def prefix_sum(array):", "function_name": "prefix_sum", "parameter_list": "(array)" }, { "docstring": "Computes the range sum using the prefix sum array.", "function_declaration": "def range_sum(prefix...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prefix_sums(arr):\n \"\"\"\n Construct prefix sums array from the given array.\n \"\"\"\n n = len(arr)\n prefix = [0] * (n + 1)\n for...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000783", "row_id": 783, "seed_ids": "[572]" }
0.722944
Code_Contests_783
I
[ "prefix_sum", "range_sum", "sum_queries" ]
3
[ [ "sum_queries", "prefix_sum" ], [ "sum_queries", "range_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
258fe7b68f9a830e910f4a6b5005ca1ed9b2aa7c
db053cc8e637c0184fc21a2609f8efc8293e980f
v1.0
instruct
Code_Contests
Code_Contests_823_I
You are developing a game where the player navigates a grid of size n x m. The grid contains barriers and the player's movement is constrained by these obstacles. The player's goal is to move from the top-left corner of the grid (1,1) to the bottom-right corner of the grid (n,m). However, the player can only move right...
def num_paths(grid): n = len(grid) m = len(grid[0]) # Ensure top-left and bottom-right are not barriers if grid[0][0] == '#' or grid[n-1][m-1] == '#': return 0 # Initialize DP table dp = [[0]*m for _ in range(n)] # Start position dp[0][0] = 1 # Fill DP tab...
from solution import count_paths def test_example_case(): input_data = '''3 3 . . . . # . . . .''' assert count_paths(input_data) == 2 def test_no_path_due_to_obstacle(): input_data = '''3 3 . . # . # . # . .''' assert count_paths(input_data) == 0 def test_single_path(): input_data = '''2 2 . . ....
[ { "docstring": null, "function_declaration": "def num_paths(grid):", "function_name": "num_paths", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter_list": "(input_string)" }, ...
[ 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 num_paths(grid):\n n = len(grid)\n m = len(grid[0])\n \n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000823", "row_id": 823, "seed_ids": "[4696]" }
0.765221
Code_Contests_823
I
[ "num_paths", "parse_input", "count_paths" ]
3
[ [ "count_paths", "num_paths" ], [ "count_paths", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6217f1b393c01b9b1af9d0bf1418f754304b0506
0af51309c5d86a58db12b34f125ef65eb8a00832
v1.0
instruct
Code_Contests
Code_Contests_845_I
Rita enjoys sequences of integers where each number in the sequence is the sum of its digits multiplied by a given integer k. Your task is to determine whether there exists any sequence of length n such that each number in the sequence (except the first one) follows the described rule. Input The first line contains t...
def sum_of_digits(n): """ Returns the sum of the digits of n. """ return sum(int(digit) for digit in str(n)) def find_sequence(n, k, x): """ Determines if there exists a sequence of length n starting with x where each number is the sum of its digits multiplied by k. If it exists, returns t...
from solution import sequence_exists, find_sequence def test_case_1(): assert find_sequence(4, 3, 5) == [5, 15, 18, 27] def test_case_2(): assert find_sequence(3, 2, 8) == [8, 16, 14] def test_case_3(): assert find_sequence(2, 5, 1) == [1, 5] def test_case_4(): assert find_sequence(5, 1, 9) == [9, 9...
[ { "docstring": "Returns the sum of the digits of n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Determines if there exists a sequence of length n starting with x where each number is the \nsum of its digits m...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of the digits of n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef find_sequence...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000845", "row_id": 845, "seed_ids": "[3176]" }
0.662535
Code_Contests_845
I
[ "sum_of_digits", "find_sequence", "sequence_exists" ]
3
[ [ "find_sequence", "sum_of_digits" ], [ "sequence_exists", "find_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ad00517156116f5893eb319a08de1b92c0d33a54
03d4f565e1315bfa0eda5cd6b8a9b683d2323df6
v1.0
instruct
Code_Contests
Code_Contests_882_I
Lena just started learning math at school and got fascinated by prime numbers. She wants to count how many prime numbers exist between two given numbers, inclusive. However, she doesn't know how to check for prime numbers effectively. Can you help her write a program to solve her problem? Input: The first line contain...
def sieve_of_eratosthenes(n): """ Generate a boolean array prime[0..n] where prime[i] will be True if i is a prime number """ prime = [True] * (n + 1) p = 2 while (p * p <= n): if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p ...
from solution import prime_counts_for_ranges def test_case_1(): test_cases = [(1, 10)] result = prime_counts_for_ranges(test_cases) assert result == [4] def test_case_2(): test_cases = [(11, 20)] result = prime_counts_for_ranges(test_cases) assert result == [4] def test_case_3(): test_cas...
[ { "docstring": "Generate a boolean array prime[0..n] where prime[i] will be True if i is a prime number ", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Count the number of primes between l and r ...
[ 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 count_primes_between(l, r):\n \"\"\"\n Returns the number of prime numbers between l and r, inclusive.\n \"\"\"\n def sieve(n):\n \"...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000882", "row_id": 882, "seed_ids": "[7254]" }
0.623547
Code_Contests_882
I
[ "sieve_of_eratosthenes", "count_primes_between_l_and_r", "prime_counts_for_ranges" ]
3
[ [ "prime_counts_for_ranges", "count_primes_between_l_and_r" ], [ "prime_counts_for_ranges", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
efa4c68675ad8606fbaa9610bff750cff7764f53
898b8f338a25566a20c29eab738fbabddbf45351
v1.0
instruct
Code_Contests
Code_Contests_894_I
In a faraway land, there exists a special type of tree known as a "Magic Binary Search Tree" (MBST). An MBST follows the same properties as a regular Binary Search Tree (BST), but with an additional magical rule: for every node `n` in the tree, the difference between the height of its left and right subtrees should not...
class TreeNode: def __init__(self, key): self.val = key self.left = None self.right = None def insert(root, key): if root is None: return TreeNode(key) if key < root.val: root.left = insert(root.left, key) else: root.right = insert(root.right, key) re...
from solution import build_mbst def test_sample_input(): sequence = [3, 1, 4, 2, 5] expected_output = [1, 2, 3, 4, 5] assert build_mbst(sequence) == expected_output def test_single_node(): sequence = [10] expected_output = [10] assert build_mbst(sequence) == expected_output def test_balanced_...
[]
[ 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, value):\n self.value = value\n self.left = None\n self.right = None\n self.height = 1 ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000894", "row_id": 894, "seed_ids": "[6430]" }
0.552833
Code_Contests_894
I
[ "insert", "height", "get_balance_factor", "right_rotate", "left_rotate", "balance", "inorder_traversal", "build_mbst" ]
8
[ [ "balance", "get_balance_factor" ], [ "balance", "left_rotate" ], [ "balance", "right_rotate" ], [ "build_mbst", "inorder_traversal" ], [ "build_mbst", "insert" ], [ "get_balance_factor", "height" ], [ "insert", "balance" ] ]
7
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
dd5800e752e470783e26844202c96c704f21907a
974163a3974005be8bb712fc8e86ba15c6788164
v1.0
instruct
Code_Contests
Code_Contests_939_I
Consider a town with N houses and M roads connecting these houses. Each road connecting two houses has a certain distance. The town council wants to minimize the distance a mailman has to travel in order to deliver letters to all houses. The mailman starts at any house and it should be possible to attend to all houses ...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rank[rootX] < rank[rootY]: parent[rootX] = rootY elif rank[rootX] > rank[rootY]: parent[rootY] = rootX e...
from solution import minimum_distance_to_travel def test_sample_input(): N, M = 4, 5 roads = [(1, 2, 5), (1, 3, 10), (1, 4, 9), (2, 3, 8), (3, 4, 6)] assert minimum_distance_to_travel(N, M, roads) == 19 def test_single_house(): N, M = 1, 0 roads = [] assert minimum_distance_to_travel(N, M, roa...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef minimum_mailman_distance(N, M, roads):\n graph = {i: [] for i in range(1, N+1)}\n \n for u, v, d in roads:\n graph[u].a...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000939", "row_id": 939, "seed_ids": "[4552]" }
0.761483
Code_Contests_939
I
[ "find", "union", "kruskal", "minimum_distance_to_travel" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_distance_to_travel", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
ec25659b42b46145379e8da4a28cd29a75f8e726
2a1ab8b7177d21268fc016e6ec64d0500d4e9d59
v1.0
instruct
Code_Contests
Code_Contests_958_I
You are given two integers x and y. You need to determine if they can be represented as the sum of two perfect squares. Specifically, if there exist non-negative integers \(a\) and \(b\) such that \(x = a^2 + b^2\) and \(y = c^2 + d^2\) where \(a, b, c,\) and \(d\) are integers. Write a function `check_sums` that take...
import math def is_sum_of_two_squares(n): """ Check if n can be represented as a sum of two perfect squares. """ for a in range(int(math.isqrt(n)) + 1): b = n - a * a if math.isqrt(b) ** 2 == b: return True return False def check_sums(x, y): """ Returns "Yes" if...
from solution import check_sums def test_check_sums_yes(): assert check_sums(5, 10) == "Yes" assert check_sums(0, 0) == "Yes" assert check_sums(1, 4) == "Yes" assert check_sums(2, 50) == "Yes" assert check_sums(9, 25) == "Yes" def test_check_sums_no(): assert check_sums(3, 17) == "No" asse...
[ { "docstring": "Check if n can be represented as a sum of two perfect squares.", "function_declaration": "def is_sum_of_two_squares(n):", "function_name": "is_sum_of_two_squares", "parameter_list": "(n)" }, { "docstring": "Returns \"Yes\" if both x and y can be represented as the sum of two ...
[ 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 check_sum_of_squares(n):\n \"\"\"Helper function to check if an integer can be expressed as the sum of two squares\"\"\"\n for i in range(int(n**...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000958", "row_id": 958, "seed_ids": "[5187]" }
0.700131
Code_Contests_958
I
[ "is_sum_of_two_squares", "check_sums" ]
2
[ [ "check_sums", "is_sum_of_two_squares" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b4fed93d1edf0daf4753f489c60a1b78632fc2b3
3a9443e7c9c461206b7459ca1e883e87a7ee5277
v1.0
instruct
Code_Contests
Code_Contests_976_I
Petya recently started learning algorithms and he was given a task to identify all prime numbers within a given range. As part of this task, he needs to implement an algorithm that finds all prime numbers from a to b (inclusive). A number is prime if it is greater than 1 and has no positive divisors other than 1 and ...
def sieve(n): """ Sieve of Eratosthenes finds all primes up to n """ is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 prime_numbers = [] for p in range(2, n + 1): ...
def test_sieve(): assert sieve(10) == [2, 3, 5, 7] assert sieve(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_find_primes_in_range(): assert find_primes_in_range(2, 10) == [2, 3, 5, 7] assert find_primes_in_range(11, 20) == [11, 13, 17, 19] assert find_primes_in_range(22, 29) == [23, 29] ...
[ { "docstring": "Sieve of Eratosthenes finds all primes up to n", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Finds all prime numbers in the inclusive range [a, b]", "function_declaration": "def find_primes_in_range(a, b):"...
[ 0, 0, 1, 1 ]
2
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 sieve(n):\n \"\"\"Returns a list of prime numbers up to n (inclusive) using the Sieve of Eratosthenes algorithm.\"\"\"\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00000976", "row_id": 976, "seed_ids": "[5343]" }
0.676355
Code_Contests_976
I
[ "sieve", "find_primes_in_range", "display_prime_ranges" ]
3
[ [ "display_prime_ranges", "find_primes_in_range" ], [ "find_primes_in_range", "sieve" ] ]
2
[]
false
[]
false
pytest
false
[]
true
f593cc6cf023b8a51237b0389d1c33071526c075
c94f91c309becd5e8d4c45df67a1660a2d64774f
v1.0
instruct
Code_Contests
Code_Contests_997_I
A large company employs a matrix of binary sensors to monitor various environmental factors in their main server room. The matrix is represented as a 2D grid where each cell contains either a 0 (inactive sensor) or a 1 (active sensor). The company wants to identify the largest rectangular subgrid where every cell conta...
def maximalRectangle(matrix): if not matrix: return 0 m = len(matrix) n = len(matrix[0]) max_area = 0 heights = [0] * n for i in range(m): for j in range(n): if matrix[i][j] == 1: heights[j] += 1 else: heights[j] = 0 ...
def test_maximalRectangle(): matrix1 = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix1) == 6 matrix2 = [ [1], ] assert maximalRectangle(matrix2) == 1 matrix3 = [ [0, 0], [0, 0] ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "paramete...
[ 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 maximalRectangle(matrix):\n if not matrix:\n return 0\n \n max_area = 0\n m, n = len(matrix), len(matrix[0])\n heights = [0] * n\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000997", "row_id": 997, "seed_ids": "[13240]" }
0.746185
Code_Contests_997
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
false
[]
true
77f852f4ec60f367b65ff596a2f8d1a48bb7f83f
6d4b9af81781a8dfeb5099ef1b4eadefec230d39
v1.0
instruct
Code_Contests
Code_Contests_999_I
You are working on a new software system, and one of your responsibilities is to implement the event scheduler. An event can be scheduled on a specific day and has a start time and end time. Your task is to find out if a new event can be added to the schedule without causing any time conflicts with existing events. Ea...
def time_to_minutes(time_str): """ Convert time string in "HH:mm" format to minutes since 00:00. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def can_schedule(day_events, new_event): """ Check if the new event can be scheduled without overlapping existing e...
def test_no_overlapping_events(): assert can_schedule([("09:00", "10:00"), ("11:30", "12:30"), ("14:00", "15:00")], ("12:30", "13:00")) == True def test_overlapping_event_start(): assert can_schedule([("09:00", "10:00"), ("10:00", "11:00"), ("11:00", "12:00")], ("10:30", "11:15")) == False def test_event_same...
[ { "docstring": "Convert time string in \"HH:mm\" format to minutes since 00:00.", "function_declaration": "def time_to_minutes(time_str):", "function_name": "time_to_minutes", "parameter_list": "(time_str)" }, { "docstring": "Check if the new event can be scheduled without overlapping existi...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef time_to_minutes(time: str) -> int:\n \"\"\"\n Converts a time string in \"HH:mm\" format to the number of minut...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000999", "row_id": 999, "seed_ids": "[9724]" }
0.611181
Code_Contests_999
I
[ "time_to_minutes", "can_schedule" ]
2
[ [ "can_schedule", "time_to_minutes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ce2b594b064d7e252cc95d353fc3ab83ef25b2a8
b213adcd9594ce30042125c3a4fd9181a28917bc
v1.0
instruct
Code_Contests
Code_Contests_1090_I
Given an array of integers, find and print all the unique pairs of elements (a, b) such that their sum is equal to a given target value x. Each pair should be printed only once, even if there are multiple ways to form the pair from the array elements. The pair (a, b) and (b, a) are considered the same, and they should ...
def find_pairs(arr, target): """ Returns a list of unique pairs (a, b) such that a + b equals target value. Pairs are returned in ascending order and each pair (a, b) is unique. """ pairs = set() seen = set() for num in arr: complement = target - num if complement in see...
from solution import find_pairs, solve, parse_input def test_find_pairs_normal_case(): assert find_pairs([1, 9, 8, 2, 4, 6], 10) == [(1, 9), (2, 8), (4, 6)] def test_find_pairs_no_pairs(): assert find_pairs([1, 2, 3], 10) == [] def test_find_pairs_with_duplicates(): assert find_pairs([1, 2, 4, 4], 8)...
[ { "docstring": "Returns a list of unique pairs (a, b) such that a + b equals target value.\nPairs are returned in ascending order and each pair (a, b) is unique.", "function_declaration": "def find_pairs(arr, target):", "function_name": "find_pairs", "parameter_list": "(arr, target)" }, { "d...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_unique_pairs(arr, x):\n \"\"\"\n Finds and returns unique pairs (a, b) in the array `arr` such that a + b = x and a <= b.\n Returns list ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001090", "row_id": 1090, "seed_ids": "[3945]" }
0.698349
Code_Contests_1090
I
[ "find_pairs", "solve", "parse_input" ]
3
[ [ "solve", "find_pairs" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
1ebe3bc8c2c8ad71589a08aa6e0de7054a2b2a24
b8d110909e9620397d3125a8fcc9c9b1a4069011
v1.0
instruct
Code_Contests
Code_Contests_1102_I
A rectangular matrix of positive integers is given. Your task is to check if there exists a row or column such that the sum of the elements of that row or column is divisible by a given integer D. Input The first line of input contains three space-separated integers: the number of rows R (1 ≤ R ≤ 10), the number of c...
def check_sum_divisible(matrix, R, C, D): for row in matrix: if sum(row) % D == 0: return "YES" for col in range(C): col_sum = sum(matrix[row][col] for row in range(R)) if col_sum % D == 0: return "YES" return "NO" def matrix_sum_divisible(R, C, D,...
from solution import matrix_sum_divisible def test_matrix_sum_divisible_row(): assert matrix_sum_divisible(3, 3, 4, [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == "YES" def test_matrix_sum_divisible_no(): assert matrix_sum_divisible(2, 3, 10, [ [1, 2, 3], [4, 5, 6] ]) ...
[ { "docstring": null, "function_declaration": "def check_sum_divisible(matrix, R, C, D):", "function_name": "check_sum_divisible", "parameter_list": "(matrix, R, C, D)" }, { "docstring": null, "function_declaration": "def matrix_sum_divisible(R, C, D, matrix):", "function_name": "matr...
[ 0, 0, 0, 0, 0, 1, 0, 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": "def is_divisible_by_d(arr, R, C, D):\n # Check each row\n for row in arr:\n if sum(row) % D == 0:\n return \"YES\"\n \n # Che...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001102", "row_id": 1102, "seed_ids": "[6718]" }
0.648111
Code_Contests_1102
I
[ "check_sum_divisible", "matrix_sum_divisible" ]
2
[ [ "matrix_sum_divisible", "check_sum_divisible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
57a9ea74453b725d9be56fe5029e08e5f1655943
4a37f5319e3b7176f17968485286dff94772d346
v1.0
instruct
Code_Contests
Code_Contests_1166_I
You are given a matrix of size n x n, where each cell contains an integer. Your task is to find the sum of the maximum element in each row. Input format The first line contains one integer n — the size of the matrix. Each of the next n lines contains n integers describing the elements of the matrix. Output format Pr...
def sum_of_max_elements(matrix): """ Returns the sum of the maximum element in each row of the given matrix. Args: matrix (list of list of int): A 2D list representing the matrix. Returns: int: Sum of the maximum elements in each row. """ return sum(max(row) for row in matrix) ...
def test_sum_of_max_elements_example(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert sum_of_max_elements(matrix) == 18 def test_sum_of_max_elements_single_row(): matrix = [ [1, 2, 3, 4, 5] ] assert sum_of_max_elements(matrix) == 5 def test_sum_of_max_elem...
[ { "docstring": "Returns the sum of the maximum element in each row of the given matrix.\n\nArgs:\nmatrix (list of list of int): A 2D list representing the matrix.\n\nReturns:\nint: Sum of the maximum elements in each row.", "function_declaration": "def sum_of_max_elements(matrix):", "function_name": "su...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_in_each_row_sum(matrix):\n \"\"\"\n Given a square matrix, return the sum of the maximum element in each row.\n \"\"\"\n max_elements_s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001166", "row_id": 1166, "seed_ids": "[9439]" }
0.627292
Code_Contests_1166
I
[ "sum_of_max_elements", "get_matrix_and_sum" ]
2
[ [ "get_matrix_and_sum", "sum_of_max_elements" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ab099bc283095f393d4c01e4112b7d922de99c4e
08354b0bef39a8033cff75a6ed0f015542b52f17
v1.0
instruct
Code_Contests
Code_Contests_1195_I
Given a coordinate plane with a directed graph embedded into it, you need to find the shortest path from point A to point B. The graph's edges are defined by a list of line segments on the plane and each segment has a weight representing the cost to traverse that segment. Each edge is represented by two endpoints ((x1...
import heapq from collections import defaultdict import sys def dijkstra(graph, start, end): priority_queue = [(0, start)] distances = {start: 0} while priority_queue: current_distance, current_vertex = heapq.heappop(priority_queue) if current_vertex == end: return...
from solution import find_shortest_path def test_find_shortest_path_case1(): t = 1 test_cases = [ { 'A': (0, 0), 'B': (5, 5), 'edges_count': 3, 'edges': [ (0, 0, 3, 3, 6), (0, 0, 1, 1, 3), (1, 1, 5, 5, 4), ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, end):", "function_name": "dijkstra", "parameter_list": "(graph, start, end)" }, { "docstring": null, "function_declaration": "def find_shortest_path(t, test_cases):", "function_name": "find_shortest_path", "...
[ 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, end):\n \"\"\"\n Find the shortest path in a graph from start to end using Dijkstra's algorithm.\n \"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001195", "row_id": 1195, "seed_ids": "[12628]" }
0.769998
Code_Contests_1195
I
[ "dijkstra", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22722c0a739a0272e3e1f25f1d4c7a4db4e7e043
aca148c770698cdb7a747ba241fd46d2ddf84fca
v1.0
instruct
Code_Contests
Code_Contests_1200_I
You are given an array of integers. You need to answer a series of queries on this array. Each query will ask for the sum of the elements between two specified indices, inclusive. You must process each query efficiently. Constraints * 1≤N≤10^5 - Number of elements in the array. * 1≤Q≤10^5 - Number of queries. * 1≤A[...
def preprocess_prefix_sums(array): """ Preprocess the prefix sums for the given array. """ n = len(array) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i-1] + array[i-1] return prefix_sums def range_sum(prefix_sums, L, R): """ Get the sum...
def test_simple_case(): N = 5 Q = 3 A = [1, 2, 3, 4, 5] queries = [(1, 3), (2, 4), (1, 5)] expected_output = [6, 9, 15] assert solve(N, Q, A, queries) == expected_output def test_single_element_arrays(): N = 1 Q = 1 A = [10] queries = [(1, 1)] expected_output = [10] asse...
[ { "docstring": "Preprocess the prefix sums for the given array.", "function_declaration": "def preprocess_prefix_sums(array):", "function_name": "preprocess_prefix_sums", "parameter_list": "(array)" }, { "docstring": "Get the sum of the subarray from index L to R (1-based).", "function_d...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_prefix_sums(array):\n \"\"\"\n Preprocess the prefix sums for the given array.\n \"\"\"\n n = len(array)\n prefix_sums = [0] ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001200", "row_id": 1200, "seed_ids": "[13102]" }
0.686973
Code_Contests_1200
I
[ "preprocess_prefix_sums", "range_sum", "solve" ]
3
[ [ "solve", "preprocess_prefix_sums" ], [ "solve", "range_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
4aaf61561268c32332a1cc025aa100ab2e804efb
c844757115be25293bf1ef391d256f7fd48e9cd7
v1.0
instruct
Code_Contests
Code_Contests_1204_I
Background Alex is a computer science student who enjoys solving problems using algorithms and data structures. One day, he stumbled upon a new puzzle involving prime numbers and decided to write a program for it. Problem You are given a list of `n` integers. Your task is to find the maximum sum of any sub-sequence ...
def is_prime(num): """Returns True if the number is prime, otherwise False.""" if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def max_prime_subsequence_sum(n, a): """ Returns the maximum sum of any sub-sequen...
from solution import is_prime, max_prime_subsequence_sum def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the maximum sum of any sub-sequence of prime numbers in the list.\nIf there are no prime num...
[ 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 Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001204", "row_id": 1204, "seed_ids": "[510]" }
0.628943
Code_Contests_1204
I
[ "is_prime", "max_prime_subsequence_sum" ]
2
[ [ "max_prime_subsequence_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fd66b6b642d247e6df19638b819c2aa0053a7b4
edf3f173b49b301b375890fa8e2b1dd1fdb5ce65
v1.0
instruct
Code_Contests
Code_Contests_1247_I
You have a garden represented by a grid of size m x n (1 ≤ m, n ≤ 50). Each cell in the grid can either be empty (denoted by '.') or contain a plant (denoted by 'P'). A plant can spread to adjacent cells in the north, south, east, and west directions if the adjacent cell is empty and was not already converted by anothe...
def spread_plants(m, n, garden): from collections import deque # Directions for north, south, east, west directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Queue to perform BFS queue = deque() # Add initial plants' positions to queue for i in range(m): for j in range(n)...
def test_example_cases(): assert garden_simulation(3, 3, ['.P.', '..P', 'P..']) == [ 'PPP', 'PPP', 'PPP' ] assert garden_simulation(4, 4, ['P..P', '.PP.', '..P.', 'P..P']) == [ 'PPPP', 'PPPP', 'PPPP', 'PPPP' ] def test_empty_garden(): ass...
[ { "docstring": null, "function_declaration": "def spread_plants(m, n, garden):", "function_name": "spread_plants", "parameter_list": "(m, n, garden)" }, { "docstring": null, "function_declaration": "def garden_simulation(m, n, grid):", "function_name": "garden_simulation", "param...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def spread_plants(m, n, garden):\n from collections import deque\n \n # Directions for north, south, east, west\n directions = [(-1, 0), (1, 0)...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001247", "row_id": 1247, "seed_ids": "[842]" }
0.60164
Code_Contests_1247
I
[ "spread_plants", "garden_simulation" ]
2
[ [ "garden_simulation", "spread_plants" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6c7c63d911e9978b5734455f1c4a8dd7bf369835
e04a46d4eec4e6bbcde3d23485b73ed06531c077
v1.0
instruct
Code_Contests
Code_Contests_1255_I
Leah has recently become fascinated with prime numbers. She came up with a game involving prime numbers and intervals. Given two integers, L and R, Leah wants to determine the number of prime numbers in the interval [L, R] (both inclusive). For example, if L=10 and R=20, the prime numbers in this interval are 11, 13, ...
def sieve_of_eratosthenes(max_num): """ Helper function to generate a list of primes up to max_num using the Sieve of Eratosthenes. """ is_prime = [True] * (max_num + 1) is_prime[0], is_prime[1] = False, False for start in range(2, int(max_num ** 0.5) + 1): if is_prime[start]: ...
from solution import count_primes_in_interval def test_single_prime(): assert count_primes_in_interval(2, 2) == 1 def test_no_primes(): assert count_primes_in_interval(14, 16) == 0 def test_multiple_primes(): assert count_primes_in_interval(10, 20) == 4 # primes are 11, 13, 17, 19 def test_entirely_pri...
[ { "docstring": "Helper function to generate a list of primes up to max_num using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": "Returns the number of prime ...
[ 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 count_primes_in_interval(L, R):\n \"\"\"\n Returns the number of prime numbers in the interval [L, R] (both inclusive).\n \"\"\"\n def siev...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001255", "row_id": 1255, "seed_ids": "[2665]" }
0.646079
Code_Contests_1255
I
[ "sieve_of_eratosthenes", "count_primes_in_interval" ]
2
[ [ "count_primes_in_interval", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c2dcc4f33addc967892e0639db7372638af5c00b
c08ff373f34d48ea177d86bc5b1f5f4dfe633fe8
v1.0
instruct
Code_Contests
Code_Contests_1298_I
Given a string s and a list of words, find which words from the list can be formed by deleting some characters of the string s without reordering the remaining characters. Input The first line contains the string s (1 ≤ |s| ≤ 105), consisting of lowercase Latin letters. The second line contains an integer n (1 ≤ n ≤...
def can_form(s, word): """ Checks if 'word' can be formed by deleting some characters of 's' without reordering the remaining characters. """ it = iter(s) return all(char in it for char in word) def words_from_string(s, words): """ Finds all words from the list that can be formed by deletin...
from solution import can_form, words_from_string def test_can_form(): assert can_form("abpcplea", "apple") == True assert can_form("abpcplea", "ale") == True assert can_form("abpcplea", "monkey") == False assert can_form("abc", "abc") == True assert can_form("abc", "ac") == True assert can_form...
[ { "docstring": "Checks if 'word' can be formed by deleting some characters of 's' without reordering the remaining characters.", "function_declaration": "def can_form(s, word):", "function_name": "can_form", "parameter_list": "(s, word)" }, { "docstring": "Finds all words from the list that ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_from_string(s, word):\n \"\"\"\n Check if `word` can be formed by deleting some characters of the string `s`\n without reordering the...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001298", "row_id": 1298, "seed_ids": "[6922]" }
0.692412
Code_Contests_1298
I
[ "can_form", "words_from_string", "solution" ]
3
[ [ "solution", "words_from_string" ], [ "words_from_string", "can_form" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b05fae4fe8271e234722dc5982ef575a5f940893
4665a494bffb76b554e265e429973c3a6867ee12
v1.0
instruct
Code_Contests
Code_Contests_1319_I
Write a function that takes a list of integers and returns the sum of all prime numbers in the list. If there are no prime numbers in the list, the function should return 0. Constraints * 1 ≤ len(list) ≤ 100 * -1000 ≤ list elements ≤ 1000 Input A list of integers separated by spaces is given in a line. Output Sum...
def is_prime(n): """ Determines if a number n is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def sum_of_primes(arr): """ Returns the sum of all prime numbers in the list. """ return ...
from solution import sum_of_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(0) == False assert is_prime(1) == False assert is_prime(-5) == False assert is_prime(17) == True def test_sum_of_primes_with_m...
[ { "docstring": "Determines if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the list.", "function_declaration": "def sum_of_primes(arr):", "function_na...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001319", "row_id": 1319, "seed_ids": "[8017]" }
0.668374
Code_Contests_1319
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b2f807867639ead1568dbab5750cf2305f81ba1a
8465cd022db79679437c0325f7c394ba49e0cc66
v1.0
instruct
Code_Contests
Code_Contests_1321_I
You are participating in a treasure hunt game that involves decoding a sequence of numbers. The treasure map is described as an array of N integers. There is a special numeric code that you need to extract from this sequence. The code is the sum of the elements at prime indices in the array. A prime index is an index...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def special_numeric_code(arr):...
from solution import special_numeric_code def test_example_case(): assert special_numeric_code([4, 7, 6, 5, 3]) == 16 def test_small_case(): assert special_numeric_code([1, 2, 3]) == 5 # Prime indices are 2, 3. Elements are 2, 3. Sum is 5 def test_large_values(): assert special_numeric_code([1000000000,...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def special_numeric_code(arr):", "function_name": "special_numeric_code", "parameter_list": "(arr)" } ]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Returns True if n is a prime number; otherwise, returns False \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001321", "row_id": 1321, "seed_ids": "[12983]" }
0.558606
Code_Contests_1321
I
[ "is_prime", "special_numeric_code" ]
2
[ [ "special_numeric_code", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ddc077b15371af99acdb170857cb34e8d5f69a2
5f8b1b33e588b785d44f955b7cae09958d56fe1d
v1.0
instruct
Code_Contests
Code_Contests_1337_I
A city in Byteland wants to establish a new postal service. The city has n neighborhoods and m direct connections between them. Each connection is bidirectional and has a specific distance d. The postal service aims to establish a central post office in one of the neighborhoods such that the maximum distance any resid...
import heapq def dijkstra(n, edges, start): """ Helper function using Dijkstra's algorithm to find the shortest paths from `start` to all other nodes in the graph. """ distances = {node: float('inf') for node in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while ...
def test_find_optimal_post_office_example_1(): n = 4 m = 4 connections = [(1, 2, 1), (2, 3, 1), (3, 4, 1), (4, 1, 1)] result = find_optimal_post_office(n, m, connections) assert result == 2 def test_find_optimal_post_office_example_2(): n = 5 m = 6 connections = [ (1, 2, 2), ...
[ { "docstring": "Helper function using Dijkstra's algorithm to find the shortest paths from `start` to all other nodes in the graph.", "function_declaration": "def dijkstra(n, edges, start):", "function_name": "dijkstra", "parameter_list": "(n, edges, start)" }, { "docstring": "This function ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(graph, start, n):\n dist = [float('inf')] * (n + 1)\n dist[start] = 0\n...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00001337", "row_id": 1337, "seed_ids": "[5900]" }
0.647277
Code_Contests_1337
I
[ "dijkstra", "find_optimal_post_office" ]
2
[ [ "find_optimal_post_office", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
3ca88f294c6d91ddf703b72578581efd42d3a992
52539f055c703406317cd98504a49913a3fbf18f
v1.0
instruct
Code_Contests
Code_Contests_1403_I
Takahashi is organizing a series of workshops. There are N participants who will join. These participants are conveniently numbered from 1 to N. Takahashi wants to schedule M workshops, numbered from 1 to M. Each participant has a preference list of workshops, ranked from most preferred to least preferred. A particip...
def can_all_attend(preferences, N, M, L): workshop_slots = [0] * M for participant_pref in preferences: for workshop in participant_pref: if workshop_slots[workshop - 1] < L: workshop_slots[workshop - 1] += 1 break return sum(workshop_slots) == N def find...
from solution import find_minimum_capacity def test_example_cases(): # Test case 1 N, M = 4, 3 preferences = [ [1, 2, 3], [2, 3, 1], [3, 1, 2], [1, 3, 2] ] assert find_minimum_capacity(N, M, preferences) == 2 # Test case 2 N, M = 3, 2 preferences = [...
[ { "docstring": null, "function_declaration": "def can_all_attend(preferences, N, M, L):", "function_name": "can_all_attend", "parameter_list": "(preferences, N, M, L)" }, { "docstring": null, "function_declaration": "def find_minimum_capacity(N, M, preferences):", "function_name": "f...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def workshop_capacity(N, M, preferences):\n def can_all_attend(L):\n filled = [0] * M\n for i in range(N):\n for workshop in pr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001403", "row_id": 1403, "seed_ids": "[6646]" }
0.663082
Code_Contests_1403
I
[ "can_all_attend", "find_minimum_capacity", "main" ]
3
[ [ "find_minimum_capacity", "can_all_attend" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5c09267b858af6ab1ddf9034cd06f21c8c8355a0
a9cd7a50debda92805725bef4ae7dadc414dd1af
v1.0
instruct
Code_Contests
Code_Contests_1413_I
In a faraway kingdom, there are numerous castles connected by roads. Each road connects exactly two castles and is bidirectional. The king wants to fortify the kingdom by ensuring that there is at least one direct or indirect road connecting every pair of castles. To achieve this, the king needs to determine the minimu...
def count_components(n, roads): parent = list(range(n)) def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent[x] def union(x, y): rootX = find(x) rootY = find(y) if rootX != rootY: parent[rootX] = rootY ...
def test_minimum_additional_roads_basic(): assert minimum_additional_roads(5, 2, [(1, 2), (3, 4)]) == 2 def test_minimum_additional_roads_single_connection(): assert minimum_additional_roads(3, 1, [(1, 2)]) == 1 def test_minimum_additional_roads_all_connected(): assert minimum_additional_roads(4, 4, [(1, ...
[ { "docstring": null, "function_declaration": "def count_components(n, roads):", "function_name": "count_components", "parameter_list": "(n, roads)" }, { "docstring": null, "function_declaration": "def minimum_additional_roads(n, m, roads):", "function_name": "minimum_additional_roads...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_roads_required(N, M, roads):\n \"\"\"\n Determine the minimum number of roads required to make the graph connected.\n \n Parameters:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001413", "row_id": 1413, "seed_ids": "[3113]" }
0.694489
Code_Contests_1413
I
[ "count_components", "minimum_additional_roads" ]
2
[ [ "minimum_additional_roads", "count_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c5b80a2b4b8f8998db3046cb915db849341fbe57
83e01b9182c2af60b4b36b36948b60bc1e22720f
v1.0
instruct
Code_Contests
Code_Contests_1455_I
Given an unsorted array of integers, find the maximum difference between the successive elements in its sorted form. Constraints * All values in input are integers. * 2 ≤ array length ≤ 10^6 * -10^9 ≤ array elements ≤ 10^9 Input Input is given from Standard Input in the following format: n a_1 a_2 a_3 ... a_n Ou...
def maximum_gap(nums): """ Finds the maximum difference between the successive elements in the sorted form of the given array nums. """ if len(nums) < 2: return 0 nums.sort() max_gap = 0 for i in range(1, len(nums)): max_gap = max(max_gap, nums[i] - nums[i - 1]) ...
from solution import maximum_gap def test_max_gap_simple_case(): assert maximum_gap([3, 6, 9, 1]) == 3 def test_max_gap_another_case(): assert maximum_gap([10, 5, 1, 8]) == 4 def test_max_gap_ordered_array(): assert maximum_gap([1, 2, 3, 4, 5, 6]) == 1 def test_max_gap_single_pair(): assert maximum_...
[ { "docstring": "Finds the maximum difference between the successive elements \nin the sorted form of the given array nums.", "function_declaration": "def maximum_gap(nums):", "function_name": "maximum_gap", "parameter_list": "(nums)" }, { "docstring": null, "function_declaration": "def r...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximum_gap(nums):\n if len(nums) < 2:\n return 0\n \n nums.sort()\n \n max_gap = 0\n \n for i in range(1, len(nums)):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00001455", "row_id": 1455, "seed_ids": "[6435]" }
0.713986
Code_Contests_1455
I
[ "maximum_gap", "read_input_and_compute_max_gap" ]
2
[ [ "read_input_and_compute_max_gap", "maximum_gap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c53b4f82df43176c7e64a871338ad20b26f292c0
6938eb9094ea419705838ce1a55080fe9258d114
v1.0
instruct
Code_Contests
Code_Contests_1466_I
Background A transportation network company is implementing a ride-sharing feature. The feature allows passengers to share a ride if their pickup and drop-off locations are within close proximity. The company needs your help to determine the best pairings of rides to maximize passenger satisfaction. Problem Given N ...
import math def can_share_ride(pickup1, dropoff1, pickup2, dropoff2, D): def euclidean_distance(point1, point2): return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) pickup_distance = euclidean_distance(pickup1, pickup2) dropoff_distance = euclidean_distance(dropoff1, dropoff2...
from solution import find_shared_rides def test_example_case_1(): N = 3 D = 5 rides = [ (1, 1, 5, 5), (2, 2, 4, 4), (10, 10, 15, 15) ] assert find_shared_rides(N, D, rides) == [(0, 1)] def test_example_case_2(): N = 4 D = 3 rides = [ (1, 2, 3, 4), ...
[ { "docstring": null, "function_declaration": "def can_share_ride(pickup1, dropoff1, pickup2, dropoff2, D):", "function_name": "can_share_ride", "parameter_list": "(pickup1, dropoff1, pickup2, dropoff2, D)" }, { "docstring": null, "function_declaration": "def find_shared_rides(N, D, rides...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef can_share_ride(pickup1, dropoff1, pickup2, dropoff2, D):\n def euclidean_distance(point1, point2):\n return math.sqrt((point1[...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001466", "row_id": 1466, "seed_ids": "[2492]" }
0.670471
Code_Contests_1466
I
[ "can_share_ride", "find_shared_rides" ]
2
[ [ "find_shared_rides", "can_share_ride" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aab8b6c8bbc82b2bc296144fbf91b3bf4ee1c77
e6e3cb3870d32b9b7ec8c711e416b6114dec3217
v1.0
instruct
Code_Contests
Code_Contests_1482_I
You are given a binary tree. Your task is to find the level order traversal of this tree, but each level should be printed from right to left. Input The input will contain multiple test cases. The first line will have an integer T, the number of test cases. For each test case, the first line will have an integer N, th...
from collections import deque class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(nodes): if not nodes or nodes[0] == -1: return None root = TreeNode(nodes[0]) queue = deque([root]) i = 1 n = len(nodes) ...
from solution import process_test_cases def test_case_1(): test_cases = [ (7, [1, 2, 3, -1, 5, -1, 4]), (3, [10, 20, -1, 30]) ] expected_output = [ [[1], [3, 2], [4, 5]], [[10], [20], [30]] ] assert process_test_cases(test_cases) == expected_output def test_single_n...
[]
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00001482", "row_id": 1482, "seed_ids": "[10727]" }
0.595449
Code_Contests_1482
I
[ "build_tree", "level_order_right_to_left", "process_test_cases" ]
3
[ [ "process_test_cases", "build_tree" ], [ "process_test_cases", "level_order_right_to_left" ] ]
2
[ "process_test_cases" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6d961535bceb45d993ca2a216814f0a8ecfdec35
efb72c1629d0d1af3bcf984a6add0f9a1c029990
v1.0
instruct
Code_Contests
Code_Contests_1486_I
Given a list of strings representing chemical equations, determine if each of the equations is balanced. A balanced equation is one where the number of atoms of each element on the left side (reactants) is equal to the number of atoms of each element on the right side (products). Each equation consists of reactants an...
import re from collections import defaultdict def is_balanced(equation): reactants, products = equation.split('=') reactant_compounds = reactants.split('+') product_compounds = products.split('+') reactant_atoms = count_atoms(reactant_compounds) product_atoms = count_atoms(product_compounds) ...
import pytest from solution import check_balanced_equations def test_single_element(): equations = ["H2+O2=H2O2"] assert check_balanced_equations(equations) == ["YES"] def test_balanced_equation(): equations = ["2H2+O2=2H2O"] assert check_balanced_equations(equations) == ["YES"] def test_multiple_ele...
[ { "docstring": null, "function_declaration": "def is_balanced(equation):", "function_name": "is_balanced", "parameter_list": "(equation)" }, { "docstring": null, "function_declaration": "def count_atoms(compounds):", "function_name": "count_atoms", "parameter_list": "(compounds)"...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "import re\nfrom collections import defaultdict\n\ndef is_balanced(equation):\n reactants, products = equation.split('=')\n r...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001486", "row_id": 1486, "seed_ids": "[3983]" }
0.5858
Code_Contests_1486
I
[ "is_balanced", "count_atoms", "parse_compound", "check_balanced_equations" ]
4
[ [ "check_balanced_equations", "is_balanced" ], [ "count_atoms", "parse_compound" ], [ "is_balanced", "count_atoms" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5d3a95910fea51d961172131626a41bf67117b85
90e9bbb8433f96487e42286ede39229f13fad1a4
v1.0
instruct
Code_Contests
Code_Contests_1527_I
You are given a tree with N nodes and N-1 edges. Each node is labeled with a unique integer from 1 to N. You need to answer Q queries. Each query gives you two nodes u and v, and you need to find the sum of all nodes in the unique path from node u to node v in the tree. The tree is represented as an undirected graph, ...
from collections import defaultdict, deque def build_tree(N, labels, edges): tree = defaultdict(list) node_labels = {i+1: labels[i] for i in range(N)} for u, v in edges: tree[u].append(v) tree[v].append(u) return tree, node_labels def bfs(tree, start, end): parent = {start: None} ...
def test_build_tree(): N = 5 labels = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] tree, node_labels = build_tree(N, labels, edges) assert tree == {1: [2, 3], 2: [1, 4, 5], 3: [1], 4: [2], 5: [2]} assert node_labels == {1: 1, 2: 2, 3: 3, 4: 4, 5: 5} def test_bfs(): tree = {1: [2...
[ { "docstring": null, "function_declaration": "def build_tree(N, labels, edges):", "function_name": "build_tree", "parameter_list": "(N, labels, edges)" }, { "docstring": null, "function_declaration": "def bfs(tree, start, end):", "function_name": "bfs", "parameter_list": "(tree, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef build_tree(N, labels, edges):\n tree = defaultdict(list)\n node_labels = {i+1: labels[i] for i in r...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001527", "row_id": 1527, "seed_ids": "[8542]" }
0.705294
Code_Contests_1527
I
[ "build_tree", "bfs", "path_sum", "solve_tree_queries" ]
4
[ [ "path_sum", "bfs" ], [ "solve_tree_queries", "build_tree" ], [ "solve_tree_queries", "path_sum" ] ]
3
[]
false
[]
false
pytest
false
[]
true
ba946ce33861ba06b55b4edcd8fdfdbbf1467676
a575aa4073f0d1c340c01ae7020a4ea893664790
v1.0
instruct
Code_Contests
Code_Contests_1578_I
A data center is structured like a tree, with servers and connections between them. A tree is a connected acyclic graph. Your task is to determine the largest distance between any two servers in terms of the number of connections, which is known as the diameter of the tree. Input The first line contains an integer n...
from collections import defaultdict, deque def tree_diameter(n, connections): def bfs(start): visited = [-1] * n visited[start] = 0 q = deque([start]) max_distance = (0, start) while q: node = q.popleft() for neighbor in graph[node]: ...
def test_tree_diameter(): assert calculate_diameter(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 3 assert calculate_diameter(4, [(1, 2), (2, 3), (2, 4)]) == 2 assert calculate_diameter(6, [(1, 2), (1, 3), (2, 4), (2, 5), (4, 6)]) == 4 def test_small_tree(): assert calculate_diameter(2, [(1, 2)]) == 1 def t...
[ { "docstring": null, "function_declaration": "def tree_diameter(n, connections):", "function_name": "tree_diameter", "parameter_list": "(n, connections)" }, { "docstring": null, "function_declaration": "def calculate_diameter(n, edges):", "function_name": "calculate_diameter", "p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef tree_diameter(n, connections):\n if n == 1:\n return 0\n\n # Build the graph\n graph = {i: [] for i in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001578", "row_id": 1578, "seed_ids": "[11300]" }
0.6406
Code_Contests_1578
I
[ "tree_diameter", "calculate_diameter" ]
2
[ [ "calculate_diameter", "tree_diameter" ] ]
1
[]
false
[]
false
pytest
false
[]
true
35b33fe50a86e6591abb2ec598f6878082bd1b92
5f779240d370eb9946120db324563b9a17f19cba
v1.0
instruct
Code_Contests
Code_Contests_1594_I
Maria loves playing with numbers. She has an array of integers and she likes to perform the following operations: 1. Select any two integers a and b from the array. 2. Replace one of these integers with their greatest common divisor (GCD). 3. Replace the other integer with their least common multiple (LCM). Maria wan...
import math from functools import reduce def gcd(a, b): """ Returns the greatest common divisor (GCD) of a and b. """ return math.gcd(a, b) def lcm(a, b): """ Returns the least common multiple (LCM) of a and b. """ return a * b // gcd(a, b) def find_min_stability(arr): """ Det...
def test_find_min_stability_single_element(): assert find_min_stability([7]) == 0 def test_find_min_stability_example1(): assert find_min_stability([2, 4, 6, 8]) == 0 def test_find_min_stability_example2(): assert find_min_stability([5, 10, 15, 20, 25]) == 0 def test_find_min_stability_all_same_elements(...
[ { "docstring": "Returns the greatest common divisor (GCD) of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple (LCM) of a and b.", "function_declaration": "def lcm(a, b):", "fun...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef min_difference(arr):\n \"\"\"\n This function takes an array of integers and returns the minimum pos...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001594", "row_id": 1594, "seed_ids": "[9563]" }
0.721552
Code_Contests_1594
I
[ "gcd", "lcm", "find_min_stability" ]
3
[ [ "find_min_stability", "gcd" ], [ "lcm", "gcd" ] ]
2
[]
false
[]
false
pytest
false
[]
true
d11b5ac1cd4832e73d30c92094e428cf1f4f84b2
b03e30a8063a669fa074440e79f52992e6486333
v1.0
instruct
Code_Contests
Code_Contests_1596_I
You are given a grid of characters with n rows and m columns. Each cell contains a lowercase English letter. Your task is to find the length of the longest path of consecutive distinct characters, where you can move to adjacent cells in the grid (up, down, left, or right). A path is a sequence of cells such that each ...
def longest_path(grid): n = len(grid) m = len(grid[0]) def dfs(x, y, visited): max_length = 1 # The starting point itself is countable. visited.add((x, y)) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right for dx, dy in directions: ...
from solution import get_longest_paths, parse_input def test_longest_path_case_1(): input_data = "3\n3 3\nabc\ndef\nghi\n4 4\naabc\ndefg\nhijk\nlmno\n2 2\nab\nba" expected_output = [9, 16, 4] test_cases = parse_input(input_data) assert get_longest_paths(test_cases) == expected_output def test_longest_...
[ { "docstring": null, "function_declaration": "def longest_path(grid):", "function_name": "longest_path", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def get_longest_paths(test_cases):", "function_name": "get_longest_paths", "parameter_list": "(test...
[ 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 longest_distinct_path(grid):\n def dfs(x, y, visited):\n if not (0 <= x < n and 0 <= y < m) or grid[x][y] in visited:\n return len...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00001596", "row_id": 1596, "seed_ids": "[3774]" }
0.759208
Code_Contests_1596
I
[ "longest_path", "get_longest_paths", "parse_input" ]
3
[ [ "get_longest_paths", "longest_path" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
48d3808ec9f064ba77a189d18f7f95bcedf25c03
d8793933a668e7a6382d0d66aa9f73a9da44707c
v1.0
instruct
Code_Contests
Code_Contests_1608_I
Eva loves puzzles and has a special one involving a grid of letters. You are given a grid of size n x m filled with lowercase English letters. Eva wants to find the longest contiguous path in the grid where each letter in the path is in increasing alphabetical order, and each step in the path moves one cell either up, ...
def longest_increasing_path(n, m, grid): def dfs(x, y): if dp[x][y] != -1: return dp[x][y] max_length = 1 for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < n and 0 <= ny < m and ord(grid[nx][ny]) == ord(grid[x][y]) + 1: max_le...
import pytest from solution import solve def test_example1(): input_str = "3 4\nabcd\nbcde\ncdef" assert solve(input_str) == 6 def test_example2(): input_str = "4 4\nabcd\naxby\nazcp\nmnop" assert solve(input_str) == 4 def test_min_case(): input_str = "1 1\na" assert solve(input_str) == 1 de...
[ { "docstring": null, "function_declaration": "def longest_increasing_path(n, m, grid):", "function_name": "longest_increasing_path", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def solve(input_str):", "function_name": "solve", "parameter_list...
[ 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 longest_increasing_path(grid):\n n, m = len(grid), len(grid[0])\n dp = [[-1 for _ in range(m)] for _ in range(n)]\n directions = [(-1, 0), (1,...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00001608", "row_id": 1608, "seed_ids": "[10255]" }
0.711638
Code_Contests_1608
I
[ "longest_increasing_path", "solve" ]
2
[ [ "solve", "longest_increasing_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d36f1d8c1655e02b6b2da0e800df6280174566ed
012b8336e9110693e86cc315e0db8ca8d855fcb2
v1.0
instruct
Code_Contests
Code_Contests_1611_I
You are given a rectangular grid of n rows and m columns. Each cell in the grid either contains a tree or is empty. Your task is to find the largest possible rectangular area consisting of only empty cells. For example, if the grid is: ``` . T . . . . T T T . . . . T T . . . . . ``` Where `.` represents an empty cel...
def maximalRectangleArea(grid): if not grid: return 0 # Transform the grid into a list of lists with 0s and 1s matrix = [[0 if cell == 'T' else 1 for cell in row] for row in grid] n = len(matrix) m = len(matrix[0]) # Initialize the histogram heights heights = [0] * m m...
def test_maximalRectangleArea(): grid = [ ".T...", ".TTT.", "...TT", "....." ] assert maximalRectangleArea(grid) == 6 def test_maximalRectangleArea_single_row(): grid = [ ".T.T." ] assert maximalRectangleArea(grid) == 1 def test_maximalRectangleArea_...
[ { "docstring": null, "function_declaration": "def maximalRectangleArea(grid):", "function_name": "maximalRectangleArea", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def maxHistogramArea(heights):", "function_name": "maxHistogramArea", "parameter_li...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_empty_rectangle_area(grid):\n if not grid or not grid[0]:\n return 0\n\n n, m = len(grid), len(grid[0])\n heights = [0] * m\n ma...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001611", "row_id": 1611, "seed_ids": "[9492]" }
0.625573
Code_Contests_1611
I
[ "maximalRectangleArea", "maxHistogramArea" ]
2
[ [ "maximalRectangleArea", "maxHistogramArea" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f50d7a91f155246e4dfdc8b750b557f2d59a08e9
8f4bd5f9e8a54ecbf997d0adb7ca541d333bc0b7
v1.0
instruct
Code_Contests
Code_Contests_1703_I
Given a binary tree, you need to compute the sum of the values of all left leaves in the tree. A leaf is a node with no children. A left leaf is a leaf that is the left child of its parent node. Input The input consists of multiple test cases. The first line contains an integer `t` (1 ≤ t ≤ 100) — the number of test ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(node_list): if not node_list: return None nodes = {} for value, left, right in node_list: if value not in nodes: n...
from solution import build_tree, sum_of_left_leaves, left_leaves_sum_multiple_cases def test_build_tree(): node_list = [(3, 9, 20), (9, -1, -1), (20, 15, 7), (15, -1, -1), (7, -1, -1)] root = build_tree(node_list) assert root.val == 3 assert root.left.val == 9 assert root.right.val == 20 assert...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001703", "row_id": 1703, "seed_ids": "[6933]" }
0.622275
Code_Contests_1703
I
[ "build_tree", "sum_of_left_leaves", "left_leaves_sum_multiple_cases" ]
3
[ [ "left_leaves_sum_multiple_cases", "build_tree" ], [ "left_leaves_sum_multiple_cases", "sum_of_left_leaves" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e90cd5414b488bfbc7bed0c97c5075a6616387b1
413d953e693fc3d94ab6b12948699ec744c46a91
v1.0
instruct
Code_Contests
Code_Contests_1742_I
You are working on an innovative calculator that can not only handle basic arithmetic operations but also support performing operations on mixed numeral systems (e.g., Roman and Arabic numerals). Your task is to develop a program that interprets a series of mixed numeral operations and returns the result in the specifi...
def roman_to_arabic(roman): roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} total = 0 prev_value = 0 for char in reversed(roman): value = roman_values[char] if value < prev_value: total -= value else: total += value ...
import pytest from solution import roman_to_arabic, arabic_to_roman, mixed_numeral_calculator def test_roman_to_arabic(): assert roman_to_arabic("I") == 1 assert roman_to_arabic("IV") == 4 assert roman_to_arabic("IX") == 9 assert roman_to_arabic("XL") == 40 assert roman_to_arabic("C") == 100 as...
[ { "docstring": null, "function_declaration": "def roman_to_arabic(roman):", "function_name": "roman_to_arabic", "parameter_list": "(roman)" }, { "docstring": null, "function_declaration": "def arabic_to_roman(arabic):", "function_name": "arabic_to_roman", "parameter_list": "(arab...
[ 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 roman_to_arabic(roman):\n roman_values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n arabic = 0\n previous_value = 0\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001742", "row_id": 1742, "seed_ids": "[9673]" }
0.474477
Code_Contests_1742
I
[ "roman_to_arabic", "arabic_to_roman", "mixed_numeral_calculator" ]
3
[ [ "mixed_numeral_calculator", "arabic_to_roman" ], [ "mixed_numeral_calculator", "roman_to_arabic" ] ]
2
[]
false
[]
false
pytest
true
[]
true
214819aac10f835be104031c7f9c7e462183f47f
dcfdd7d87a4774eb5cf395cf7ae108e5e7c3c14b
v1.0
instruct
Code_Contests
Code_Contests_1776_I
A company organizes a contest where participants earn points through various activities. Each participant's total points can be represented as a non-negative integer. The company wants to reward the participants by giving out certificates based on the number of distinct ways the total points can be split into smaller, ...
MOD = 10**9 + 7 def partition_count(n): """ Returns the number of distinct ways to split n into one or more non-negative integers in non-increasing order modulo 10^9 + 7. """ dp = [0] * (n + 1) dp[0] = 1 # There's one way to partition 0 (an empty sum) for i in range(1, n + 1): ...
def test_partition_count_0(): assert distinct_partition_modulo(0) == 1 # Only one way: empty partition def test_partition_count_2(): assert distinct_partition_modulo(2) == 2 # Partitions: [2], [1,1] def test_partition_count_5(): assert distinct_partition_modulo(5) == 7 # Partitions: [5], [4,1], [3,2], ...
[ { "docstring": "Returns the number of distinct ways to split n into one or more non-negative integers \nin non-increasing order modulo 10^9 + 7.", "function_declaration": "def partition_count(n):", "function_name": "partition_count", "parameter_list": "(n)" }, { "docstring": null, "funct...
[ 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": "MOD = 10**9 + 7\n\ndef ways_to_split(k):\n # DP array to store the number of ways to partition each number up to k\n dp = [0] * (k + 1)\n dp[0] = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001776", "row_id": 1776, "seed_ids": "[7966]" }
0.599703
Code_Contests_1776
I
[ "partition_count", "distinct_partition_modulo" ]
2
[ [ "distinct_partition_modulo", "partition_count" ] ]
1
[]
false
[]
false
pytest
false
[]
true
92df6e49b8244158ab8729deb7b2a9256b7047e2
a7021915a4b9fa061f35fce289023b9cb60573cd
v1.0
instruct
Code_Contests
Code_Contests_1825_I
The year is 2030, and humanity has established a colony on Mars. To ensure the smooth functioning of the colony, a group of engineers and scientists have developed an advanced robotic system. This robotic system is responsible for maintaining critical infrastructure such as the air supply, temperature control, and wate...
import math def lcm(a, b): return a * b // math.gcd(a, b) def min_total_check_time(n, k): return lcm(n, k)
from solution import min_total_check_time def test_basic_case(): assert min_total_check_time(5, 3) == 15 def test_equal_n_and_k(): assert min_total_check_time(4, 4) == 4 def test_n_greater_than_k(): assert min_total_check_time(6, 3) == 6 def test_k_greater_than_n(): assert min_total_check_time(3, 7)...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def min_total_check_time(n, k):", "function_name": "min_total_check_time", "parameter_list": "(n, k)" } ]
[ 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 minimum_check_time(n, k):\n \"\"\"\n Calculates the minimum total time required to check all robots once.\n \n Args:\n n (int): Number o...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00001825", "row_id": 1825, "seed_ids": "[6411]" }
0.605245
Code_Contests_1825
I
[ "lcm", "min_total_check_time" ]
2
[ [ "min_total_check_time", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a42530eb03cced6099d644bac0934a01b947f8d8
313bd34d3270315d6bdc67f9b54e194bad3d81da
v1.0
instruct
Code_Contests
Code_Contests_1840_I
You are assigned to organize an inter-college coding competition. There are m colleges participating, each represented by one student, and n coding challenges. A student can be assigned to a challenge only if they have the required skill level for that challenge. Additionally, each challenge must have exactly one stude...
from collections import defaultdict, deque def find_assignment(m, n, skill_levels, requirements): graph = defaultdict(list) for chall in range(n): for student in range(m): if requirements[chall][student] == 1: graph[student].append(chall + m) graph[chall + m]...
from solution import organize_competition def test_case_1(): m, n = 3, 3 skill_levels = [3, 2, 4] requirements = [ [1, 0, 1], [1, 1, 0], [1, 1, 1] ] result = organize_competition(m, n, skill_levels, requirements) assert sorted(result) == [1, 2, 3] # Valid assignment exi...
[ { "docstring": null, "function_declaration": "def find_assignment(m, n, skill_levels, requirements):", "function_name": "find_assignment", "parameter_list": "(m, n, skill_levels, requirements)" }, { "docstring": null, "function_declaration": "def organize_competition(m, n, skill_levels, ...
[ 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 assign_students_to_challenges(m, n, skill_levels, requirements):\n from scipy.optimize import linear_sum_assignment\n import numpy as np\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001840", "row_id": 1840, "seed_ids": "[9905]" }
0.682574
Code_Contests_1840
I
[ "find_assignment", "organize_competition" ]
2
[ [ "organize_competition", "find_assignment" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7160d8a0ddb7f50e19c715a2d7197aabc295f32b
472075194272e5c7bf8a18dd582e48893a9342d7
v1.0
instruct
Code_Contests
Code_Contests_1869_I
### Problem: Compress and Expand String You are working on a compression algorithm to save space in large text files. To achieve this, you decide to implement a basic run-length encoding (RLE) scheme where sequences of the same character are replaced by a single character followed by the count of occurrences. For exam...
import re def compress(text): """ Compresses a text using basic run-length encoding. Parameters: text (str): The input string to be compressed. Returns: str: The compressed string. """ compressed = [] count = 1 for i in range(1, len(text)): if ...
from solution import compress, expand, process_text def test_compress(): assert compress("aaabccccd") == "a3b1c4d1" assert compress("hhhhhhhhhhhh") == "h12" assert compress("abc") == "a1b1c1" assert compress("a") == "a1" def test_expand(): assert expand("a3b1c4d1") == "aaabccccd" assert expand...
[ { "docstring": "Compresses a text using basic run-length encoding.\n\nParameters:\n text (str): The input string to be compressed.\n \nReturns:\n str: The compressed string.", "function_declaration": "def compress(text):", "function_name": "compress", "parameter_list": "(text)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef compress_string(s):\n \"\"\"\n Compresses the given string using run-length encoding.\n \n Parameters:\n s (str): The strin...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001869", "row_id": 1869, "seed_ids": "[7387]" }
0.746531
Code_Contests_1869
I
[ "compress", "expand", "process_text" ]
3
[ [ "process_text", "compress" ], [ "process_text", "expand" ] ]
2
[]
false
[]
false
pytest
true
[]
true
56ea238417d8d3f8ded0686b3d1d6a6e799c6c44
c4804080b2fab317c346f61b3a23e7919571ed57
v1.0
instruct
Code_Contests
Code_Contests_1871_I
Chris is participating in a game show where he has to maximize the value of his bag without exceeding its capacity. He is given a bag with a maximum capacity W and a list of items. Each item is characterized by its weight w and value v. Chris can only take items that will fit in the bag without exceeding the total weig...
def knapsack(max_capacity, weights, values, n): dp = [[0 for x in range(max_capacity + 1)] for x in range(n + 1)] for i in range(n + 1): for w in range(max_capacity + 1): if i == 0 or w == 0: dp[i][w] = 0 elif weights[i-1] <= w: dp[i][w] = max(val...
from solution import main def test_case1(capfd): input_data = '2\n50\n3\n10 60\n20 100\n30 120\n60\n2\n40 100\n50 140\n' expected_output = '220\n140\n' main(input_data) out, _ = capfd.readouterr() assert out == expected_output def test_case2(capfd): input_data = '1\n50\n1\n10 60\n' expecte...
[ { "docstring": null, "function_declaration": "def knapsack(max_capacity, weights, values, n):", "function_name": "knapsack", "parameter_list": "(max_capacity, weights, values, n)" }, { "docstring": null, "function_declaration": "def max_knapsack_value(test_cases):", "function_name": ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def knapsack(W, items):\n \"\"\"\n Determines the maximum total value that can be achieved within the given weight capacity.\n \n Arguments:\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00001871", "row_id": 1871, "seed_ids": "[11218]" }
0.712263
Code_Contests_1871
I
[ "knapsack", "max_knapsack_value", "parse_input", "main" ]
4
[ [ "max_knapsack_value", "knapsack" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
15a27bab9cee7af5799ca07e67501cedf9ad29f8
fc3a7959755b4899221bb2cb1303ab6bccf00fe5
v1.0
instruct
Code_Contests
Code_Contests_1877_I
You are tasked with assembling a scheduler for a series of events happening in different rooms. Each event has a specified start and end time. The goal of the scheduler is to ensure that no two events overlap in the same room and to minimize the number of rooms required. To help you develop the scheduler, assume you w...
def min_rooms_for_events(datasets): results = [] for events in datasets: if not events: continue times = [] for start, end in events: times.append((start, 'start')) times.append((end, 'end')) times.sort() current_rooms = 0 max_...
from solution import scheduler def test_scheduler(): input_data = """3 0 30 5 10 15 20 4 1 10 2 3 5 7 8 9 0""" expected_output = [2, 2] assert scheduler(input_data) == expected_output def test_scheduler_no_overlap(): input_data = """3 0 10 15 20 25 30 0""" expected_output = [1] a...
[ { "docstring": null, "function_declaration": "def min_rooms_for_events(datasets):", "function_name": "min_rooms_for_events", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_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": "import heapq\n\ndef min_meeting_rooms(intervals):\n if not intervals:\n return 0\n \n intervals.sort(key=lambda x: x[0])\n\n heap = []\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001877", "row_id": 1877, "seed_ids": "[9468]" }
0.569588
Code_Contests_1877
I
[ "min_rooms_for_events", "parse_input", "scheduler" ]
3
[ [ "scheduler", "min_rooms_for_events" ], [ "scheduler", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
abcc8efe5074d8ed53d0bacc0802c58098173c53
e92dc3596c68ce49d6738129dcc14d1b86895684
v1.0
instruct
Code_Contests
Code_Contests_1900_I
In an ancient kingdom, there are N cities connected by M bidirectional roads. Each road has a certain length associated with it. The King wants to know the minimum distance required to travel from the capital city (city 1) to all other cities. If a city is not reachable from the capital, the distance should be represen...
import heapq def shortest_paths_from_capital(N, M, roads): graph = {i: [] for i in range(1, N+1)} for road in roads: u, v, w = road graph[u].append((w, v)) graph[v].append((w, u)) distances = {i: float('inf') for i in range(1, N+1)} distances[1] = 0 priority_queue ...
import pytest from solution import shortest_paths_from_capital, minimum_distances_from_input def test_shortest_paths_from_capital_basic(): assert shortest_paths_from_capital(5, 6, [(1, 2, 2), (1, 3, 4), (2, 3, 1), (3, 4, 2), (3, 5, 3), (4, 5, 2)]) == [2, 3, 5, 6] def...
[ { "docstring": null, "function_declaration": "def shortest_paths_from_capital(N, M, roads):", "function_name": "shortest_paths_from_capital", "parameter_list": "(N, M, roads)" }, { "docstring": null, "function_declaration": "def minimum_distances_from_input(input_string):", "function...
[ 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\nimport sys\n\ndef dijkstra(N, M, roads):\n graph = {i: [] for i in range(1, N+1)}\n for u, v, w in roads:\n graph[u].append((w, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001900", "row_id": 1900, "seed_ids": "[10485]" }
0.839373
Code_Contests_1900
I
[ "shortest_paths_from_capital", "minimum_distances_from_input" ]
2
[ [ "minimum_distances_from_input", "shortest_paths_from_capital" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76e5ae73fcde77e2aa2701fba857be27119d92a9
b5b29b33d7434ed04de770ec5cc70d03d95c4eae
v1.0
instruct
Code_Contests
Code_Contests_1908_I
Problem description: An efficient stock tracking system is a crucial feature for modern inventory management. Consider a scenario where you need to keep track of stock levels for different items and update the inventory based on daily transactions. Problem: You will be given an initial list of item names along with th...
def update_stock_levels(test_cases): results = [] for case in test_cases: initial_stock, transactions = case stock_dict = {} for item, quantity in initial_stock: stock_dict[item] = quantity for transaction in transactions: item, transacti...
from solution import process_stock_input def test_case_1(): input_data = "2\n2\napple 50\nbanana 30\n3\napple sold 10\nbanana restocked 20\nbanana sold 5\n1\nmango 100\n2\nmango sold 50\nmango restocked 30\n" expected_output = ["apple 40, banana 45", "mango 80"] assert process_stock_input(input_data) == ex...
[ { "docstring": null, "function_declaration": "def update_stock_levels(test_cases):", "function_name": "update_stock_levels", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def update_stock_levels(test_cases):\n \"\"\"\n Update stock levels based on transactions and return the final stock levels.\n \n Arguments:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001908", "row_id": 1908, "seed_ids": "[3025]" }
0.585818
Code_Contests_1908
I
[ "update_stock_levels", "parse_input", "process_stock_input" ]
3
[ [ "process_stock_input", "parse_input" ], [ "process_stock_input", "update_stock_levels" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
9e4e00468ca2741463f924d27fcbed6ed0cd2159
112bd7c9853335c072570e9df43954fcc6ea76f4
v1.0
instruct
Code_Contests
Code_Contests_1916_I
Given a binary tree, you have to either: * find the height of the tree. * or find the lowest common ancestor (LCA) of two given nodes in the tree. The height of a binary tree is the number of edges on the longest path from the root to a leaf. The lowest common ancestor of two nodes `p` and `q` in a binary tree...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_height(root): if root is None: return -1 else: left_height = find_height(root.left) right_height = find_height(root.right) return 1 + max(left_height, righ...
def test_find_height(): assert find_height(TreeNode(1)) == 0 # Single node tree height def test_lca_basic(): root = TreeNode(1) node2 = TreeNode(2) node3 = TreeNode(3) root.left = node2 root.right = node3 assert lca(root, node2, node3).val == 1 # LCA of 2 and 3 is 1 def test_lca_deeper(): ...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\n\nclass BinaryTree:\n def __in...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001916", "row_id": 1916, "seed_ids": "[5544]" }
0.652431
Code_Contests_1916
I
[ "find_height", "lca", "parse_tree", "find_height_or_lca" ]
4
[ [ "find_height_or_lca", "find_height" ], [ "find_height_or_lca", "lca" ], [ "find_height_or_lca", "parse_tree" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
5ac4934b5daefd7bc4a1cc3d135054e93d972304
c410510cdb565f6d70be3bbc4469573c0842bf49
v1.0
instruct
Code_Contests
Code_Contests_1981_I
Masha has an array of integers a[1 ... n], and she wants to modify it to meet certain conditions. The process involves performing several operations on subarrays. The allowed operation is as follows: * Masha selects two indices i and j (1 ≤ i ≤ j ≤ n) and replaces all elements of the subarray a[i ... j] with a single ...
def is_prime(n): ''' Checks if the given number n is prime. ''' if n <= 1: return False for i in range(2, int(n**0.5)+1): if n % i == 0: return False return True def can_transform_to_primes(arr): ''' Checks if the array can be transformed into an array of pri...
import pytest from solution import is_prime, can_transform_to_primes, process_test_cases 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 def test_can_transform_to_primes(): assert ca...
[ { "docstring": "Checks if the given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Checks if the array can be transformed into an array of prime numbers.", "function_declaration": "def can_transform...
[ 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 a number is a prime number.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00001981", "row_id": 1981, "seed_ids": "[5340]" }
0.645861
Code_Contests_1981
I
[ "is_prime", "can_transform_to_primes", "process_test_cases" ]
3
[ [ "can_transform_to_primes", "is_prime" ], [ "process_test_cases", "can_transform_to_primes" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
ea5bf86ade78f483d925cd9f55ff03dd9781addb
8b13bcab4a80a181e66e1ee041a3f9a22e2c197b
v1.0
instruct
Code_Contests
Code_Contests_2025_I
Martha has just started learning to code, and she is fascinated with prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. She came across a puzzle where she needs to find the largest prime number that is smaller than or equal to a given number M. Given...
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i...
from solution import is_prime, largest_prime_leq, solve_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False assert is_prime(17) == True assert is_prime(19) == True assert i...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the largest prime number less than or equal to M.\nIf no prime number exists, returns -1.", "func...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00002025", "row_id": 2025, "seed_ids": "[8525]" }
0.617638
Code_Contests_2025
I
[ "is_prime", "largest_prime_leq", "solve_primes" ]
3
[ [ "largest_prime_leq", "is_prime" ], [ "solve_primes", "largest_prime_leq" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e54bcb572597c384d0d27724a19238a91a67c6fc
c2f6c824f23dac146dbe3b42b362d212955b8502
v1.0
instruct
Code_Contests
Code_Contests_2048_I
You are organizing a treasure hunt competition at the annual festival. Participants will receive a series of clues which they must solve sequentially. Each clue contains a target number and a range of possible numbers. To get the answer to a clue, participants must find the smallest number in the given range that is no...
def find_answers(n, ranges): previous_answers = set() answers = [] for l, r in ranges: for number in range(l, r + 1): if number not in previous_answers: previous_answers.add(number) answers.append(number) break return answers # Helpe...
from solution import solve_treasure_hunt def test_example_1(): n = 3 ranges = [ (5, 10), (7, 15), (6, 12) ] result = solve_treasure_hunt(n, ranges) assert result == [5, 7, 6] def test_example_2(): n = 4 ranges = [ (1, 5), (2, 6), (3, 7), ...
[ { "docstring": null, "function_declaration": "def find_answers(n, ranges):", "function_name": "find_answers", "parameter_list": "(n, ranges)" }, { "docstring": null, "function_declaration": "def solve_treasure_hunt(n, ranges):", "function_name": "solve_treasure_hunt", "parameter_...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_answers(n, ranges):\n previous_answers = set()\n answers = []\n\n for l, r in ranges:\n for number in range(l, r + 1):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002048", "row_id": 2048, "seed_ids": "[2762]" }
0.570661
Code_Contests_2048
I
[ "find_answers", "solve_treasure_hunt" ]
2
[ [ "solve_treasure_hunt", "find_answers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15706bc3482036c5942fd5bc1c8f443ccaee1d0c
25473226974dd560ebf1c093b159c3e8e9882751
v1.0
instruct
Code_Contests
Code_Contests_2056_I
You are given a circular track with N checkpoints numbered from 1 to N. A group of runners is participating in a race and each runner starts from a different checkpoint. Due to a magical spell, every second, each runner moves forward a unique, pre-determined number of steps. The race organizer wants to know after how m...
import math from functools import reduce def lcm(a, b): """ Helper function to compute the Least Common Multiple (LCM) of two integers. """ return abs(a*b) // math.gcd(a, b) def lcm_multiple(nums): """ Helper function to compute the LCM of a list of integers. """ return reduce(lcm, num...
from solution import minimum_seconds def test_case_1(): T = 2 test_cases = [(3, [2, 3, 2]), (4, [1, 3, 4, 6])] assert minimum_seconds(T, test_cases) == [6, 12] def test_case_2(): T = 1 test_cases = [(5, [1, 2, 3, 4, 5])] assert minimum_seconds(T, test_cases) == [60] def test_case_3(): T =...
[ { "docstring": "Helper function to compute the Least Common Multiple (LCM) of two integers.", "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Helper function to compute the LCM of a list of integers.", "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 math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Helper function to compute the Least Common Multiple (LCM) of two integers.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002056", "row_id": 2056, "seed_ids": "[11356]" }
0.714446
Code_Contests_2056
I
[ "lcm", "lcm_multiple", "minimum_seconds" ]
3
[ [ "lcm_multiple", "lcm" ], [ "minimum_seconds", "lcm_multiple" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cbb981cec2fcb4c61720df854f76ea9d9a36d63b
8691c87936d91cc77e7decace55c2e56e6bb52d3
v1.0
instruct
Code_Contests
Code_Contests_2069_I
Write a function that takes an input of space-separated integers and returns the largest number that can be formed by concatenating those integers together. Input: The first line contains the number of test cases T. The next T lines each contain space-separated integers. Output: For each test case, output the larg...
from functools import cmp_to_key def compare(x, y): return (int(y + x) - int(x + y)) def largest_number(numbers): """ Returns the largest number that can be formed by concatenating the input integers. """ # Convert numbers to string to prepare for concatenation comparisons numbers_str = list(m...
import pytest from solution import largest_number, process_test_cases def test_largest_number(): assert largest_number(['50', '2', '1', '9']) == '95021' assert largest_number(['5', '56', '50']) == '56550' assert largest_number(['1', '34', '3', '98', '9', '76', '45', '4']) == '998764543431' assert large...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest number that can be formed by concatenating the input integers.", "function_declaration": "def largest_number(numbers):", "f...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef compare(x, y):\n return (int(y + x) - int(x + y))\n\ndef largest_number(numbers):\n \"\"\"\n Returns the l...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002069", "row_id": 2069, "seed_ids": "[6837]" }
0.678158
Code_Contests_2069
I
[ "compare", "largest_number", "process_test_cases" ]
3
[ [ "largest_number", "compare" ], [ "process_test_cases", "largest_number" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
0d0589ef9311c810cd67dfbd05e7df696fcfe3cf
2f1000ffb7700006e720743ae609ff74d88aff73
v1.0
instruct
Code_Contests
Code_Contests_2095_I
A company has a task management system where n employees are assigned tasks to complete. Each employee has a particular assigned task denoted by its id t_i. A task i can depend on another task j if and only if task i is strictly greater than task j (t_i > t_j) and the two tasks are not in a dependency conflict. You a...
from collections import defaultdict def count_dependencies(n, k, tasks, conflicts): # Convert task IDs to employee indexing starting from 0 conflicts_set = set() for x, y in conflicts: conflicts_set.add((x - 1, y - 1)) conflicts_set.add((y - 1, x - 1)) result = [0] * n for...
from solution import count_dependencies def test_example_1(): n = 4 k = 2 tasks = [10, 4, 10, 15] conflicts = [(1, 2), (4, 3)] expected = [0, 0, 1, 2] assert count_dependencies(n, k, tasks, conflicts) == expected def test_example_2(): n = 10 k = 4 tasks = [5, 4, 1, 5, 4, 3, 7, 1, 2...
[ { "docstring": null, "function_declaration": "def count_dependencies(n, k, tasks, conflicts):", "function_name": "count_dependencies", "parameter_list": "(n, k, tasks, conflicts)" }, { "docstring": null, "function_declaration": "def solve(n, k, task_ids, conflict_pairs):", "function_...
[ 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 count_dependent_tasks(n, k, task_ids, conflicts):\n from collections import defaultdict\n\n conflicts_set = set((min(x, y) - 1, max(x, y) - 1) fo...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002095", "row_id": 2095, "seed_ids": "[10063]" }
0.644748
Code_Contests_2095
I
[ "count_dependencies", "solve" ]
2
[ [ "solve", "count_dependencies" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f0c38001054d5431e15f4b3ce77ad540b989afeb
78ce1ac9a26819e741006ecd214a0914edace146
v1.0
instruct
Code_Contests
Code_Contests_2126_I
Megan recently found an ancient map that shows a network of mashing pathways where cave treasures are hidden. The map depicts caves connected by pathways, and the caves are numbered from 1 to n. Megan wants to explore the caves and collect treasures. However, she wants to start her journey from a specific cave, visit e...
import itertools def read_input(input_str): lines = input_str.strip().split('\n') n, m = map(int, lines[0].split()) edges = [] for i in range(1, m + 1): u, v, w = map(int, lines[i].split()) edges.append((u, v, w)) s = int(lines[m + 1]) return n, m, edges, s def tsp(n, edges, st...
def test_solve_case_1(): input_str = "4 6\n1 2 10\n1 3 15\n2 3 35\n2 4 25\n3 4 30\n1 4 50\n1" expected = "1 2 4 3" result = solve(input_str) result_set = set(map(int, result.split())) expected_set = set(map(int, expected.split())) assert result_set == expected_set def test_solve_case_2(): i...
[ { "docstring": null, "function_declaration": "def read_input(input_str):", "function_name": "read_input", "parameter_list": "(input_str)" }, { "docstring": null, "function_declaration": "def tsp(n, edges, start):", "function_name": "tsp", "parameter_list": "(n, edges, start)" }...
[ 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 itertools\n\ndef find_shortest_route(n, m, pathways, s):\n # Initializing adjacency matrix with infinity\n adj_matrix = [[float('inf')] * n fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002126", "row_id": 2126, "seed_ids": "[2123]" }
0.668752
Code_Contests_2126
I
[ "read_input", "tsp", "solve" ]
3
[ [ "solve", "read_input" ], [ "solve", "tsp" ] ]
2
[ "read_input" ]
false
[]
false
pytest
false
[]
true
72a36feb4172b166d8ea5cc463f6941377885cbe
0969a9189dabd7a04c6611b79fa6db087453c593
v1.0
instruct
Code_Contests
Code_Contests_2161_I
A programming competition involves solving a puzzle game that uses an NxN grid. In this game, two types of pieces, represented by 1s (treasure) and 0s (empty), are placed on the grid. The objective is to find the largest rectangular area that contains only 1s (treasure). Write a function that, given the NxN grid, com...
def maximalRectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 # create a dp array to store the height of 1's ending at each cell dp = [0] * m for i in range(n): for j in range(m): # update the dp array ...
from solution import largestRectangleArea def test_example_case(): grid = [ [1, 0, 1, 0], [1, 0, 1, 1], [1, 1, 1, 1], [1, 0, 0, 1] ] assert largestRectangleArea(grid) == 4 def test_single_row(): grid = [ [1, 1, 0, 1] ] assert largestRectangleArea(grid) =...
[ { "docstring": null, "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def calculateHistogramArea(heights):", "function_name": "calculateHistogramArea", "para...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack or heights[stack...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00002161", "row_id": 2161, "seed_ids": "[2504]" }
0.670126
Code_Contests_2161
I
[ "maximalRectangle", "calculateHistogramArea", "largestRectangleArea" ]
3
[ [ "largestRectangleArea", "maximalRectangle" ], [ "maximalRectangle", "calculateHistogramArea" ] ]
2
[]
false
[]
false
pytest
true
[]
true
840ed5465fefe557eeefecc7f1d4816191ba214e
55ed0ba91ff6af1d838562cb038406bdbc4c04b6
v1.0
instruct
Code_Contests
Code_Contests_2167_I
You are given an array of N integers. An integer X is said to be a "magic number" if and only if it has a non-zero digit which is repeated consecutively. For example, 233, 858558, and 10011 are magic numbers, while 123, 405, and 8990 are not. Find the total number of "magic numbers" in the given array. Constraints *...
def is_magic_number(n): """ Checks if the number is a magic number. A magic number has a non-zero digit which is repeated consecutively. """ n = abs(n) str_n = str(n) for i in range(1, len(str_n)): if str_n[i] == str_n[i-1] and str_n[i] != '0': return True return Fals...
import pytest from solution import is_magic_number, count_magic_numbers def test_is_magic_number(): assert is_magic_number(233) == True assert is_magic_number(858558) == True assert is_magic_number(123) == False assert is_magic_number(405) == False assert is_magic_number(10011) == True assert i...
[ { "docstring": "Checks if the number is a magic number.\nA magic number has a non-zero digit which is repeated consecutively.", "function_declaration": "def is_magic_number(n):", "function_name": "is_magic_number", "parameter_list": "(n)" }, { "docstring": "Counts the total number of magic n...
[ 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_magic_number(num):\n \"\"\"\n Check if the number is a magic number.\n A magic number has a non-zero digit which appears consecutively.\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002167", "row_id": 2167, "seed_ids": "[2997]" }
0.621161
Code_Contests_2167
I
[ "is_magic_number", "count_magic_numbers" ]
2
[ [ "count_magic_numbers", "is_magic_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ccdbc1e07e7768a5c9bde410703d1def9db470ff
7393c3ebc98042a8031f29b0cd7fa087bc1bc665
v1.0
instruct
Code_Contests
Code_Contests_2181_I
Design a maze generator and solver. **Task**: Write a program that generates a random maze and then solves it using the Depth-First Search (DFS) algorithm. The maze will be represented as a grid. Each cell in the grid can either be a wall or open space. **Input**: The input will consist of two integers, n and m (2 ...
import random def generate_maze(n, m): """ Generates a random maze of dimensions n x m. The maze is represented using '#' for walls and '.' for open spaces. """ # Initialize the maze with walls maze = [['#'] * m for _ in range(n)] # DFS to carve out a random path def carve_passages...
from solution import generate_maze, solve_maze def test_generate_maze_dimensions(): for n in range(2, 6): for m in range(2, 6): maze = generate_maze(n, m) assert len(maze) == n assert all(len(row) == m for row in maze) def test_generate_maze_paths(): maze = generate...
[ { "docstring": "Generates a random maze of dimensions n x m.\nThe maze is represented using '#' for walls and '.' for open spaces.", "function_declaration": "def generate_maze(n, m):", "function_name": "generate_maze", "parameter_list": "(n, m)" }, { "docstring": "Finds a path in the maze fr...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_maze(n, m):\n maze = [['#' for _ in range(m)] for _ in range(n)]\n\n # Create an entrance and exit\n maze[0][0] = '....
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00002181", "row_id": 2181, "seed_ids": "[4221]" }
0.595496
Code_Contests_2181
I
[ "generate_maze", "solve_maze", "print_maze", "generate_and_solve_maze" ]
4
[ [ "generate_and_solve_maze", "generate_maze" ], [ "generate_and_solve_maze", "print_maze" ], [ "generate_and_solve_maze", "solve_maze" ] ]
3
[]
false
[]
false
pytest
true
[]
true
064b9183036b00e32ae1fc8425df9b00b884e88c
058c94cab7fb7fa8546bd5754a321ce11399f938
v1.0
instruct
Code_Contests
Code_Contests_2201_I
In a particular country, a new law mandates that every city must improve their transportation system to reduce traffic congestion. The government has provided a scheme where each city must replace some of their existing two-way roads with high-speed expressways to facilitate this. Each city has a number of two-way road...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] ...
def test_minimum_roads_to_convert(): n = 4 roads = [ [0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4], ] assert minimum_roads_to_convert(n, roads) == 3 def test_minimum_roads_to_convert_with_single_road(): n = 2 roads = [ [0, 1, 5] ] assert minimum_road...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 1 ]
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_roads_to_expressways(n, m, roads):\n import sys\n import itertools\n\n def floyd_warshall(dist):\n for k in range(n):\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002201", "row_id": 2201, "seed_ids": "[7303]" }
0.747889
Code_Contests_2201
I
[ "find", "union", "minimum_roads_to_convert" ]
3
[ [ "minimum_roads_to_convert", "find" ], [ "minimum_roads_to_convert", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
false
[]
true
2f568f9306dc50054e20fbd22c960537cf13cfc6
b15798f52caacb859718fe23855f66fadd88a7e5
v1.0
instruct
Code_Contests
Code_Contests_2232_I
Ana is interested in number series and their properties. She loves exploring the sum of digits in such series. Currently, she is focused on Fibonacci numbers. The Fibonacci sequence is defined as follows: - F(0) = 0 - F(1) = 1 - F(n) = F(n-1) + F(n-2) for n ≥ 2 Ana wants to know the sum of the digits of the N-th Fibo...
def sum_of_digits(n): return sum(int(digit) for digit in str(n)) def nth_fibonacci(n): if n == 1: return 1 elif n == 2: return 1 a, b = 1, 1 for _ in range(3, n + 1): a, b = b, a + b return b def sum_of_digits_in_nth_fibonacci(n): fib_number = nth_fibonacci(n) r...
def test_sum_of_digits(): assert sum_of_digits(123) == 6 assert sum_of_digits(4567) == 22 assert sum_of_digits(0) == 0 assert sum_of_digits(987654321) == 45 def test_nth_fibonacci(): assert nth_fibonacci(1) == 1 assert nth_fibonacci(2) == 1 assert nth_fibonacci(3) == 2 assert nth_fibona...
[ { "docstring": null, "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def nth_fibonacci(n):", "function_name": "nth_fibonacci", "parameter_list": "(n)" }, { "docstri...
[ 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 sum_of_digits_of_fibonacci(n):\n \"\"\"\n Returns the sum of the digits of the N-th Fibonacci number.\n \"\"\"\n if n == 1:\n return...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002232", "row_id": 2232, "seed_ids": "[6736]" }
0.618463
Code_Contests_2232
I
[ "sum_of_digits", "nth_fibonacci", "sum_of_digits_in_nth_fibonacci", "sum_of_digits_of_nth_fibonacci_for_multiple_cases" ]
4
[ [ "sum_of_digits_in_nth_fibonacci", "nth_fibonacci" ], [ "sum_of_digits_in_nth_fibonacci", "sum_of_digits" ], [ "sum_of_digits_of_nth_fibonacci_for_multiple_cases", "sum_of_digits_in_nth_fibonacci" ] ]
3
[]
false
[]
false
pytest
false
[]
true
05893d8113ecdd77c0003d6f319ee95506e67b23
d2d5754b5bccec53f4e1de7d271adde1029b01fc
v1.0
instruct
Code_Contests
Code_Contests_2282_I
The city of Greendale is undergoing a significant renovation project, and several roads are being built in a planned manner. However, due to budget constraints, not all proposed roads can be constructed immediately. Instead, the city council has decided to build as many roads as possible while ensuring that there remai...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif rank[root_x] < ...
import pytest from solution import minimal_total_cost def test_minimal_total_cost_example1(): assert minimal_total_cost(4, 5, [ (1, 2, 1), (1, 3, 4), (2, 3, 6), (2, 4, 5), (3, 4, 3) ]) == 8 def test_minimal_total_cost_example2(): assert minimal_total_cost(3, 3, [ ...
[ { "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 else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00002282", "row_id": 2282, "seed_ids": "[681]" }
0.736458
Code_Contests_2282
I
[ "find", "union", "minimal_total_cost" ]
3
[ [ "minimal_total_cost", "find" ], [ "minimal_total_cost", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8f93051710921cacd7e71068da36387cb061e21f
e88be84ab77b4d5a009f8352733bf54f43dffedd
v1.0
instruct
Code_Contests
Code_Contests_2288_I
M distinct items are placed in a row, and N people are playing a game called "Swap-in-a-row". Initially, each person starts at a unique position in the line where there is an item designated for them and no two people start at the same position. During the game, they are allowed to swap their positions under strict ru...
def factorial_mod(n, mod=1000000007): res = 1 for i in range(2, n + 1): res = (res * i) % mod return res def swap_in_a_row(M, N): return factorial_mod(N)
from solution import swap_in_a_row def test_example_1(): assert swap_in_a_row(3, 2) == 2 def test_example_2(): assert swap_in_a_row(5, 3) == 6 def test_example_3(): assert swap_in_a_row(4, 4) == 24 def test_single_person(): assert swap_in_a_row(1, 1) == 1 def test_all_people_to_max(): assert sw...
[ { "docstring": null, "function_declaration": "def factorial_mod(n, mod=1000000007):", "function_name": "factorial_mod", "parameter_list": "(n, mod=1000000007)" }, { "docstring": null, "function_declaration": "def swap_in_a_row(M, N):", "function_name": "swap_in_a_row", "parameter...
[ 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 factorial_mod(n, mod=1000000007):\n res = 1\n for i in range(2, n + 1):\n res = (res * i) % mod\n return res\n\ndef swap_in_a_row(M, N)...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002288", "row_id": 2288, "seed_ids": "[5184]" }
0.655928
Code_Contests_2288
I
[ "factorial_mod", "swap_in_a_row" ]
2
[ [ "swap_in_a_row", "factorial_mod" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7f170575843837b370ce9d0298fae65948e569a5
090f6e38998c0c5c366b496d24c0a00015647b1f
v1.0
instruct
Code_Contests
Code_Contests_2308_I
Lily is a novice programmer and she is fascinated by palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Lily wants to write a program that, given two integers n and m (1 ≤ n ≤ m ≤ 109), can count how many numbers between n and m (inclusive) are palindromic. Can you...
def is_palindromic(number): """ Check if a number is palindromic. """ str_num = str(number) return str_num == str_num[::-1] def count_palindromic_numbers(n, m): """ Returns the count of palindromic numbers between n and m (inclusive). """ count = 0 for num in range(n, m + 1): ...
from solution import is_palindromic, count_palindromic_numbers def test_is_palindromic(): assert is_palindromic(121) == True assert is_palindromic(123) == False assert is_palindromic(1) == True assert is_palindromic(0) == True assert is_palindromic(11) == True assert is_palindromic(1001) == Tru...
[ { "docstring": "Check if a number is palindromic.", "function_declaration": "def is_palindromic(number):", "function_name": "is_palindromic", "parameter_list": "(number)" }, { "docstring": "Returns the count of palindromic numbers between n and m (inclusive).", "function_declaration": "d...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindromic(number):\n \"\"\"\n Check if a number is palindromic.\n \"\"\"\n str_num = str(number)\n return str_num == str_num[::-1]\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002308", "row_id": 2308, "seed_ids": "[7437]" }
0.711938
Code_Contests_2308
I
[ "is_palindromic", "count_palindromic_numbers", "main" ]
3
[ [ "count_palindromic_numbers", "is_palindromic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
864a652d9201faa83e93bc0b6153427c118c8d2a
e72acdd83eb40d7d4938486515fc8cb9572ececc
v1.0
instruct
Code_Contests
Code_Contests_2336_I
**Alice has been given a new type of encrypted message called a "run-length encoded string." Each run-length encoded string consists of sequences of characters repeated consecutively, and is represented as a sequence of characters followed by their counts. For example, the run-length encoded string "a3b4c2" represents ...
def decode(encoded_str): """ Decodes a run-length encoded string. """ decoded_str = [] i = 0 while i < len(encoded_str): char = encoded_str[i] num = 0 i += 1 while i < len(encoded_str) and encoded_str[i].isdigit(): num = num * 10 + int(encoded_str[i]) ...
def test_decode(): assert decode("a3b4c2") == "aaabbbbcc" assert decode("x2y5z1") == "xxyyyyyz" assert decode("a1b1c1") == "abc" assert decode("a10") == "aaaaaaaaaa" assert decode("z3a2b1c4") == "zzzaabcccc" def test_extract_substring(): assert extract_substring("aaabbbbcc", 1, 3) == "aaa" ...
[ { "docstring": "Decodes a run-length encoded string.", "function_declaration": "def decode(encoded_str):", "function_name": "decode", "parameter_list": "(encoded_str)" }, { "docstring": "Extracts the substring from index l to r (1-indexed) in the expanded string.", "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": "def decode_run_length(s):\n \"\"\"\n Decodes a run-length encoded string into its expanded form.\n \"\"\"\n decoded_str = []\n i = 0\n wh...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002336", "row_id": 2336, "seed_ids": "[1581]" }
0.675524
Code_Contests_2336
I
[ "decode", "extract_substring", "count_character", "process_operations" ]
4
[ [ "process_operations", "count_character" ], [ "process_operations", "decode" ], [ "process_operations", "extract_substring" ] ]
3
[]
false
[]
false
pytest
false
[]
true
90c728a32804841a12243b59e928f73c8f275d4a
25fc1fe226c06df221a2637e5c00e24775c19f11
v1.0
instruct
Code_Contests
Code_Contests_2354_I
You are given an array of integers `arr` of length `n`. Your task is to find another array `result` of length `n` such that for each index `i` in the range [0, n-1], `result[i]` is equal to the minimum value in `arr` after the removal of the element at index `i`. For example, if `arr = [3, 1, 4, 2]`, then: - Removing ...
def find_min_excluding_indices(test_cases): results = [] for arr in test_cases: n = len(arr) result = [] min_left = [float('inf')] * n min_right = [float('inf')] * n # Build the min_left array min_left[0] = arr[0] for i in range(1, n): ...
def test_find_min_excluding_indices(): # Test case 1 input_data = [[3, 1, 4, 2]] expected_output = [[1, 2, 1, 1]] assert find_min_excluding_indices(input_data) == expected_output # Test case 2 input_data = [[2, 7, 3]] expected_output = [[3, 2, 2]] assert find_min_excluding_indices(input...
[ { "docstring": null, "function_declaration": "def find_min_excluding_indices(test_cases):", "function_name": "find_min_excluding_indices", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input_and_output():", "function_name": "process_inp...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_min_excluding_indices(test_cases):\n results = []\n \n for arr in test_cases:\n n = len(arr)\n result = []\n min_lef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002354", "row_id": 2354, "seed_ids": "[1491]" }
0.78306
Code_Contests_2354
I
[ "find_min_excluding_indices", "process_input_and_output" ]
2
[ [ "process_input_and_output", "find_min_excluding_indices" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1b8230d0f72bdcbc3112e75fe1b085976838803f
72fed5141c3927983d3bbe847b90f540010eb9e0
v1.0
instruct
Code_Contests
Code_Contests_2372_I
You are given an array of n integers a_1, a_2, ..., a_n. You can perform the following operation on the array any number of times: - Choose two integers i and j (1 ≤ i < j ≤ n) such that a_i is less than a_j, and then swap a_i and a_j. Your task is to determine the lexicographically smallest permutation of the array ...
def lexicographically_smallest_permutations(test_cases): results = [] for case in test_cases: array = case['array'] sorted_array = sorted(array) results.append(sorted_array) return results def process_input(input_string): input_lines = input_string.strip().split("\n") ...
from solution import smallest_permutations def test_sample_case(): input_string = "3\n5\n3 1 2 5 4\n4\n9 5 3 7\n3\n10 8 2" expected_output = "1 2 3 4 5\n3 5 7 9\n2 8 10" assert smallest_permutations(input_string) == expected_output def test_single_element(): input_string = "2\n1\n1\n1\n1000000000" ...
[ { "docstring": null, "function_declaration": "def lexicographically_smallest_permutations(test_cases):", "function_name": "lexicographically_smallest_permutations", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_string):", "f...
[ 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 smallest_permutation(t, test_cases):\n \"\"\"\n Returns the lexicographically smallest permutation for each test case.\n \n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002372", "row_id": 2372, "seed_ids": "[8140]" }
0.823529
Code_Contests_2372
I
[ "lexicographically_smallest_permutations", "process_input", "format_output", "smallest_permutations" ]
4
[ [ "smallest_permutations", "format_output" ], [ "smallest_permutations", "lexicographically_smallest_permutations" ], [ "smallest_permutations", "process_input" ] ]
3
[ "process_input", "format_output" ]
false
[]
false
pytest
true
[]
true
c74ee5dc244de7c43a25f8e82d895ce4a68f39f4
d8da252a6e53fab8e6d78fca6e4bd1b7e33bb95a
v1.0
instruct
Code_Contests
Code_Contests_2385_I
You are designing a system to manage usernames for a web application. Each username can only contain lowercase and uppercase Latin letters, digits, and special characters. However, to ensure better user readability, the system prohibits registration of usernames if the new username can be considered too similar to an a...
def transform_char(c): """ Transform a character based on the explained rules. """ if c == '1': return ['1', '!'] elif c == '!': return ['!', '1'] elif c == '7': return ['7', '&'] elif c == '&': return ['&', '7'] elif c.isalpha(): return [c.lower()...
import pytest from solution import can_register def test_example_1(): new_username = "coder!name" existing_usernames = ["Coder1name", "codER&name", "CoderName!"] assert can_register(new_username, existing_usernames) == "No" def test_example_2(): new_username = "secure7code" existing_usernames = ["...
[ { "docstring": "Transform a character based on the explained rules.", "function_declaration": "def transform_char(c):", "function_name": "transform_char", "parameter_list": "(c)" }, { "docstring": "Generate all possible transformations of a username.", "function_declaration": "def transf...
[ 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 is_similar(new_username, existing_username):\n sim_map = {'1': '!', '!': '1', '7': '&', '&': '7'}\n \n # Helper function to shift character\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00002385", "row_id": 2385, "seed_ids": "[5273]" }
0.709614
Code_Contests_2385
I
[ "transform_char", "transform_username", "can_register" ]
3
[ [ "can_register", "transform_username" ], [ "transform_username", "transform_char" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bcce1bd42cb8ddbda5ad7a8667bc5cf2578b6a75
c52064012a19e236c00bd93568469c369a2c08c1
v1.0
instruct
Code_Contests
Code_Contests_2412_I
Given a binary tree, implement a function to determine the maximum sum of values for any path within the tree, where the path may start and end at any nodes in the tree. The binary tree is represented as a list where index `0` is the root, and for any node at index `i`, the left child is at index `2i + 1` and the righ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(values): if not values: return None nodes = [TreeNode(val) if val is not None else None for val in values] kids = nodes[::-1] root...
from solution import find_max_path_sums def test_example_1(): assert find_max_path_sums([[1, 2, 3]]) == [6] def test_example_2(): assert find_max_path_sums([[-10, 9, 20, None, None, 15, 7]]) == [42] def test_example_3(): assert find_max_path_sums([[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1]]) =...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\n\nclass TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insertLevel...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002412", "row_id": 2412, "seed_ids": "[10714]" }
0.644637
Code_Contests_2412
I
[ "build_tree", "max_path_sum", "find_max_path_sums" ]
3
[ [ "find_max_path_sums", "build_tree" ], [ "find_max_path_sums", "max_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d1fd3175e55499373720c974a31f20863b29c934
8dfb45f88dde732e1181c26dabcfd546a23efc78
v1.0
instruct
Code_Contests
Code_Contests_2463_I
A company has designed a network of warehouses for effective goods distribution. Each warehouse has a single unique road leading in and out, connecting to other warehouses. The company's goal is to ensure that each warehouse is reachable from any other warehouse through a series of connecting roads. However, sometimes ...
class DisjointSetUnion: def __init__(self, n): self.parent = list(range(n)) self.rank = [1] * n def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): rootX = self.find(x) ...
from solution import warehouse_connectivity def test_case_1(): assert warehouse_connectivity(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)], 3, [(1, 5), (2, 4), (1, 3)]) == ["YES", "YES", "YES"] def test_case_2(): assert warehouse_connectivity(5, 3, [(1, 2), (2, 3), (4, 5)], 2, [(1, 3), (1, 5)]) == ["YES", "NO"] def...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [1] * n\n\n def find(self, x):\n i...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002463", "row_id": 2463, "seed_ids": "[1184]" }
0.687629
Code_Contests_2463
I
[ "process_queries", "warehouse_connectivity" ]
2
[ [ "warehouse_connectivity", "process_queries" ] ]
1
[ "process_queries" ]
false
[ "DisjointSetUnion" ]
true
pytest
true
[]
true
4e4bcfa7c98a69aee3c76db14b899f7fce2399fa
837f0591e1311dc88388aa02819f8fb65a88ba69
v1.0
instruct
Code_Contests
Code_Contests_2469_I
A scientist is conducting an experiment in a rectangular lab grid of size N x M. The scientist wants to place a square observation platform of size k x k in the lab such that the platform covers as many 'O' cells as possible, where 'O' represents an open cell suitable for observation. The cell that isn't 'O' is represe...
def max_observation_cells(grid, k): """ Given a grid with 'O' and 'X', and size of the square observation platform k, returns the maximum number of 'O' cells that can be covered by the platform. """ N = len(grid) M = len(grid[0]) max_count = 0 for i in range(N - k + 1): for j i...
from solution import max_observation_cells def test_example_case(): grid = [ "OOOOX", "OOOOX", "XXOOX", "XOXXO" ] k = 2 assert max_observation_cells(grid, k) == 4 def test_full_open_grid(): grid = [ "OOOOO", "OOOOO", "OOOOO", "OOOOO" ...
[ { "docstring": "Given a grid with 'O' and 'X', and size of the square observation platform k,\nreturns the maximum number of 'O' cells that can be covered by the platform.", "function_declaration": "def max_observation_cells(grid, k):", "function_name": "max_observation_cells", "parameter_list": "(g...
[ 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 max_observation_cells(grid, k):\n \"\"\"\n Given a grid with 'O' and 'X', and size of the square observation platform k,\n returns the maximum...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002469", "row_id": 2469, "seed_ids": "[5910]" }
0.670912
Code_Contests_2469
I
[ "max_observation_cells", "read_and_solve" ]
2
[ [ "read_and_solve", "max_observation_cells" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b2befa991c9df1a68926aa9b9b72ceede2215de
ef86ed02a33390926d0fd73737ca8d4a5b931cc7
v1.0
instruct
Code_Contests
Code_Contests_2548_I
Palindrome Partitioning Problem Statement Given a string s, partition it into substrings such that each substring is a palindrome. Return all possible palindrome partitioning of s. For example, given the string "aab", you may return: [ ["a","a","b"], ["aa","b"] ] Your task is to implement a function which will...
def is_palindrome(s): return s == s[::-1] def partition(s): def dfs(start, path): if start == len(s): result.append(path[:]) return for end in range(start + 1, len(s) + 1): if is_palindrome(s[start:end]): dfs(end, path + [s[start:end]]) ...
from solution import partition def test_partition_simple_case(): assert partition("aab") == [["a", "a", "b"], ["aa", "b"]] def test_partition_single_character(): assert partition("a") == [["a"]] def test_partition_two_characters(): assert partition("ab") == [["a", "b"]] assert partition("aa") == [["a...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def partition(s):", "function_name": "partition", "parameter_list": "(s)" }, { "docstring": nul...
[ 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_palindrome(s):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef partition(s)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00002548", "row_id": 2548, "seed_ids": "[5935]" }
0.7361
Code_Contests_2548
I
[ "is_palindrome", "partition" ]
2
[ [ "partition", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c867e6a027b587377abf9875ac90f38ceb539c8d
87b4b70e4522f85c7deab77619b5ac1090702242
v1.0
instruct
Code_Contests
Code_Contests_2569_I
Our company's warehouse system consists of a grid of cells, with each cell representing a section that can store items. Some sections are blocked and cannot hold any items nor can they be part of a path. The objective is to move items from the entrance of the warehouse to the exit by finding the shortest possible path,...
from collections import deque def shortest_path(warehouse, entrance, exit, blocked_sections): M, N = warehouse (Ex, Ey) = entrance (Dx, Dy) = exit # Initialize grid and mark blocked sections grid = [[0] * N for _ in range(M)] for bx, by in blocked_sections: grid[bx][by] = -1 # Mov...
def test_shortest_path(): # Example test case assert find_shortest_path(5, 7, 0, 0, 4, 6, 3, [(1, 2), (2, 3), (3, 4)]) == 10, "Test case 1 failed" # Test case with no blocked sections assert find_shortest_path(5, 7, 0, 0, 4, 6, 0, []) == 10, "Test case 2 failed" # Test case with entrance =...
[ { "docstring": null, "function_declaration": "def shortest_path(warehouse, entrance, exit, blocked_sections):", "function_name": "shortest_path", "parameter_list": "(warehouse, entrance, exit, blocked_sections)" }, { "docstring": null, "function_declaration": "def find_shortest_path(M, N...
[ 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 shortest_path(grid_size, entrance, exit, blocked_cells):\n M, N = grid_size\n Ex, Ey = entrance\n Dx, Dy = ex...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002569", "row_id": 2569, "seed_ids": "[8093]" }
0.685952
Code_Contests_2569
I
[ "shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
4ca4884f54e4f9a43ad8eeb26cc57caa6e8c48c6
f6bca2201c75609685a185c904929f5bc5b1de6d
v1.0
instruct
Code_Contests
Code_Contests_2588_I
In a magical land, there are n towns connected by m bidirectional roads. Each road has a certain travel distance associated with it. Some of these roads, unfortunately, have been enchanted by a mischievous sorcerer, causing each road's distance to oscillate by a given factor. You have a special map that shows the minim...
import heapq def dijkstra(n, graph, is_min): distances = [float('inf')] * (n + 1) distances[1] = 0 pq = [(0, 1)] # (distance, node) while pq: current_distance, u = heapq.heappop(pq) if current_distance > distances[u]: continue for v, min_d, ma...
import pytest from solution import process_input_and_solve def test_example_1(): n = 4 m = 4 roads = [ (1, 2, 3, 5), (2, 3, 2, 4), (3, 4, 1, 3), (1, 4, 10, 12) ] assert process_input_and_solve(n, m, roads) == (6, 12) def test_example_2(): n = 5 m = 5 roa...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, is_min):", "function_name": "dijkstra", "parameter_list": "(n, graph, is_min)" }, { "docstring": null, "function_declaration": "def shortest_and_longest_path(n, m, roads):", "function_name": "shortest_and_longest_pa...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra(graph, start, n, is_min):\n # Set initial distances to infinity\n distances = [sys.maxsize] * (n + 1)\n d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002588", "row_id": 2588, "seed_ids": "[12099]" }
0.777903
Code_Contests_2588
I
[ "dijkstra", "shortest_and_longest_path", "process_input_and_solve" ]
3
[ [ "process_input_and_solve", "shortest_and_longest_path" ], [ "shortest_and_longest_path", "dijkstra" ] ]
2
[]
false
[]
false
pytest
true
[]
true
49f462a5c008687813fb601b7f9a1a0558786c61
c7e8ab33854f9a1af6da2139e7d7d1bb64c2c771
v1.0
instruct
Code_Contests
Code_Contests_2592_I
You are given a weighted undirected graph with N vertices and M edges. Each edge has a weight W, and you need to find the number of ways to add a minimum number of edges to make the graph connected. In other words, you need to find how many different sets of edges can be added to make a connected graph with the given v...
from collections import defaultdict def find_connected_components(adj_list, N): visited = [False] * N components = 0 def dfs(node): stack = [node] while stack: v = stack.pop() for neighbor in adj_list[v]: if not visited[neighbor]: ...
from solution import min_edges_to_connect_graph def test_min_edges_to_connect_graph(): assert min_edges_to_connect_graph(4, 2, [(1, 2, 1), (3, 4, 1)]) == 1 assert min_edges_to_connect_graph(3, 0, []) == 2 assert min_edges_to_connect_graph(6, 2, [(1, 2, 1), (3, 4, 1)]) == 3 assert min_edges_to_connect_g...
[ { "docstring": null, "function_declaration": "def find_connected_components(adj_list, N):", "function_name": "find_connected_components", "parameter_list": "(adj_list, N)" }, { "docstring": null, "function_declaration": "def min_edges_to_connect_graph(N, M, edges):", "function_name":...
[ 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 collections import defaultdict\n\ndef find_connected_components(adj_list, N):\n visited = [False] * N\n components = 0\n \n def dfs(node):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002592", "row_id": 2592, "seed_ids": "[11742]" }
0.792886
Code_Contests_2592
I
[ "find_connected_components", "min_edges_to_connect_graph", "main" ]
3
[ [ "min_edges_to_connect_graph", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d2d0fc2086c2452368efc438adc17cb1c5932ad
4f744b39c6856c0ef737153a45434f0e3d875dd4
v1.0
instruct
Code_Contests
Code_Contests_2594_I
Write a function to find the smallest positive integer that is not a subsequence of a given input string. For instance, for the string "0123456789" the output should be "10" because all numbers from 0 to 9 are present and "10" is the smallest number that is not a subsequence of it. Input The first line contains the ...
def is_subsequence(s, num): it = iter(s) return all(char in it for char in num) def smallest_missing_integer(input_str): i = 1 while True: if not is_subsequence(input_str, str(i)): return str(i) i += 1 def process_test_cases(test_cases): return [smallest_missing_integer...
from solution import find_smallest_missing_positive_integer def test_single_case_all_digits(): assert find_smallest_missing_positive_integer(1, ["0123456789"]) == ["10"] def test_single_case_repeated_digits(): assert find_smallest_missing_positive_integer(1, ["111"]) == ["2"] def test_single_case_mixed_digit...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, num):", "function_name": "is_subsequence", "parameter_list": "(s, num)" }, { "docstring": null, "function_declaration": "def smallest_missing_integer(input_str):", "function_name": "smallest_missing_integer", "pa...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def smallest_missing_subsequence(T, test_cases):\n def is_subsequence(s, subseq):\n it = iter(s)\n return all(char in it for char in subse...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002594", "row_id": 2594, "seed_ids": "[625]" }
0.683754
Code_Contests_2594
I
[ "is_subsequence", "smallest_missing_integer", "process_test_cases", "find_smallest_missing_positive_integer" ]
4
[ [ "find_smallest_missing_positive_integer", "process_test_cases" ], [ "process_test_cases", "smallest_missing_integer" ], [ "smallest_missing_integer", "is_subsequence" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
072804c7e7de6581feab11500215defd14b1f61f
447d90675246a2283189391eca919dde6d510a6a
v1.0
instruct
Code_Contests
Code_Contests_2596_I
You are given two strings S1 and S2. Define the following operations: a. concatenate(S1, S2) denotes the string obtained by concatenating S2 to the end of S1. E.g., concatenate("abc", "def") = "abcdef" b. swap(S, i, j) denotes the string obtained by swapping the characters at indices i and j in the string S. E.g., sw...
def swap(S, i, j): S = list(S) S[i], S[j] = S[j], S[i] return "".join(S) def rotate_left(S, k): return S[k:] + S[:k] def min_operations_to_transform(S1, S2): if len(S1) != len(S2): return -1 from collections import Counter if Counter(S1) != Counter(S2): return -1 def ...
from solution import min_operations_to_transform def test_min_operations_to_transform_case1(): assert min_operations_to_transform("abcd", "acbd") == 1 def test_min_operations_to_transform_case2(): assert min_operations_to_transform("abcd", "abcd") == 0 def test_min_operations_to_transform_case3(): assert...
[ { "docstring": null, "function_declaration": "def swap(S, i, j):", "function_name": "swap", "parameter_list": "(S, i, j)" }, { "docstring": null, "function_declaration": "def rotate_left(S, k):", "function_name": "rotate_left", "parameter_list": "(S, k)" }, { "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 minimal_operations(S1, S2):\n if len(S1) != len(S2):\n return -1\n \n from collections import Counter\n \n if Counter(S1) != Coun...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002596", "row_id": 2596, "seed_ids": "[386]" }
0.75393
Code_Contests_2596
I
[ "swap", "rotate_left", "min_operations_to_transform" ]
3
[ [ "min_operations_to_transform", "swap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d701aba6cbb0cb2f52ac6b6c6ad7ed70553bb86a
45c0273bbbe5789207a04e1beb22f6b187a6df83
v1.0
instruct
Code_Contests
Code_Contests_2641_I
Write a program that calculates the longest increasing subsequence of a given sequence of integers. Input The input consists of several datasets. Each dataset consists of: The length of the sequence. The sequence of integers. The input ends with a line consisting of a single 0. Output For each dataset, print the ...
def lis_length(sequence): """ Returns the length of the longest increasing subsequence in sequence. """ if not sequence: return 0 n = len(sequence) lis = [1] * n for i in range(1, n): for j in range(0, i): if sequence[i] > sequence[j]: lis[i]...
from solution import lis_length, parse_input, longest_increasing_subsequence def test_lis_length(): assert lis_length([10, 22, 9, 33, 21, 50]) == 4 assert lis_length([3, 10, 2, 1, 20]) == 3 assert lis_length([]) == 0 assert lis_length([1, 2, 3, 4, 5]) == 5 assert lis_length([9, 8, 7, 6, 5]) == 1 d...
[ { "docstring": "Returns the length of the longest increasing subsequence in sequence.", "function_declaration": "def lis_length(sequence):", "function_name": "lis_length", "parameter_list": "(sequence)" }, { "docstring": "Parses the input data and returns the list of sequences to be processe...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_increasing_subsequence(arr):\n \"\"\"\n Returns the length of the longest increasing subsequence in the array arr.\n \"\"\"\n if no...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002641", "row_id": 2641, "seed_ids": "[11439]" }
0.771592
Code_Contests_2641
I
[ "lis_length", "parse_input", "longest_increasing_subsequence" ]
3
[ [ "longest_increasing_subsequence", "lis_length" ], [ "longest_increasing_subsequence", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
56457848669b0e66701c0dfefb974be2503ac0b9
80f2c1fce5a6fea36ad070daa8e2567160568b01
v1.0
instruct
Code_Contests
Code_Contests_2652_I
Problem Statement: Sarah has a list of items she needs to buy. Each item has a specific price, and she can only afford to spend up to a certain amount of money. She wants to maximize the number of items she can buy without exceeding her budget. Your task is to help Sarah determine the maximum number of items she can ...
def max_items_within_budget(budget, prices): prices.sort() count = 0 total = 0 for price in prices: if total + price <= budget: total += price count += 1 else: break return count def solve_max_items(test_cases): results = [] for budget, n,...
from solution import max_items_within_budget, solve_max_items, parse_input, format_output def test_max_items_simple_case(): assert max_items_within_budget(50, [10, 20, 30, 40, 50]) == 2 def test_max_items_within_budget(): assert max_items_within_budget(75, [10, 20, 30, 40, 50]) == 3 assert max_items_withi...
[ { "docstring": null, "function_declaration": "def max_items_within_budget(budget, prices):", "function_name": "max_items_within_budget", "parameter_list": "(budget, prices)" }, { "docstring": null, "function_declaration": "def solve_max_items(test_cases):", "function_name": "solve_ma...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_items_within_budget(T, test_cases):\n results = []\n\n for case in test_cases:\n budget, num_items, prices = case\n prices.sort...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00002652", "row_id": 2652, "seed_ids": "[12988]" }
0.757293
Code_Contests_2652
I
[ "max_items_within_budget", "solve_max_items", "parse_input", "format_output" ]
4
[ [ "solve_max_items", "max_items_within_budget" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
16729656f70a7f6b20e478099fd82de351c73987
f2d690126e1acb2dbd8f1e415d481ab4fda54f2b
v1.0
instruct
Code_Contests
Code_Contests_2688_I
A transportation company is managing a fleet of vehicles. Each vehicle can transfer goods between two points. Each vehicle has a capacity limit, and cannot carry an amount of goods that exceeds this limit. The company needs to determine if it is possible to fulfill a given list of shipping orders using their fleet of v...
def can_fulfill_orders(vehicle_capacities, orders): max_capacity = max(vehicle_capacities) for order in orders: if order > max_capacity: return "NO" return "YES" def transportation_company(input_data): lines = input_data.strip().split('\n') V = int(lines[0]) vehicle_capaciti...
def test_transportation_company(): input_data1 = """3 100 200 150 4 90 110 130 160""" output1 = "YES" assert transportation_company(input_da...
[ { "docstring": null, "function_declaration": "def can_fulfill_orders(vehicle_capacities, orders):", "function_name": "can_fulfill_orders", "parameter_list": "(vehicle_capacities, orders)" }, { "docstring": null, "function_declaration": "def transportation_company(input_data):", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_fulfill_orders(vehicle_capacities, shipping_orders):\n max_capacity = max(vehicle_capacities)\n\n for order in shipping_orders:\n if o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002688", "row_id": 2688, "seed_ids": "[12898]" }
0.675523
Code_Contests_2688
I
[ "can_fulfill_orders", "transportation_company" ]
2
[ [ "transportation_company", "can_fulfill_orders" ] ]
1
[]
false
[]
false
pytest
false
[]
true
703733ea1afbd581e9d594def06390e440119642
045d7863d3d14ad458027763fdd0c08c7b17ea79
v1.0
instruct
Code_Contests
Code_Contests_2743_I
Given an undirected weighted graph with `n` nodes and `m` edges, your task is to determine the weight of the minimum spanning tree of the graph. Input The first line contains two integers `n` (1 ≤ n ≤ 10^5) and `m` (1 ≤ m ≤ 2 * 10^5), representing the number of nodes and the number of edges, respectively. The next `...
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...
def test_example_1(): n = 4 m = 5 edge_list = '1 2 3\n1 3 1\n2 3 3\n3 4 6\n2 4 5' assert minimum_spanning_tree(n, m, edge_list) == 9 def test_example_2(): n = 3 m = 1 edge_list = '1 2 4' assert minimum_spanning_tree(n, m, edge_list) == -1 def test_single_node(): n = 1 m = 0 ...
[ { "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 DSU:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, a):\n if self.parent...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002743", "row_id": 2743, "seed_ids": "[5464]" }
0.849348
Code_Contests_2743
I
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
776a60b0b52cfd176fbf194c6a6007dbd1d0caeb
d731e4ecffbd9b8e09406289a9db2fe5b06cd722
v1.0
instruct
Code_Contests
Code_Contests_2773_I
You are provided with a 2D grid of dimension `n * m` where `1 <= n, m <= 1000`. The grid is initially filled with zeros. You need to perform a series of `Q` operations of the following two types: - `1 x y v`: Update the cell at position `(x, y)` (1-indexed) by adding the value `v` (`1 <= x <= n, 1 <= y <= m, -1000 <= ...
def update_grid(grid, x, y, v): """ Update the grid at position (x, y) by adding value v. """ grid[x-1][y-1] += v def sum_rectangle(grid, x1, y1, x2, y2): """ Calculate the sum of the rectangle defined by (x1, y1) as top-left and (x2, y2) as bottom-right. """ sum_val = 0 for i in ra...
def test_update_and_sum(): Q = 5 operations = ["1 1 2 5", "1 3 4 -3", "2 1 1 3 4", "1 2 2 2", "2 2 2 3 4"] assert process_operations(Q, operations) == [2, -1] def test_single_update(): Q = 1 operations = ["1 1 1 100"] result = process_operations(Q, operations) assert result == [] def test_...
[ { "docstring": "Update the grid at position (x, y) by adding value v.", "function_declaration": "def update_grid(grid, x, y, v):", "function_name": "update_grid", "parameter_list": "(grid, x, y, v)" }, { "docstring": "Calculate the sum of the rectangle defined by (x1, y1) as top-left and (x2...
[ 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 process_operations(n, m, operations):\n grid = [[0] * m for _ in range(n)]\n results = []\n \n def update(x, y, v):\n grid[x-1][y-1]...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002773", "row_id": 2773, "seed_ids": "[2358]" }
0.6723
Code_Contests_2773
I
[ "update_grid", "sum_rectangle", "process_operations" ]
3
[ [ "process_operations", "sum_rectangle" ], [ "process_operations", "update_grid" ] ]
2
[]
false
[]
false
pytest
false
[]
true
77b7709eae30caee0b8bbb29acd184799082d7a1
85758dbad3b06246465e05d52368f334876e035b
v1.0
instruct
Code_Contests
Code_Contests_2895_I
In a faraway kingdom, there exists a magical garden divided into an M x M grid. Each cell in the grid represents a plot of land that can grow magical flowers. The king of this kingdom wants to arrange his garden in such a way that the flowers form a symmetrical pattern. Specifically, each row and each column must conta...
import itertools def count_distinct_arrangements(m): def is_valid(permutation): return len(set(permutation)) == len(permutation) count = 0 for perm in itertools.permutations(range(m)): if is_valid(perm): count += 1 return count def count_solution(m): retur...
from solution import count_solution def test_count_solution_m_1(): assert count_solution(1) == 1 def test_count_solution_m_2(): assert count_solution(2) == 2 def test_count_solution_m_3(): assert count_solution(3) == 6 def test_count_solution_m_4(): assert count_solution(4) == 24 def test_count_sol...
[ { "docstring": null, "function_declaration": "def count_distinct_arrangements(m):", "function_name": "count_distinct_arrangements", "parameter_list": "(m)" }, { "docstring": null, "function_declaration": "def count_solution(m):", "function_name": "count_solution", "parameter_list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef count_distinct_flower_arrangements(m):\n \"\"\"\n Counts the number of distinct ways to arrange flowers in ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00002895", "row_id": 2895, "seed_ids": "[11442]" }
0.575296
Code_Contests_2895
I
[ "count_distinct_arrangements", "count_solution" ]
2
[ [ "count_solution", "count_distinct_arrangements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fed58f9cd739e237ad290fa84f6925b490d422c7
b11bd11685d8c34c7a5677e7a505178545c00889
v1.0
instruct
Code_Contests
Code_Contests_2927_I
Your friend is developing a text-based adventure game, and he needs your help to handle certain in-game mechanics. One important feature he needs is a way to process player commands and evaluate expressions involving in-game variables which represent different attributes such as health (`h`), stamina (`s`), magic point...
import re def evaluate_expression(expression, variables, operators): def apply_operator(op, left, right): try: if op == '+': return left + right elif op == '-': return left - right elif op == '*': return left * right ...
from solution import process_in_game_mechanics def test_dataset1_all_error(): input_data = """1 5 + L 1 - L 1 * L 2 / L 2 ^ R 3 4 a+b*c d-e^f g+h-i*j/k m^n^o""" expected_output = "ERROR\nERROR\nERROR\nERROR" assert process_in_game_mechanics(input_data) == expected_output def test_dataset2_all_error(): ...
[ { "docstring": null, "function_declaration": "def evaluate_expression(expression, variables, operators):", "function_name": "evaluate_expression", "parameter_list": "(expression, variables, operators)" }, { "docstring": null, "function_declaration": "def evaluate_dataset(O, operators, E,...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import operator\nimport re\n\ndef calculate_expression(operators, expressions):\n results = []\n for expr in expressions:\n try:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002927", "row_id": 2927, "seed_ids": "[12695]" }
0.472943
Code_Contests_2927
I
[ "evaluate_expression", "evaluate_dataset", "parse_input", "process_in_game_mechanics" ]
4
[ [ "evaluate_dataset", "evaluate_expression" ], [ "process_in_game_mechanics", "evaluate_dataset" ], [ "process_in_game_mechanics", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
18440efe31c17358223903d00ef03d0284784258
2f73ed07312e2bc465d9310304d7e035a39fc55f
v1.0
instruct
Code_Contests
Code_Contests_2977_I
A company wants to build a system to manage project dependencies. Each project depends on one or more other projects, and to start a project, all its dependencies must be completed first. Every project has a unique identifier, which is an integer from 1 to N. You are tasked to write a program to produce a valid order ...
def find_project_order(N, dependencies): from collections import defaultdict, deque # Build graph and in-degree counter graph = defaultdict(list) in_degree = [0] * (N + 1) for project in range(1, N + 1): deps = dependencies[project - 1] for dep in deps: graph[de...
from solution import solution def test_example_1(): input_str = "5\n0\n1 1\n1 2\n2 1 2\n0\n" output_str = solution(input_str) assert output_str in {"1 2 3 4 5", "1 2 4 3 5", "1 5 2 3 4", "1 5 2 4 3"} # Valid orders def test_example_2(): input_str = "4\n1 2\n1 3\n1 4\n1 2\n" output_str = solution(...
[ { "docstring": null, "function_declaration": "def find_project_order(N, dependencies):", "function_name": "find_project_order", "parameter_list": "(N, dependencies)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "pa...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_project_order(N, dependencies):\n from collections import defaultdict, deque\n \n # Build graph and in-degree counter\n graph = defaul...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00002977", "row_id": 2977, "seed_ids": "[8943]" }
0.544491
Code_Contests_2977
I
[ "find_project_order", "parse_input", "solution" ]
3
[ [ "solution", "find_project_order" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6984350e9b84c45d8e5b31d64bd2f3a3ef2b53a7
4073ca3f6151b3826b145bcd1729b59c9a1a31f0
v1.0
instruct
Code_Contests
Code_Contests_2982_I
A software company is organizing a competition where each participant is given a matrix of integers. The task is to find the submatrix which has the maximum sum. The participants should write a program that outputs the maximum sum of any submatrix within the given matrix. Input : The first line contains two integers,...
def max_sum_submatrix(matrix, n, m): def kadane(arr): max_ending_here = max_so_far = arr[0] for x in arr[1:]: max_ending_here = max(x, max_ending_here + x) max_so_far = max(max_so_far, max_ending_here) return max_so_far max_sum = float('-inf') for le...
from solution import matrix_max_sum def test_sample_case(): matrix = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert matrix_max_sum(4, 5, matrix) == 29 def test_single_element_matrix(): matrix = [[-5]] assert matrix_max_sum(1,...
[ { "docstring": null, "function_declaration": "def max_sum_submatrix(matrix, n, m):", "function_name": "max_sum_submatrix", "parameter_list": "(matrix, n, m)" }, { "docstring": null, "function_declaration": "def matrix_max_sum(n, m, matrix):", "function_name": "matrix_max_sum", "p...
[ 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_sum_submatrix(matrix):\n \"\"\"\n Returns the maximum sum of any submatrix in the given matrix.\n \"\"\"\n if not matrix or not matrix[...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00002982", "row_id": 2982, "seed_ids": "[11219]" }
0.65479
Code_Contests_2982
I
[ "max_sum_submatrix", "matrix_max_sum" ]
2
[ [ "matrix_max_sum", "max_sum_submatrix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cfd77b396ed3aa30ef2ce2f1d9f8934c6c98e140
364c7526250293231692b7829f3cf93823e044c3
v1.0
instruct
Code_Contests
Code_Contests_2991_I
You are given a grid of size n × m. The grid contains integers, each integer representing the height of a cell in the grid. A cell is called a peak if it is strictly greater than all of its adjacent cells. The off-grid cells are treated as having a height of negative infinity (i.e., any cell that is out of the grid is ...
def find_peaks(grid): def is_peak(i, j): current = grid[i][j] for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni, nj = i + di, j + dj if 0 <= ni < len(grid) and 0 <= nj < len(grid[0]): if current <= grid[ni][nj]: return False retu...
import pytest from solution import peak_heights def test_peak_heights_example_case(): grid = [ [3, 4, 5], [2, 6, 1], [1, 2, 3] ] assert peak_heights(3, 3, grid) == [6, 5, 3] def test_peak_heights_single_element(): grid = [ [7] ] assert peak_heights(1, 1, grid) =...
[ { "docstring": null, "function_declaration": "def find_peaks(grid):", "function_name": "find_peaks", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def peak_heights(n, m, grid):", "function_name": "peak_heights", "parameter_list": "(n, m, grid)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_peak_cells(grid, n, m):\n def is_peak(x, y):\n current_height = grid[x][y]\n adjacents = [\n (-1, 0), (1, 0), # Up an...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00002991", "row_id": 2991, "seed_ids": "[2937]" }
0.657408
Code_Contests_2991
I
[ "find_peaks", "peak_heights" ]
2
[ [ "peak_heights", "find_peaks" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7d631e30b76f381ccecf42ffd936157e78a81e11
7e836d4be1472177e26a5208392d989560482ac5
v1.0
instruct
Code_Contests
Code_Contests_3052_I
A group of researchers are investigating a strange phenomenon involving magic flowers in an enchanted forest. Each flower displays petals with colors represented by integers. There are `n` flowers in total and each flower has exactly `m` petals. The flowers are considered identical if they can be rotated such that the ...
def rotate_sequence(seq, k): """ Returns the sequence rotated k places to the left. """ return seq[k:] + seq[:k] def normalize_sequence(seq): """ Returns the normalized (canonical) form of the sequence by rotating it to the smallest lexicographical order. """ return min(rotate_sequence(...
from solution import rotate_sequence, normalize_sequence, count_identical_flower_groups def test_rotate_sequence(): assert rotate_sequence([1, 2, 3, 4], 1) == [2, 3, 4, 1] assert rotate_sequence([1, 2, 3, 4], 2) == [3, 4, 1, 2] assert rotate_sequence([1, 2, 3, 4], 3) == [4, 1, 2, 3] assert rotate_seque...
[ { "docstring": "Returns the sequence rotated k places to the left.", "function_declaration": "def rotate_sequence(seq, k):", "function_name": "rotate_sequence", "parameter_list": "(seq, k)" }, { "docstring": "Returns the normalized (canonical) form of the sequence by rotating it to the small...
[ 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 number_of_flower_groups(n, m, petals):\n def canonical_rotation(flower):\n rotations = []\n for i in range(len(flower)):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003052", "row_id": 3052, "seed_ids": "[4527]" }
0.634213
Code_Contests_3052
I
[ "rotate_sequence", "normalize_sequence", "count_identical_flower_groups" ]
3
[ [ "count_identical_flower_groups", "normalize_sequence" ], [ "normalize_sequence", "rotate_sequence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b0f204f8815452f454ca61fed8c9f38a2a33ace1
588e4453c313895fc5cb8ddd7a8f527919bf3baf
v1.0
instruct
Code_Contests
Code_Contests_3063_I
Calculate the Product of Large Numbers Given two positive integers $X$ and $Y$, compute the product, $X \times Y$. Input Two positive integers $X$ and $Y$ separated by a space character are given in a line. Output Print the product in a line. Constraints * $1 \leq X, Y \leq 10^{100000}$ Sample Input 1 3 4 Sam...
def calculate_product(x, y): """ Returns the product of x and y. """ return x * y def parse_input(input_str): """ Parses input in the form of a string with two large integers separated by a space. Returns two integers. """ X_str, Y_str = input_str.strip().split() return int(X_st...
from solution import calculate_product, parse_input, product_of_large_numbers def test_calculate_product(): assert calculate_product(3, 4) == 12 assert calculate_product(12345678901234567890, 98765432109876543210) == 1219326311370217952237463801111263526900 assert calculate_product(99999999999999999999, 99...
[ { "docstring": "Returns the product of x and y.", "function_declaration": "def calculate_product(x, y):", "function_name": "calculate_product", "parameter_list": "(x, y)" }, { "docstring": "Parses input in the form of a string with two large integers separated by a space.\nReturns two intege...
[ 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_product(X, Y):\n \"\"\"\n Returns the product of two large positive integers X and Y.\n X and Y are given as strings to handle large...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003063", "row_id": 3063, "seed_ids": "[520]" }
0.580532
Code_Contests_3063
I
[ "calculate_product", "parse_input", "product_of_large_numbers" ]
3
[ [ "product_of_large_numbers", "calculate_product" ], [ "product_of_large_numbers", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
8994ca76f4d0c6cd2ab2b6ce1ab7583cec0270a8
c8dcaeab59c0833dee26bc8b4a49f2d14afa3c42
v1.0
instruct
Code_Contests
Code_Contests_3084_I
Mina loves prime numbers and she enjoys counting them. Given two integers l and r, she wants to find how many prime numbers are there in the inclusive range [l, r]. As the prime numbers can be large, the result can be very large as well, so she only needs to know the number of prime numbers in the range, not the primes...
def sieve_of_eratosthenes(max_num): """ Generates a list of booleans indicating the primality of numbers up to max_num. True means the number is prime, False means it is not. """ is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not primes p = 2 while p * ...
def test_sieve_of_eratosthenes(): is_prime = sieve_of_eratosthenes(30) expected_primes = [False, False, True, True, False, True, False, True, False, False, False, True, False, True, False, False, False, True, False, True, False, False, False, True, False, False, False, False, False, True, False] assert is_p...
[ { "docstring": "Generates a list of booleans indicating the primality of numbers up to max_num.\nTrue means the number is prime, False means it is not.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { ...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Generates a list of booleans indicating the primality of numbers up to max_num.\n True means the nu...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003084", "row_id": 3084, "seed_ids": "[4926]" }
0.640381
Code_Contests_3084
I
[ "sieve_of_eratosthenes", "count_primes_in_ranges", "process_input", "solve" ]
4
[ [ "count_primes_in_ranges", "sieve_of_eratosthenes" ], [ "solve", "count_primes_in_ranges" ], [ "solve", "process_input" ] ]
3
[ "process_input" ]
false
[]
false
pytest
false
[]
true
7f29741a382766f1449422ec45daf748f30b41cb
9dc8e0776a24aa0776669f187cb02ce624226345
v1.0
instruct
Code_Contests
Code_Contests_3098_I
In a mythical kingdom, there is a garden where magic flowers grow. Each flower has a unique magical value associated with it. The garden is arranged as a large grid of flowers with `R` rows and `C` columns. The magical value of each flower might change over time due to magical influences. The Queen of the kingdom is ...
def compute_prefix_sum(matrix): """ Compute the prefix sum matrix. """ R = len(matrix) C = len(matrix[0]) prefix_sum = [[0] * (C + 1) for _ in range(R + 1)] for i in range(1, R + 1): for j in range(1, C + 1): prefix_sum[i][j] = (matrix[i - 1][j - 1] ...
from solution import solve def test_basic_case(): R, C, Q = 3, 3, 2 garden = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] queries = [ (1, 1, 2, 2), (2, 2, 3, 3) ] result = solve(R, C, Q, garden, queries) assert result == [12, 28] def test_single_element_query...
[ { "docstring": "Compute the prefix sum matrix.", "function_declaration": "def compute_prefix_sum(matrix):", "function_name": "compute_prefix_sum", "parameter_list": "(matrix)" }, { "docstring": "Calculate the sum of the elements in the subgrid (r1, c1) to (r2, c2)\nusing the prefix sum matri...
[ 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 calculate_subgrid_sums(R, C, grid, queries):\n # Generate prefix sums\n prefix_sum = [[0] * (C + 1) for _ in range(R + 1)]\n \n for i in ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003098", "row_id": 3098, "seed_ids": "[7457]" }
0.595151
Code_Contests_3098
I
[ "compute_prefix_sum", "subgrid_sum", "solve" ]
3
[ [ "solve", "compute_prefix_sum" ], [ "solve", "subgrid_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ae995de245f8942154ca3ac9978c802ea1feabb6
98a0087bb89ba3864485ac2611809cf5cccbe3a3
v1.0
instruct
Code_Contests
Code_Contests_3149_I
A school organized a marathon event where students from different classes participate. The event is held in a large park, and the track is circular of length l meters. The students start running from point 0 and continue running along the track. Each student has a different speed and they all start running at the same...
import math from functools import reduce def gcd(a, b): """ Helper function to compute the GCD of two numbers. """ while b: a, b = b, a % b return a def lcm(a, b): """ Helper function to compute the LCM of two numbers. """ return a * b // gcd(a, b) def earliest_meeting_tim...
def test_earliest_meeting_time_example1(): assert earliest_meeting_time(3, 12, [2, 3, 4]) == 12 def test_earliest_meeting_time_example2(): assert earliest_meeting_time(2, 7, [3, 5]) == -1 def test_earliest_meeting_time_single_student(): assert earliest_meeting_time(1, 10, [5]) == 2 def test_earliest_meet...
[ { "docstring": "Helper function to compute the GCD of two numbers.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Helper function to compute the LCM of two numbers.", "function_declaration": "def lcm(a, b):", "functio...
[ 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": "import math\nfrom functools import reduce\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003149", "row_id": 3149, "seed_ids": "[9415]" }
0.665808
Code_Contests_3149
I
[ "gcd", "lcm", "earliest_meeting_time" ]
3
[ [ "earliest_meeting_time", "lcm" ], [ "lcm", "gcd" ] ]
2
[]
false
[]
false
pytest
false
[]
true
efc98e86087fac34b3ca07d779cf8fa8c2a326d6
edc7d2d4840c07e6fc9d3b8693bb5d60e4a77a08
v1.0
instruct
Code_Contests
Code_Contests_3208_I
Lina is playing a board game on a rectangular grid constituted of cells. Each cell is either passable or blocked. Lina can move from one cell to an adjacent cell if both cells are passable. Two cells are adjacent if they share a side. Lina wants to reach a specific goal cell starting from her initial position. Can you...
from collections import deque def min_moves(grid, n, m): # Find start and goal positions start = None goal = None for i in range(n): for j in range(m): if grid[i][j] == 'S': start = (i, j) elif grid[i][j] == 'G': goal = (i, j) if...
from solution import solve_game def test_example_1(): n = 5 m = 5 lines = [ "S...#", ".#..#", "..#.#", "#...#", "#..G." ] assert solve_game(n, m, lines) == 7 def test_example_2(): n = 3 m = 4 lines = [ "S..#", "###.", "......
[ { "docstring": null, "function_declaration": "def min_moves(grid, n, m):", "function_name": "min_moves", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def solve_game(n, m, lines):", "function_name": "solve_game", "parameter_list": "(n, m, lines...
[ 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 min_moves_to_reach_goal(n, m, grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y]...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003208", "row_id": 3208, "seed_ids": "[2652]" }
0.807933
Code_Contests_3208
I
[ "min_moves", "solve_game" ]
2
[ [ "solve_game", "min_moves" ] ]
1
[]
false
[]
false
pytest
true
[]
true
165202d188290b94f1deefcd8b7bbb88af1a24a5
c7539f784b81059fb634bc52171d69bf5297283d
v1.0
instruct
Code_Contests
Code_Contests_3235_I
You are given an integer array `arr` and you need to find the maximum product of any contiguous subarray within `arr`. For example, given the array `arr = [2, 3, -2, 4]`, the contiguous subarray `[2, 3]` has the maximum product of `6`. Input: - The first line contains an integer `T`, the number of test cases. - The ...
def max_product_subarray(arr): """ Returns the maximum product of any contiguous subarray within `arr`. """ if not arr: return 0 max_product = min_product = result = arr[0] for num in arr[1:]: if num < 0: max_product, min_product = min_product, max_product ...
from solution import max_product_subarray, solve, parse_input def test_max_product_subarray(): assert max_product_subarray([2, 3, -2, 4]) == 6 assert max_product_subarray([-1, -3, -10]) == 30 assert max_product_subarray([0, 2, -3, -4, 0]) == 24 assert max_product_subarray([1, -2, -3, 0, 7, -8, -2]) == ...
[ { "docstring": "Returns the maximum product of any contiguous subarray within `arr`.", "function_declaration": "def max_product_subarray(arr):", "function_name": "max_product_subarray", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_product_subarray(arr):\n \"\"\"\n Returns the maximum product of any contiguous subarray within `arr`.\n \"\"\"\n if not arr:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003235", "row_id": 3235, "seed_ids": "[2675]" }
0.785745
Code_Contests_3235
I
[ "max_product_subarray", "solve", "parse_input" ]
3
[ [ "solve", "max_product_subarray" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
31847335e8b70f622a311278495ff3567020677b
f13b6926ccad263ea1388033232149f5a539529d
v1.0
instruct
Code_Contests
Code_Contests_3296_I
You are given a rectangular matrix of dimensions n x m consisting of integers. We define the sum of a submatrix as the sum of all the elements within that submatrix. Your task is to find the submatrix with the maximum sum. The rectangle with the maximum sum will give you the desired result. ### Input The first line...
def max_submatrix_sum(matrix): """ Finds the submatrix within the given matrix that has the maximum sum and returns that sum. Uses a 2D variant of Kadane's algorithm. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for ...
from solution import max_submatrix_sum def test_example_1(): matrix = [ [1, 2, -1, 4, -5], [-8, 3, 0, 5, 2], [-4, 6, -3, -4, 4], [2, 8, 0, -1, 3] ] assert max_submatrix_sum(matrix) == 23 def test_example_2(): matrix = [ [-1, -2, -3], [-4, -5, -6], ...
[ { "docstring": "Finds the submatrix within the given matrix that has the maximum sum and returns that sum.\nUses a 2D variant of Kadane's algorithm.", "function_declaration": "def max_submatrix_sum(matrix):", "function_name": "max_submatrix_sum", "parameter_list": "(matrix)" }, { "docstring"...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Returns the maximum sum of a submatrix within the given matrix.\n \"\"\"\n def kadane(arr):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003296", "row_id": 3296, "seed_ids": "[12126]" }
0.654684
Code_Contests_3296
I
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fe4701f5b0aedfe0cb1f9a329866e10c96454aba
6a3f8fb68876b030d6ed4240a8e3d6a7a27339e1