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_42346_I
You are a prisoner in a strange world with only your laptop as a companion. Suddenly, a mystical creature appears, offering you freedom if you can solve the following challenge: You are given a binary tree with `n` nodes, where each node has a unique value from `1` to `n`. For each node, you can perform the following ...
class TreeNode: def __init__(self, value=-1, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(node_descriptors): nodes = {} for desc in node_descriptors: value, left, right = desc if value not in nodes: nodes[v...
def test_basic_case(): initial_tree = [ (1, 2, 3), (2, 4, -1), (3, -1, 5), (4, -1, -1), (5, -1, 6), (6, -1, -1) ] target_tree =[ (1, 3, 2), (3, 5, -1), (2, 6, 4), (5, -1, -1), (6, -1, -1), (4, -1, -1) ] ...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(nodes):\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042346", "row_id": 42346, "seed_ids": "[9081]" }
0.585399
Code_Contests_42346
I
[ "build_tree", "trees_are_identical", "swap_children", "can_transform", "solve" ]
5
[ [ "can_transform", "swap_children" ], [ "can_transform", "trees_are_identical" ], [ "solve", "build_tree" ], [ "solve", "can_transform" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
42db03703dafcde66911555456f6a9ac27450368
fb1b8891211279da62ee9b93a3c47640ea8f846a
v1.0
instruct
Code_Contests
Code_Contests_42467_I
You are given a directed graph with `N` nodes and `M` edges. Each edge has a non-negative weight. The nodes are numbered from `1` to `N`. Your task is to determine the shortest path from a given starting node `S` to all other nodes in the graph. Constraints * All values in input are integers. * 1 \leq N \leq 1000 * 1...
import heapq def dijkstra(N, edges, S): # Create adjacency list graph = {i: [] for i in range(1, N + 1)} for u, v, w in edges: graph[u].append((v, w)) # Initialize distances with infinity distances = {i: float('inf') for i in range(1, N + 1)} distances[S] = 0 # Min-heap pr...
def test_example1(): input_str = "5 6 1\n1 2 2\n1 3 4\n2 3 1\n3 4 7\n2 4 3\n4 5 1\n" output = shortest_paths(input_str) assert output == "0 2 3 5 6" def test_example2(): input_str = "3 2 2\n2 1 5\n2 3 1\n" output = shortest_paths(input_str) assert output == "5 0 1" def test_example3(): inp...
[ { "docstring": null, "function_declaration": "def dijkstra(N, edges, S):", "function_name": "dijkstra", "parameter_list": "(N, edges, S)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list": "(input_str)"...
[ 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 shortest_paths(N, M, S, edges):\n # Create adjacency list for the graph\n graph = [[] for _ in range(N + 1)]\n for u, v, w in ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042467", "row_id": 42467, "seed_ids": "[1229]" }
0.808031
Code_Contests_42467
I
[ "dijkstra", "parse_input", "shortest_paths" ]
3
[ [ "shortest_paths", "dijkstra" ], [ "shortest_paths", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
fda06b43deffeed9ec15f17987797c08ef874fca
148a0eba642434b4cd7b8676c83b25ba91f0bde5
v1.0
instruct
Code_Contests
Code_Contests_42494_I
A grid-based farm has dimensions n x m, containing several types of cells - open land for planting crops (.), rocks that cannot be moved (X), and a watering system that should be placed in one specific cell (W). A robot placed on one of the open land cells must navigate the farm to place the watering system in the targ...
from collections import deque # Directions for moving and pushing the system & corresponding changes in coordinates dirs = [("U", -1, 0), ("D", 1, 0), ("L", 0, -1), ("R", 0, 1)] pdirs = {"U": ("PU", -2, 0), "D": ("PD", 2, 0), "L": ("PL", 0, -2), "R": ("PR", 0, 2)} def bfs(start, is_valid): """ Standard BFS for sh...
from solution import main from io import StringIO import sys def test_possible_case_1(capsys): input_str = "5 5\n.....\n.R..X\n..X..\n..W..\n....T\n" sys.stdin = StringIO(input_str) main(5, 5, [ ".....", ".R..X", "..X..", "..W..", "....T" ]) captured = capsys...
[ { "docstring": "Standard BFS for shortest path search ", "function_declaration": "def bfs(start, is_valid):", "function_name": "bfs", "parameter_list": "(start, is_valid)" }, { "docstring": "Returns a function for valid cell checking ", "function_declaration": "def is_valid_factory(n, m,...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_shortest_path(grid, start, end, robot_initial):\n n, m = len(grid), len(grid[0])\n directions = [('U', -1, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00042494", "row_id": 42494, "seed_ids": "[7967]" }
0.647792
Code_Contests_42494
I
[ "bfs", "is_valid_factory", "determine_sequence", "main" ]
4
[ [ "determine_sequence", "bfs" ], [ "determine_sequence", "is_valid_factory" ] ]
2
[]
false
[]
false
pytest
true
[]
true
842f3d2b80c9ef017c48cff2e88e69aac9f7f016
486c1406ac8168a39cd5fba0982f57e6b79a0ae1
v1.0
instruct
Code_Contests
Code_Contests_42516_I
Little Dormi is playing with dominoes on a grid and needs your help to determine if he can completely cover a particular rectangular grid using only 2x1 dominoes. The rectangular grid has dimensions n rows and m columns, where n and m are both even. Little Dormi can place a 2x1 domino either horizontally or vertically...
def can_cover_with_dominoes(n, m, grid): from collections import deque # Check the total number of empty cells. empty_cells = sum(row.count('.') for row in grid) # If the number of empty cells is odd, it's impossible to cover them with 2x1 dominoes. if empty_cells % 2 != 0: return "NO"...
from solution import solve_domino_cover def test_basic_yes_case(): n, m = 4, 4 raw_grid = [ "....", "....", "....", "...." ] result = solve_domino_cover(n, m, raw_grid) assert result.startswith("YES") def test_basic_no_case(): n, m = 4, 4 raw_grid = [ ...
[ { "docstring": null, "function_declaration": "def can_cover_with_dominoes(n, m, grid):", "function_name": "can_cover_with_dominoes", "parameter_list": "(n, m, grid)" }, { "docstring": null, "function_declaration": "def solve_domino_cover(n, m, raw_grid):", "function_name": "solve_dom...
[ 0, 0, 0, 0, 0, 1, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_cover_with_dominoes(n, m, grid):\n def find_empty_cell():\n for i in range(n):\n for j in range(m):\n if grid[i...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00042516", "row_id": 42516, "seed_ids": "[9507]" }
0.68695
Code_Contests_42516
I
[ "can_cover_with_dominoes", "solve_domino_cover" ]
2
[ [ "solve_domino_cover", "can_cover_with_dominoes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
019be8a9753747b25a056af1fa318c581d0cf574
abb085bea20432d0a12d77c692ff24cfe0619d1a
v1.0
instruct
Code_Contests
Code_Contests_42526_I
Problem description. Mason loves prime numbers and also palindromes. He came up with a challenge to test his friends. He asked them to find the smallest prime palindrome greater than or equal to a given number N. A number is called a palindrome if it reads the same backward as forward. Help Mason's friends by writing...
def is_prime(n): """Check if a number is prime.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def is_p...
from solution import smallest_prime_palindrome def test_example_case(): assert smallest_prime_palindrome(31) == 101 def test_smallest_numbers(): assert smallest_prime_palindrome(1) == 2 assert smallest_prime_palindrome(2) == 2 assert smallest_prime_palindrome(3) == 3 def test_next_prime_palindrome():...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00042526", "row_id": 42526, "seed_ids": "[3963]" }
0.767767
Code_Contests_42526
I
[ "is_prime", "is_palindrome", "smallest_prime_palindrome" ]
3
[ [ "smallest_prime_palindrome", "is_palindrome" ], [ "smallest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c809486adb4639d633f299d21d7078834fc59740
30c221d0a883d520e0fb44ab4cd66a8318015be4
v1.0
instruct
Code_Contests
Code_Contests_42534_I
A company is launching a new password policy to strengthen security. The new policy mandates that a valid password must have the following characteristics: - At least 8 characters long - Contains at least one uppercase letter - Contains at least one lowercase letter - Contains at least one digit - Contains at least one...
import re def is_valid_password(password): """ Checks if the given password meets the new policy requirements. """ if len(password) < 8: return False if not re.search(r'[A-Z]', password): return False if not re.search(r'[a-z]', password): return False if not re.searc...
from solution import is_valid_password, check_passwords def test_is_valid_password(): assert is_valid_password("Password123!") == True assert is_valid_password("password123") == False assert is_valid_password("PASSWORD123!") == False assert is_valid_password("Passw0rd") == False assert is_valid_pas...
[ { "docstring": "Checks if the given password meets the new policy requirements.", "function_declaration": "def is_valid_password(password):", "function_name": "is_valid_password", "parameter_list": "(password)" }, { "docstring": "Given a list of passwords, return a list of \"YES\" or \"NO\" ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_valid_password(password):\n if len(password) < 8:\n return \"NO\"\n if not re.search(r'[A-Z]', password):\n return ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042534", "row_id": 42534, "seed_ids": "[12884]" }
0.631609
Code_Contests_42534
I
[ "is_valid_password", "check_passwords" ]
2
[ [ "check_passwords", "is_valid_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a9013b77a431e184787d54cdd2e10684f86062bd
c6966355b5084a8f44bf7e9ee26d509d67616b26
v1.0
instruct
Code_Contests
Code_Contests_42535_I
Mike loves playing with colors. He has an unlimited supply of three primary colors: red, green, and blue. He wants to mix these primary colors to form various new colors. Each new color Mike wants to create requires a specific quantity of red, green, and blue. Given a list of ratios for each color he wants to generate,...
import math def gcd(x, y): while y: x, y = y, x % y return x def normalize_color(r, g, b): g_value = gcd(gcd(r, g), b) return (r // g_value, g // g_value, b // g_value) def count_unique_colors(n, color_ratios): unique_colors = set() for r, g, b in color_ratios: normalized = no...
from solution import count_unique_colors def test_basic_examples(): assert count_unique_colors(5, [(2, 4, 6), (1, 2, 3), (3, 3, 9), (2, 2, 6), (5, 6, 7)]) == 3 assert count_unique_colors(4, [(1, 1, 1), (10, 10, 10), (2, 2, 2), (1, 1, 1)]) == 1 assert count_unique_colors(3, [(1, 2, 3), (2, 4, 6), (3, 5, 9)]...
[ { "docstring": null, "function_declaration": "def gcd(x, y):", "function_name": "gcd", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def normalize_color(r, g, b):", "function_name": "normalize_color", "parameter_list": "(r, g, b)" }, { "docst...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom functools import reduce\n\ndef normalize_ratio(r, g, b):\n \"\"\"\n Normalize the color ratios by dividing each by their g...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042535", "row_id": 42535, "seed_ids": "[3549]" }
0.593863
Code_Contests_42535
I
[ "gcd", "normalize_color", "count_unique_colors" ]
3
[ [ "count_unique_colors", "normalize_color" ], [ "normalize_color", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
95433cb26750966635f3bedfcccf56dcbf84f899
28205b2a0d219c5d4f77cc037099d2320bfee5ef
v1.0
instruct
Code_Contests
Code_Contests_42558_I
Sum of Digits In the United Kingdom of XYZ, every citizen is required to have a unique identification number called the Unique Identity Number (UIN). This number is a positive integer composed of up to 64 digits. The government decides to introduce a security system where citizens' UINs are verified by computing a ch...
def sum_of_digits(uin): """ Computes the check digit for the given UIN. """ while len(uin) > 1: uin = str(sum(int(digit) for digit in uin)) return int(uin) def process_uins(uins): """ Processes a list of UIN strings, computing the check digit for each. """ results = [] f...
from solution import sum_of_digits, process_uins def test_sum_of_digits_single_digit(): assert sum_of_digits("5") == 5 def test_sum_of_digits_multiple_iterations(): assert sum_of_digits("9875") == 2 assert sum_of_digits("12345") == 6 def test_process_uins_with_termination(): assert process_uins(["987...
[ { "docstring": "Computes the check digit for the given UIN.", "function_declaration": "def sum_of_digits(uin):", "function_name": "sum_of_digits", "parameter_list": "(uin)" }, { "docstring": "Processes a list of UIN strings, computing the check digit for each.", "function_declaration": "...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check_digit(uin):\n \"\"\"\n Returns the check digit for a given UIN by repeatedly summing the digits until a single-digit number is obtained.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042558", "row_id": 42558, "seed_ids": "[9576]" }
0.666895
Code_Contests_42558
I
[ "sum_of_digits", "process_uins" ]
2
[ [ "process_uins", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56c87927b0ed7c86832dfc48bdc4153615a44b02
d44738718f2ac6717689cf8c9f9ee3501213f1f6
v1.0
instruct
Code_Contests
Code_Contests_42620_I
Jack loves prime numbers. According to him, a prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. While preparing for a math competition, he encounters many lists of numbers and wants to find prime numbers in these lists. He also wants to count how many primes are there in e...
def is_prime(num): """ Helper function to check if a number is prime """ if num <= 1: return False if num == 2: return True # 2 is the only even prime number if num % 2 == 0: return False # Other even numbers are not primes for i in range(3, int(num**0.5) + 1, 2): ...
from solution import count_prime_numbers def test_valid_case(): assert count_prime_numbers([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 13, 17, 19, 23, 24, 25, 26]]) == [4, 5] def test_zero_lists(): assert count_prime_numbers([]) == "Invalid Test" def test_too_many_lists(): lists = [[1] for _ in range(11)] ...
[ { "docstring": "Helper function to check if a number is prime ", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Takes a list of lists of numbers and returns a list of counts of prime numbers in each sublist.", "func...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n elif num == 2:\n return Tru...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00042620", "row_id": 42620, "seed_ids": "[2886]" }
0.687047
Code_Contests_42620
I
[ "is_prime", "count_prime_numbers" ]
2
[ [ "count_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f5f20c0e28c32ad39ceb282df361dca6f6a43a0
65a656ba84cf8dc768187063d4c0755789259a0d
v1.0
instruct
Code_Contests
Code_Contests_42637_I
Two friends, Ankit and Priya, enjoy designing challenges for each other. Priya has left an interesting problem for Ankit to solve. The problem was written on a note inside a small chest. Help Ankit solve the problem to unlock the chest. Here is the puzzle given: Define a function S(n) as follows: S(0) = 1, S(1) = 2,...
def S(n): """ Computes the value of S(n) as described in the problem statement. """ if n == 0: return 1 if n == 1: return 2 if n == 2: return 4 sum_squares = 0 for even in range(2, n + 1, 2): sum_squares += even ** 2 return sum_squares def sum_of_rema...
from solution import S, sum_of_remainders, solve_challenges def test_S(): assert S(0) == 1 assert S(1) == 2 assert S(2) == 4 assert S(3) == 4 assert S(5) == 20 def test_sum_of_remainders(): assert sum_of_remainders(3) == 1 assert sum_of_remainders(5) == 2 assert sum_of_remainders(0) ==...
[ { "docstring": "Computes the value of S(n) as described in the problem statement.", "function_declaration": "def S(n):", "function_name": "S", "parameter_list": "(n)" }, { "docstring": "Computes the sum of the remainders when S(n) is divided by each integer from 1 to n.", "function_decla...
[ 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 S(n):\n if n == 0:\n return 1\n elif n == 1:\n return 2\n elif n == 2:\n return 4\n else:\n return sum(k**2 for...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00042637", "row_id": 42637, "seed_ids": "[5702]" }
0.700785
Code_Contests_42637
I
[ "S", "sum_of_remainders", "solve_challenges" ]
3
[ [ "solve_challenges", "sum_of_remainders" ], [ "sum_of_remainders", "S" ] ]
2
[]
false
[]
false
pytest
true
[]
true
89bc08ad7e8bcb62b240f04e51cba1a24b389609
430dfd9a19ca8b4a53346a340db7bc018dc481af
v1.0
instruct
Code_Contests
Code_Contests_42686_I
A delivery service needs to optimize its route to visit multiple locations sequentially and return to the starting point. You are required to solve this using the Traveling Salesperson Problem (TSP) and implement an algorithm to find the shortest possible route. ### Problem Statement Given a list of locations represen...
import math from functools import lru_cache def calculate_distance(point1, point2): """Calculates the Euclidean distance between two points.""" return math.sqrt((point2[0] - point1[0])**2 + (point2[1] - point1[1])**2) def tsp(n, locations): """Returns the length of the shortest possible route visiting eac...
from solution import tsp def test_tsp_example(): n = 4 locations = [(0, 0), (2, 2), (2, 0), (0, 2)] assert math.isclose(tsp(n, locations), 8.000000, rel_tol=1e-6) def test_tsp_two_locations(): n = 2 locations = [(0, 0), (3, 4)] assert math.isclose(tsp(n, locations), 10.000000, rel_tol=1e-6) d...
[ { "docstring": "Calculates the Euclidean distance between two points.", "function_declaration": "def calculate_distance(point1, point2):", "function_name": "calculate_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Returns the length of the shortest possible route visiting...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import lru_cache\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculates the Euclidean distance between two points p1 an...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00042686", "row_id": 42686, "seed_ids": "[11971]" }
0.696289
Code_Contests_42686
I
[ "calculate_distance", "tsp" ]
2
[ [ "tsp", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ab8903d8058a2b5138057a658abd26770bcac5b
bc88059918bf7d96586eded16af0f243ed9ee4d2
v1.0
instruct
Code_Contests
Code_Contests_42702_I
Matching Tiles Two artists have created unique wall tile patterns represented by binary matrices of the same size. These patterns consist of two characters, '0' and '1', where '0' represents a blank tile and '1' represents a filled tile. The patterns are aesthetically different due to their complex structure and desig...
def rotate_90(matrix): """ Rotates the given nxn matrix 90 degrees clockwise. """ n = len(matrix) return [[matrix[n - j - 1][i] for j in range(n)] for i in range(n)] def check_rotations(matrix1, matrix2): """ Checks if matrix1 can be transformed into matrix2 via rotations of 0°, 90°, 180°, ...
from solution import matching_tiles def test_matching_tiles(): test_cases = [ ( [["0", "1", "0"], ["1", "0", "1"], ["0", "1", "0"]], [["1", "1", "1"], ["1", "0", "1"], ["1", "1", "1"]] ), ( [["0", "...
[ { "docstring": "Rotates the given nxn matrix 90 degrees clockwise.", "function_declaration": "def rotate_90(matrix):", "function_name": "rotate_90", "parameter_list": "(matrix)" }, { "docstring": "Checks if matrix1 can be transformed into matrix2 via rotations of 0°, 90°, 180°, or 270°.", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_matrix_90_degrees(matrix):\n \"\"\"Rotates a given matrix 90 degrees clockwise.\"\"\"\n return [''.join(row[i] for row in matrix[::-1]) fo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042702", "row_id": 42702, "seed_ids": "[7072]" }
0.656233
Code_Contests_42702
I
[ "rotate_90", "check_rotations", "matching_tiles" ]
3
[ [ "check_rotations", "rotate_90" ], [ "matching_tiles", "check_rotations" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6369088ef26204b0da1f663828f7dd4fb5fc0101
d1fc05a6699ad3de8001353b6a1ebabd9163602d
v1.0
instruct
Code_Contests
Code_Contests_42815_I
In a distant galaxy, there are several planets. Each planet is connected to some number of other planets through teleportation portals. Each portal has a certain cost associated with it. The government of the galaxy wants to establish a main hub on one of these planets such that the sum of the costs to travel from thi...
import heapq import sys def dijkstra(n, graph, start): distances = [sys.maxsize] * n distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, u = heapq.heappop(priority_queue) if current_distance > distances[u]: continue ...
def test_dijkstra(): n = 3 graph = [ [(1, 1), (2, 4)], [(0, 1), (2, 2)], [(0, 4), (1, 2)] ] assert dijkstra(n, graph, 0) == [0, 1, 3] assert dijkstra(n, graph, 1) == [1, 0, 2] assert dijkstra(n, graph, 2) == [3, 2, 0] def test_find_main_hub(): n = 3 m = 3 ...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def find_main_hub(n, m, portals):", "function_name": "find_main_hub", "parameter_list...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_hub_planet(n, m, edges):\n def dijkstra(source):\n dist = [float('inf')] * n\n dist[source] = 0\n min_heap...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042815", "row_id": 42815, "seed_ids": "[2882]" }
0.64292
Code_Contests_42815
I
[ "dijkstra", "find_main_hub", "solve", "main" ]
4
[ [ "find_main_hub", "dijkstra" ], [ "solve", "find_main_hub" ] ]
2
[]
false
[]
false
pytest
false
[]
true
041c826dd8ed1e48006da9c41b0e18c4957d56a3
7a4b8ca2b0643836128163647740ed1be05dc559
v1.0
instruct
Code_Contests
Code_Contests_42840_I
In a kingdom far away, there are N beautiful castles connected by M pathways. Each pathway directly connects two castles and has a positive integer length associated with it. However, due to a recent war, some of the pathways may have become impassable. The king wants to ensure that the kingdom remains united, meaning...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, u, v): root_u = find(parent, u) root_v = find(parent, v) if root_u != root_v: if rank[root_u] > rank[root_v]: parent[r...
from solution import minimum_repair_needed def test_case_1(): n = 6 m = 7 edges = [ (1, 2, 5), (2, 3, 10), (3, 4, 3), (4, 5, 4), (5, 6, 2), (6, 1, 8), (3, 6, 7) ] k = 2 damaged = [ (3, 4), (5, 6) ] assert minimum_re...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, u, v):", "function_name": "union", "parameter_list": "(parent, rank, u, v)" }, ...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n \"\"\"\n A helper function to find the root of the node i with path compression.\n \"\"\"\n if parent[i] != i:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00042840", "row_id": 42840, "seed_ids": "[1361]" }
0.664083
Code_Contests_42840
I
[ "find", "union", "minimum_repair_needed" ]
3
[ [ "minimum_repair_needed", "find" ], [ "minimum_repair_needed", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3b540fe4bc473213ae16208b2308ef5970d1f014
96ec10f83000d5d0c57f0ed2ac38e769f24b85d5
v1.0
instruct
Code_Contests
Code_Contests_42847_I
Certain numbers are called palindrome numbers if they read the same forwards and backwards. For example, 121, 1331, and 7 are palindrome numbers. Your task is to determine whether an input number is a palindrome. Further, if the input number is a palindrome, you need to determine the smallest palindrome number that ca...
from collections import Counter def is_palindrome(num): """ Determine if a number is a palindrome. """ s = str(num) return s == s[::-1] def smallest_palindrome_permutation(N): """ Determine if the input number N is a palindrome. If it is, return the smallest palindrome permutation of N...
from solution import is_palindrome, smallest_palindrome_permutation def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123) == False assert is_palindrome(7) == True assert is_palindrome(22) == True def test_smallest_palindrome_permu...
[ { "docstring": "Determine if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring": "Determine if the input number N is a palindrome.\nIf it is, return the smallest palindrome permutation of...
[ 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 Counter\n\ndef is_palindrome(num):\n \"\"\"\n Returns True if the given number is a palindrome, else False.\n \"\"\"\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00042847", "row_id": 42847, "seed_ids": "[11949]" }
0.84782
Code_Contests_42847
I
[ "is_palindrome", "smallest_palindrome_permutation" ]
2
[ [ "smallest_palindrome_permutation", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
59200597f4822b5eb4fc02010d4f3d27c2b459ea
46febdf61be25c7b0f9b919b898378893696c464
v1.0
instruct
Code_Contests
Code_Contests_42865_I
Consider a game where you are given an infinite 2D grid, and each cell of the grid is initially empty. You can perform the following operations: 1. Add a token to a cell. 2. Find the minimum distance between two tokens on the grid, with distance being Manhattan distance. Manhattan distance between two points (x1, y1)...
def min_manhattan_distance(tokens): """ Function to find the minimum Manhattan distance between any two tokens on the grid """ min_dist = float('inf') # Calculate the distance between each pair of tokens for i in range(len(tokens)): for j in range(i + 1, len(tokens)): di...
from solution import perform_operations def test_min_dist_single_query(): operations = ["ADD 1 2", "ADD 3 4", "MIN_DIST"] assert perform_operations(operations) == [4] def test_min_dist_multiple_queries(): operations = ["ADD 1 2", "ADD 3 4", "ADD 1 3", "ADD 5 6", "MIN_DIST", "ADD 2 2", "MIN_DIST"] asse...
[ { "docstring": "Function to find the minimum Manhattan distance between any two tokens on the grid", "function_declaration": "def min_manhattan_distance(tokens):", "function_name": "min_manhattan_distance", "parameter_list": "(tokens)" }, { "docstring": "Function to perform the operations on...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class GridGame:\n def __init__(self):\n self.tokens = []\n\n def add_token(self, x, y):\n self.tokens.append((x, y))\n\n def min_dis...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00042865", "row_id": 42865, "seed_ids": "[9864]" }
0.678454
Code_Contests_42865
I
[ "min_manhattan_distance", "perform_operations" ]
2
[ [ "perform_operations", "min_manhattan_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1696ff734b633bd8100bd6bce3ffe7d30feca44c
20892f2d64068ecb4c24b057e8643fa64e20868d
v1.0
instruct
Code_Contests
Code_Contests_42876_I
Calculate the smallest prime number that is greater than a given integer N. Constraints * 0 \leq N \leq 10^6 Input Input is given from Standard Input in the following format: N Output Print the smallest prime number greater than N. Examples Input 10 Output 11 Input 29 Output 31 Input 0 Output ...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def smallest_prime_greater_than(N): candid...
from solution import is_prime, smallest_prime_greater_than def test_is_prime(): assert not is_prime(0) assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(6) assert is_prime(7) assert not is_prime(9) assert i...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def smallest_prime_greater_than(N):", "function_name": "smallest_prime_greater_than", "parameter_list": "(N)" }...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if the number is prime, otherwise False\n \"\"\"\n if num <= 1:\n return False\n if num <=...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00042876", "row_id": 42876, "seed_ids": "[5078]" }
0.600237
Code_Contests_42876
I
[ "is_prime", "smallest_prime_greater_than" ]
2
[ [ "smallest_prime_greater_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fae7ad4a98680c09eef2e3526a18f4ac87cc74bc
61e4a683c00bc5c50c386fe31b8b2ffee6c6189b
v1.0
instruct
Code_Contests
Code_Contests_42959_I
The Prime Palindrome Puzzle A palindrome is a string that reads the same forward and backward. A prime number is a natural number greater than 1 that is not divisible by any numbers other than 1 and itself. The task is to find the smallest prime number greater than or equal to a given integer N, which is also a palind...
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 is_palindrome(num): re...
from solution import is_prime, is_palindrome, smallest_prime_palindrome def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(31) == True assert is_prime(101) == True def test_is_palindrome(): assert is_palindrome(121) == True ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { "docstring...
[ 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(x):\n \"\"\"\n Check if a given number x is a palindrome.\n \"\"\"\n s = str(x)\n return s == s[::-1]\n\ndef is_prime(x):\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00042959", "row_id": 42959, "seed_ids": "[942]" }
0.702659
Code_Contests_42959
I
[ "is_prime", "is_palindrome", "smallest_prime_palindrome" ]
3
[ [ "smallest_prime_palindrome", "is_palindrome" ], [ "smallest_prime_palindrome", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
45705af3abbf832538eb8a1674aa1e0e6757aa74
efddd8f39284cd026d7e493f4c0d9527670a9f3c
v1.0
instruct
Code_Contests
Code_Contests_42965_I
Alice is interested in prime numbers and their properties. She recently learned about twin primes, which are pairs of prime numbers that differ by exactly 2. For example, (3, 5) and (11, 13) are twin primes. Alice wants to find out if there exists a pair of twin primes within a given range of numbers. Write a program ...
def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def find_twin_primes(n, ...
from solution import is_prime, find_twin_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(11) == True assert is_prime(13) == True assert is_prime(17) == T...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Determine if there exists at least one pair of twin primes (p1, p2)\nsuch that n <= p1 < p2 <= m.", "function_declaration"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00042965", "row_id": 42965, "seed_ids": "[1305]" }
0.677605
Code_Contests_42965
I
[ "is_prime", "find_twin_primes" ]
2
[ [ "find_twin_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
593c42bf2efc5b6fd832e02c8ec1e490379bcf40
2ed1831f482cdc414811d6e47ffe882db90f1544
v1.0
instruct
Code_Contests
Code_Contests_43024_I
You are given an array of integers that describes an initial state of a binary tree. The array is represented in a level order traversal manner where `None` represents a missing node. Your task is to validate whether the given array can represent a binary search tree (BST). Remember that in a BST, for any node `n`, a...
def is_bst(level_order): """ Checks if the given level order traversal represents a valid binary search tree. """ def helper(index, min_val, max_val): if index >= len(level_order) or level_order[index] is None: return True if not (min_val < level_order[index] < max_v...
from solution import bst_from_level_order, parse_input def test_bst_from_level_order(): input_data = "3\n7\n2 1 3 None None None None\n5\n5 1 4 None None 3 6\n7\n10 5 15 4 7 12 18" expected_output = ["YES", "NO", "YES"] t, test_cases = parse_input(input_data) assert bst_from_level_order(t, test_cases) ...
[ { "docstring": "Checks if the given level order traversal represents a valid binary search tree.", "function_declaration": "def is_bst(level_order):", "function_name": "is_bst", "parameter_list": "(level_order)" }, { "docstring": null, "function_declaration": "def bst_from_level_order(t,...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_represent_bst(t, test_cases):\n results = []\n \n for i in range(t):\n l, arr = test_cases[i]\n if validate_bst_level_order(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043024", "row_id": 43024, "seed_ids": "[6177]" }
0.624978
Code_Contests_43024
I
[ "is_bst", "bst_from_level_order", "parse_input" ]
3
[ [ "bst_from_level_order", "is_bst" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
1c6cbd12ee2fd1be881b840f8f68601fd71925fe
392d2622e07a2247d28555579aefcd57abdc4e3b
v1.0
instruct
Code_Contests
Code_Contests_43062_I
In the enchanted forest of Eldoria, each tree is connected to other trees via magical vines. The forest guardians want to ensure that the network of vine connections forms a looplessly connected structure, which means there should be exactly one path connecting any pair of trees. If there are additional or redundant vi...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: ...
def test_minimal_spanning_tree(): edges = [ (1, 2, 2), (1, 3, 3), (2, 3, 1), ] N, M = 3, 3 result = minimal_spanning_tree(N, M, edges) expected = [(2, 3), (1, 2)] for edge in result: assert edge in expected assert len(result) == N-1 def test_minimal_span...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_spanning_tree(N, M, edges):\n \"\"\"\n This function takes the number of trees (N), the number of vines (M), and a list of edges where each ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043062", "row_id": 43062, "seed_ids": "[11272]" }
0.633531
Code_Contests_43062
I
[ "find", "union", "kruskal", "minimal_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimal_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
c99a53c5c98a97b57046b7136390905e1ba71827
6f78e95dacc3e2fba8e90381b566dac68154dc39
v1.0
instruct
Code_Contests
Code_Contests_43162_I
You are given a grid of size n × m, where each cell in the grid contains a single lowercase English letter. You need to determine the size of the largest rectangle that can be formed using only one type of letter. Input The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in...
def largest_rectangle_area(grid): n = len(grid) if n == 0: return 0 m = len(grid[0]) if m == 0: return 0 # Transform the grid into height matrix for each letter heights = {chr(i): [0] * m for i in range(ord('a'), ord('z') + 1)} max_area = 0 for i in range(n): ...
from solution import largest_rectangle_area def test_largest_rectangle_area_case1(): grid = [ "aab", "abb", "bbb" ] assert largest_rectangle_area(grid) == 4 def test_largest_rectangle_area_case2(): grid = [ "abcde", "fghij", "klmno", "pqrst" ...
[ { "docstring": null, "function_declaration": "def largest_rectangle_area(grid):", "function_name": "largest_rectangle_area", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def largest_histogram_area(heights):", "function_name": "largest_histogram_area", ...
[ 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 largest_rectangle_area(grid):\n n = len(grid)\n m = len(grid[0])\n \n max_area = 0\n \n for row in range(n):\n heights = [0] *...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043162", "row_id": 43162, "seed_ids": "[2460]" }
0.644496
Code_Contests_43162
I
[ "largest_rectangle_area", "largest_histogram_area" ]
2
[ [ "largest_rectangle_area", "largest_histogram_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7eec75ac94b4aa78fe6073e64464718e4b8944e
715a3b420360f0fc4a64cf565b1d9872891b6805
v1.0
instruct
Code_Contests
Code_Contests_43180_I
Given an array of n integers, we refer to a subarray as "interesting" if it contains only prime numbers. Your task is to find the maximum length of such an "interesting" subarray. Input The first line contains a single integer n (1 ≤ n ≤ 105), which is the number of elements in the array. The second line contains n ...
def is_prime(num): """ Helper function to check if a number is prime. """ if num < 2: return False if num in (2, 3): return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: retu...
from solution import max_length_interesting_subarray def test_example_1(): arr = [2, 3, 5, 4, 11, 13, 6] assert max_length_interesting_subarray(arr) == 3 def test_example_2(): arr = [10, 12, 15, 8, 9] assert max_length_interesting_subarray(arr) == 0 def test_example_3(): arr = [13, 17, 19, 20, 23...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Given an array of integers, return the maximum length of interesting subarray\nwhich contains only prime nu...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043180", "row_id": 43180, "seed_ids": "[4722]" }
0.70637
Code_Contests_43180
I
[ "is_prime", "max_length_interesting_subarray" ]
2
[ [ "max_length_interesting_subarray", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac91b23202dfa889c24dfdd7b694f6984a0fc920
f022967dc5c6e225d24b5d8626428cc85107cf9a
v1.0
instruct
Code_Contests
Code_Contests_43184_I
You are given an undirected weighted graph with n nodes and m edges. The graph represents a network where each node is a computing device, and each edge represents a direct communication link between two devices with a certain weight indicating the latency of the link. You need to determine the minimum latency required...
import heapq def dijkstra(n, m, s, edges): """ Returns the minimum latency to communicate from source node s to all other nodes in an undirected weighted graph. """ graph = [[] for _ in range(n + 1)] for v, u, l in edges: graph[v].append((u, l)) graph[u].append((v, l)) dist = [...
from solution import solve def test_example1(): n = 6 m = 7 s = 1 edges = [ (1, 2, 10), (1, 3, 5), (2, 3, 2), (2, 4, 1), (3, 4, 9), (3, 5, 2), (4, 6, 6) ] result = solve(n, m, s, edges) assert result == [0, 7, 5, 8, 7, 14] def test_ex...
[ { "docstring": "Returns the minimum latency to communicate from source node s to all other nodes in an undirected weighted graph.", "function_declaration": "def dijkstra(n, m, s, edges):", "function_name": "dijkstra", "parameter_list": "(n, m, s, edges)" }, { "docstring": null, "function...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef dijkstra(n, edges, s):\n \"\"\"\n Apply Dijkstra's algorithm to find the shortest path from source `s` to all nodes i...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00043184", "row_id": 43184, "seed_ids": "[6798]" }
0.711895
Code_Contests_43184
I
[ "dijkstra", "solve" ]
2
[ [ "solve", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d7a3e70f17aa91a1f40a32f819f792594fc92a0
b5e146d036378824fcacb92a807572e396c3429f
v1.0
instruct
Code_Contests
Code_Contests_43211_I
Write a function that takes an integer n and a list of integers. The function should return a list containing only the prime numbers from the given list, up to the integer n. Input The first line of input contains an integer n (2 ≤ n ≤ 103). The second line contains a list of integers separated by single spaces. Out...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def primes_up_to_n(n, numbers): """ Returns a list of prime numbers from 'n...
from solution import primes_up_to_n def test_primes_up_to_50(): assert primes_up_to_n(50, [11, 2, 3, 15, 22, 29, 31, 40, 47, 51]) == [11, 2, 3, 29, 31, 47] def test_primes_up_to_20(): assert primes_up_to_n(20, [19, 12, 17, 4, 5, 6]) == [19, 17, 5] def test_primes_up_to_30(): assert primes_up_to_n(30, [30...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers from 'numbers' that are <= n.", "function_declaration": "def primes...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043211", "row_id": 43211, "seed_ids": "[1598]" }
0.728813
Code_Contests_43211
I
[ "is_prime", "primes_up_to_n" ]
2
[ [ "primes_up_to_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
737e684b2634624e29018b91bf31deba0201bed0
07b8a265744613a710011e20237ed3d220c432d5
v1.0
instruct
Code_Contests
Code_Contests_43224_I
Henry enjoys solving mathematical puzzles. He recently stumbled upon an interesting sequence of numbers called “super primes.” A super prime is a prime number whose index in the sequence of prime numbers is also a prime number. For instance, the number 3 is prime and it is the second prime number (index = 2, which is a...
def is_prime(num): if num < 2: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def nth_super_primes(n): primes = [] super_primes = [] i = 2 while len(super_primes) < n: if is_prime(i): primes...
from solution import nth_super_primes def test_nth_super_primes_5(): assert nth_super_primes(5) == [3, 5, 11, 17, 31] def test_nth_super_primes_10(): assert nth_super_primes(10) == [3, 5, 11, 17, 31, 41, 59, 67, 83, 109] def test_nth_super_primes_1(): assert nth_super_primes(1) == [3] def test_nth_super...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def nth_super_primes(n):", "function_name": "nth_super_primes", "parameter_list": "(n)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sympy\n\ndef first_n_super_primes(n):\n \"\"\"\n Returns the first n super primes.\n \"\"\"\n primes = list(sympy.primerange(1, 100000))...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043224", "row_id": 43224, "seed_ids": "[10250]" }
0.533942
Code_Contests_43224
I
[ "is_prime", "nth_super_primes" ]
2
[ [ "nth_super_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ca57c4aaab70c6f3647f85d2d9e5c5d43ad026e
22da48cc016fca3b811192b212d85b823c9a3091
v1.0
instruct
Code_Contests
Code_Contests_43375_I
You are given an issue of resource allocation among a network of cities. There are `C` cities connected by `R` bidirectional roads. Each road connects two cities and has a length associated with it. To facilitate travel and connectivity, the government has decided to build additional roads, such that the longest dist...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: p...
from solution import minimize_longest_distance def test_minimize_longest_distance_case_1(): C = 5 R = 5 roads = [ (1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 4, 4), (4, 5, 5) ] assert minimize_longest_distance(C, R, roads) == 5 def test_minimize_longest_distance_ca...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\n\ndef u...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00043375", "row_id": 43375, "seed_ids": "[8512]" }
0.773384
Code_Contests_43375
I
[ "find", "union", "kruskal_mst", "minimize_longest_distance" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimize_longest_distance", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
a2a31ea0e1c3d62e7797cdb833ac01b517cb951d
81ae226a13d8a27a2768eba256cc266b74dec63f
v1.0
instruct
Code_Contests
Code_Contests_43422_I
A delivery company needs to optimize its fleet management. Each vehicle in the fleet operates with a set mileage limit for fuel efficiency, after which it must return to the depot for refueling. Additionally, every vehicle can only carry a maximum load. Given the historical data of deliveries, the company wants to det...
def parse_input(input_string): lines = input_string.strip().split('\n') number_of_days, vehicle_mileage_limit = map(int, lines[0].split()) index = 1 deliveries = [] for _ in range(number_of_days): number_of_trips, number_of_deliveries = map(int, lines[index].split()) index += 1 ...
def test_parse_input(): input_string = "2 500\n3 2\n15 400\n10 300\n4 4\n20 200\n30 100\n25 150\n10 250\n" expected_output = (2, 500, [[(15, 400), (10, 300)], [(20, 200), (30, 100), (25, 150), (10, 250)]]) assert parse_input(input_string) == expected_output def test_calculate_trips_for_day(): assert ca...
[ { "docstring": null, "function_declaration": "def parse_input(input_string):", "function_name": "parse_input", "parameter_list": "(input_string)" }, { "docstring": null, "function_declaration": "def calculate_trips_for_day(vehicle_mileage_limit, day_deliveries):", "function_name": "c...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_minimum_trips(input_data):\n lines = input_data.strip().split('\\n')\n number_of_days, vehicle_mileage_limit = map(int, lines[0].split(...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00043422", "row_id": 43422, "seed_ids": "[8937]" }
0.736304
Code_Contests_43422
I
[ "parse_input", "calculate_trips_for_day", "optimize_fleet_management" ]
3
[ [ "optimize_fleet_management", "calculate_trips_for_day" ], [ "optimize_fleet_management", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
95124e038bae3a4512c127f9ddd8807729310b39
8b636565c2afb9f982de75cca209fed2a074b5aa
v1.0
instruct
Code_Contests
Code_Contests_43485_I
**Problem: Longest Path in a Directed Acyclic Graph (DAG)** Alex is analyzing a network represented as a Directed Acyclic Graph (DAG). Each node in the network represents a task and each directed edge represents a dependency between tasks. To optimize the network, Alex wants to find the longest path from any node to a...
from collections import defaultdict, deque def longest_path_in_dag(n, m, edges): def topological_sort(): in_degree = {i: 0 for i in range(1, n + 1)} for u, v in edges: in_degree[v] += 1 zero_in_degree_queue = deque([i for i in range(1, n + 1) if in_degree[i] == 0]) ...
from solution import compute_longest_path def test_sample1(): assert compute_longest_path(5, 6, [(1, 2), (2, 3), (1, 3), (1, 4), (4, 5), (3, 5)]) == 3 def test_sample2(): assert compute_longest_path(4, 3, [(1, 2), (2, 3), (3, 4)]) == 3 def test_no_edges(): assert compute_longest_path(3, 0, []) == 0 def ...
[ { "docstring": null, "function_declaration": "def longest_path_in_dag(n, m, edges):", "function_name": "longest_path_in_dag", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def compute_longest_path(n, m, edge_list):", "function_name": "compute_long...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef longest_path_in_dag(n, m, edges):\n def topological_sort():\n in_degree = [0] * (n + 1)\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00043485", "row_id": 43485, "seed_ids": "[8840]" }
0.693466
Code_Contests_43485
I
[ "longest_path_in_dag", "compute_longest_path" ]
2
[ [ "compute_longest_path", "longest_path_in_dag" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9dd4e2cd02ab218b048f7ac12505a3637209a03f
d68f591a284f08e83be9dded40ad045fb34c3cfb
v1.0
instruct
Code_Contests
Code_Contests_43550_I
An e-commerce website tracks the number of purchases made by users over consecutive days. Each day, the number of purchases each user makes is recorded. The website wants to identify trends in user activity to improve their service. For this purpose, it needs a program that determines the length of the longest increasi...
def length_of_LIS(purchases): """ Finds the length of the longest increasing subsequence in the given list of purchases. """ if not purchases: return 0 # Initialize dp array, where dp[i] indicates the length of LIS ending at index i dp = [1] * len(purchases) for i in range(...
from solution import length_of_LIS, longest_increasing_subsequences def test_length_of_LIS(): assert length_of_LIS([2, 1, 3, 5, 2, 6]) == 4 assert length_of_LIS([7, 4, 8, 3, 9]) == 3 assert length_of_LIS([1, 2, 3, 4, 5]) == 5 # strictly increasing sequence assert length_of_LIS([5, 4, 3, 2, 1]) ==...
[ { "docstring": "Finds the length of the longest increasing subsequence in the given list of purchases.", "function_declaration": "def length_of_LIS(purchases):", "function_name": "length_of_LIS", "parameter_list": "(purchases)" }, { "docstring": "Given the purchases data for multiple users, ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def length_of_LIS(purchases):\n \"\"\"\n Finds the length of the longest increasing subsequence in the given list of purchases.\n \"\"\"\n if n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00043550", "row_id": 43550, "seed_ids": "[6978]" }
0.676679
Code_Contests_43550
I
[ "length_of_LIS", "longest_increasing_subsequences" ]
2
[ [ "longest_increasing_subsequences", "length_of_LIS" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ed814bc6d7bd097ce5674347b4938705825216e
27a6958fbb351bc588d5dd195d4404e05027e42b
v1.0
instruct
Code_Contests
Code_Contests_43580_I
Given a matrix of integers, find the submatrix with the maximum sum. A submatrix is a rectangular portion of the matrix defined by a contiguous range of rows and columns. The sum of a submatrix is the sum of all elements within it. **Input** - The first line contains two integers, `n` and `m` (1 ≤ n, m ≤ 100), the n...
def max_submatrix_sum(matrix): """ Returns the maximum sum of any submatrix of the given matrix. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): row_sum = [0] * n for right in range(left, m): for i in range(n): ...
from solution import max_submatrix_sum def test_example_case_1(): matrix = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_submatrix_sum(matrix) == 29 def test_example_case_2(): matrix = [ [-1, -2, -3], [-4, -5...
[ { "docstring": "Returns the maximum sum of any submatrix of the given matrix.", "function_declaration": "def max_submatrix_sum(matrix):", "function_name": "max_submatrix_sum", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def kadane(arr):", "function_n...
[ 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 Given a matrix of integers, find the submatrix with the maximum sum.\n \"\"\"\n n = len(matrix)\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043580", "row_id": 43580, "seed_ids": "[3517]" }
0.677841
Code_Contests_43580
I
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
efbe33ff900a87800f0a770d2f29a3df200cb3fb
dcfad4a66f9e88400ddbb462f30be3d675f72b48
v1.0
instruct
Code_Contests
Code_Contests_43584_I
You are given an array of integers `nums`. Your task is to create a new array `result` where each element at index `i` contains the product of all the elements in `nums` except `nums[i]`. You cannot use division and must complete it in O(n) time. Input: - The first line contains an integer `t` (1 ≤ t ≤ 10^4) — the num...
def product_except_self(nums): """ Returns a list where each element at index i is the product of all the elements in the input list except nums[i]. """ n = len(nums) result = [1] * n # Calculate prefix multiplication prefix = 1 for i in range(n): result[i] = prefix ...
import pytest from solution import solve, parse_input, format_output def test_case_1(): input_data = "2\n3\n1 2 3\n4\n2 3 4 5" expected_output = "6 3 2\n60 40 30 24" test_cases = parse_input(input_data) results = solve(test_cases) output = format_output(results) assert output == expec...
[ { "docstring": "Returns a list where each element at index i is the product of all the elements in the input list except nums[i].", "function_declaration": "def product_except_self(nums):", "function_name": "product_except_self", "parameter_list": "(nums)" }, { "docstring": null, "functi...
[ 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 product_except_self(nums):\n \"\"\"\n Given a list of numbers, returns a list where each element at index i\n contains the product of all the ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043584", "row_id": 43584, "seed_ids": "[7002]" }
0.739112
Code_Contests_43584
I
[ "product_except_self", "solve", "parse_input", "format_output" ]
4
[ [ "solve", "product_except_self" ] ]
1
[ "parse_input", "format_output" ]
false
[]
false
pytest
true
[]
true
33b128cd39458f9199e9c33be4c11611da2d833a
6959827d55a5c49200968387321d67e616ed541a
v1.0
instruct
Code_Contests
Code_Contests_43610_I
You are given an array of integers. Your task is to determine if it is possible to split the array into two non-empty parts such that the sum of the elements in both parts is equal. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The f...
def can_partition_equal_sum(arr): total_sum = sum(arr) # If the total sum is odd, it can't be divided into two equal parts if total_sum % 2 != 0: return "NO" target = total_sum // 2 current_sum = 0 for num in arr: current_sum += num if current_sum == target...
import pytest from solution import split_array def test_example_case(): inputs = ["3", "5", "10 -5 2 5 -2", "4", "1 1 1 1", "3", "2 1 2"] expected = ["YES", "YES", "NO"] assert split_array(inputs) == expected def test_single_case_yes(): inputs = ["1", "4", "3 1 1 1"] expected = ["YES"] assert ...
[ { "docstring": null, "function_declaration": "def can_partition_equal_sum(arr):", "function_name": "can_partition_equal_sum", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def equal_sum_partitions(test_cases):", "function_name": "equal_sum_partitions", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_partition(array):\n \"\"\"\n Determines if it's possible to split the array into two non-empty parts with equal sums.\n \"\"\"\n total_...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043610", "row_id": 43610, "seed_ids": "[11460]" }
0.750933
Code_Contests_43610
I
[ "can_partition_equal_sum", "equal_sum_partitions", "split_array" ]
3
[ [ "equal_sum_partitions", "can_partition_equal_sum" ], [ "split_array", "equal_sum_partitions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
12825ef9a07d21090e8a9adcd2da33fefe6455ea
305a8a5e0412eb90a8f9a9c70534b774d7dbf47c
v1.0
instruct
Code_Contests
Code_Contests_43669_I
Alice is planning to build a string from a set of predefined words. She has a dictionary of words, and she knows the exact string `S` she wants to form. She can only use the words from her dictionary, and she can use each word multiple times. Alice wants to minimize the total number of words used to form the string `S`...
def min_words_to_form_string(S, words): """ Returns the minimum number of words required to form the string S using the words dictionary, or -1 if it's impossible. """ # Create a dp array where dp[i] represents the minimum number of words to form S[0:i] dp = [float('inf')] * (len(S) + 1) dp[...
import pytest from solution import min_words_solver, min_words_to_form_string def test_case_1(): input_str = "applepie\n3\napple\npie\nale" assert min_words_solver(input_str) == 2 def test_case_2(): input_str = "catdog\n2\ncat\ndog" assert min_words_solver(input_str) == 2 def test_case_3(): input...
[ { "docstring": "Returns the minimum number of words required to form the string S using the words dictionary,\nor -1 if it's impossible.", "function_declaration": "def min_words_to_form_string(S, words):", "function_name": "min_words_to_form_string", "parameter_list": "(S, words)" }, { "docs...
[ 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_words_to_form_string(S, n, dictionary):\n # Initialize a list to store the minimum number of words needed to form each prefix of S\n dp = [fl...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043669", "row_id": 43669, "seed_ids": "[7033]" }
0.741275
Code_Contests_43669
I
[ "min_words_to_form_string", "min_words_solver" ]
2
[ [ "min_words_solver", "min_words_to_form_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
51b4c8f039c15a91b324bea301eb109b2d492104
dbf4a3239ff7c3e1803d966c96c6412a30f7f687
v1.0
instruct
Code_Contests
Code_Contests_43676_I
Bob owns a farm with several plants arranged in a straight line. He wants to water his plants using an automatic watering system that utilizes pipes. The pipes are fixed in place and each pipe can water only a specific range of plants. The coverage of each pipe is given in terms of the start and end indices (inclusive)...
def min_pipes_to_water_plants(T, cases): results = [] for case in cases: P, L, pipes = case['P'], case['L'], case['pipes'] # Sort pipes based on starting index, then by ending index pipes.sort() num_pipes = 0 current_end = 0 idx = 0 ...
def test_min_pipes_to_water_plants(): data = """3 5 3 1 2 2 5 1 3 5 4 1 2 3 4 5 5 2 3 7 2 1 3 4 5""" expected = [2, 5, -1] assert solve(data) == expected data = """1 6 3 1 4 2 6 5 6""" expected = [1] assert solve(data) == expected data = """1 6 4 1 2 2 3 3 4 4 6""" expected = [3] a...
[ { "docstring": null, "function_declaration": "def min_pipes_to_water_plants(T, cases):", "function_name": "min_pipes_to_water_plants", "parameter_list": "(T, cases)" }, { "docstring": null, "function_declaration": "def parse_input_input(data):", "function_name": "parse_input_input", ...
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.125
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_pipes_to_water_plants(test_cases):\n results = []\n\n for plants, pipes, ranges in test_cases:\n ranges.sort()\n required_end =...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00043676", "row_id": 43676, "seed_ids": "[10104]" }
0.630576
Code_Contests_43676
I
[ "min_pipes_to_water_plants", "parse_input_input", "solve" ]
3
[ [ "solve", "min_pipes_to_water_plants" ], [ "solve", "parse_input_input" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8f73837852c588e66aee4406f619ed5b8898baaf
fdee254fcfa0be0f6d0181e8c440bf660b05c951
v1.0
instruct
Code_Contests
Code_Contests_43687_I
Given an array of N positive integers, you need to determine if there exists a non-empty subarray whose product is a perfect square. A subarray is a contiguous part of an array and a perfect square is an integer that is the square of an integer. Return "Yes" if there exists such a subarray, and "No" otherwise. Cons...
import math def has_perfect_square_subarray(N, arr): """ Determines if there exists a non-empty subarray whose product is a perfect square. Args: N : int : the number of elements in the array arr : list of int : the array of positive integers Returns: str : "Yes" if a subarra...
from solution import has_perfect_square_subarray, is_perfect_square def test_has_perfect_square_subarray_example1(): assert has_perfect_square_subarray(5, [1, 3, 9, 4, 2]) == "Yes" def test_has_perfect_square_subarray_example2(): assert has_perfect_square_subarray(4, [2, 3, 5, 7]) == "No" def test_has_perfec...
[ { "docstring": "Determines if there exists a non-empty subarray \nwhose product is a perfect square.\n\nArgs:\nN : int : the number of elements in the array\narr : list of int : the array of positive integers\n\nReturns:\nstr : \"Yes\" if a subarray whose product is a perfect square exists, otherwise \"No\"", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_perfect_square(x):\n \"\"\"\n Check if x is a perfect square.\n \"\"\"\n return int(x ** 0.5) ** 2 == x\n\ndef has_perfect_square_subarr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043687", "row_id": 43687, "seed_ids": "[7790]" }
0.632581
Code_Contests_43687
I
[ "has_perfect_square_subarray", "is_perfect_square" ]
2
[ [ "has_perfect_square_subarray", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67d8f85a31750ccda65db3024e1fc3c0757cde11
adaee4d62d145ae65e82d046793d8217bc2262a9
v1.0
instruct
Code_Contests
Code_Contests_43727_I
You are given a list of strings, where each string represents a sequence of characters. Your task is to determine the longest substring of distinct characters for each string in the list. If there are multiple substrings with the same length, return the first occurring one. Input The first line contains an integer n ...
def longest_distinct_substring(s): """ This function returns the longest substring of distinct characters for the given string s. """ n = len(s) longest_substr = "" start = 0 seen = {} for end in range(n): if s[end] in seen: start = max(start, seen[s[end]] + 1) ...
from solution import longest_distinct_substring, process_strings def test_longest_distinct_substring_all_unique(): assert longest_distinct_substring("abcdef") == "abcdef" def test_longest_distinct_substring_repeated_characters(): assert longest_distinct_substring("bbbbb") == "b" def test_longest_distinct_sub...
[ { "docstring": "This function returns the longest substring of distinct characters for the given string s.", "function_declaration": "def longest_distinct_substring(s):", "function_name": "longest_distinct_substring", "parameter_list": "(s)" }, { "docstring": "Given a list of strings, return...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_distinct_substring(s):\n \"\"\"\n Given a string s, returns the longest substring with all distinct characters.\n \"\"\"\n n = len(...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043727", "row_id": 43727, "seed_ids": "[12767]" }
0.792845
Code_Contests_43727
I
[ "longest_distinct_substring", "process_strings" ]
2
[ [ "process_strings", "longest_distinct_substring" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dd59cade87f8ca17e077bdf425688429d26b7590
f8f8efa82b076a30750694df9478710a6d1ba83f
v1.0
instruct
Code_Contests
Code_Contests_43731_I
You are given a large number, and you need to determine whether it is a palindrome. A number is a palindrome if it reads the same forwards and backwards. However, this number can get very large, and you might need to check multiple such numbers in a short amount of time. Write a program to check if given numbers are ...
def is_palindrome(n): """ Check if the given string representation of a number is a palindrome. """ return n == n[::-1] def check_palindromes(numbers): """ Given a list of numbers in string format, check if each one is a palindrome. """ results = [] for number in numbers: if...
from solution import check_palindromes def test_basic_cases(): assert check_palindromes(["123", "121", "1001"]) == ["NO", "YES", "YES"] def test_single_digit_numbers(): assert check_palindromes(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) == ["YES"] * 9 def test_larger_numbers(): assert check_palindrom...
[ { "docstring": "Check if the given string representation of a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Given a list of numbers in string format, check if each one is a palindrome.",...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(num_str):\n \"\"\"\n Check if the given string representation of a number is a palindrome.\n \n Parameters:\n num_str (str...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043731", "row_id": 43731, "seed_ids": "[7985]" }
0.745845
Code_Contests_43731
I
[ "is_palindrome", "check_palindromes" ]
2
[ [ "check_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a9c15f3894163550c54e5263dee6d195a98a5b5
8b91ffbe20d9eb457acf84694bf2e317775d7270
v1.0
instruct
Code_Contests
Code_Contests_43736_I
Alice is learning about numerical operations and she is fascinated by the concept of palindromic numbers. A palindromic number is a number that remains the same when its digits are reversed. Alice wants to write a program to count how many numbers in a given range [L, R] are palindromic. Help Alice by writing a progra...
def is_palindromic(number): """ Helper function to check if a number is palindromic. """ return str(number) == str(number)[::-1] def count_palindromic_numbers(L, R): """ Returns the count of palindromic numbers in the inclusive range [L, R]. """ count = 0 for num in range(L, R + 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(22) == True assert is_palindromic(10) == False def test_count_palindromic_numbers_...
[ { "docstring": "Helper function to 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 in the inclusive range [L, R].", "func...
[ 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 count_palindromic_numbers(L, R):\n \"\"\"\n Returns the count of palindromic numbers in the inclusive range [L, R].\n \"\"\"\n count = 0\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043736", "row_id": 43736, "seed_ids": "[1425]" }
0.716511
Code_Contests_43736
I
[ "is_palindromic", "count_palindromic_numbers" ]
2
[ [ "count_palindromic_numbers", "is_palindromic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9f1db0388affa55a0734c30d881fca905852870
03fccae50d2fcc49f34033278eaf15110785db1c
v1.0
instruct
Code_Contests
Code_Contests_43756_I
A veterinarian clinic is managing their appointments for various pets. Each pet is characterized by their species and a unique identification number. The clinic runs on a schedule represented by a grid, where each cell corresponds to a time slot available for an appointment. The rows represent the hours in a day (for e...
def update_appointment_grid(m, n, grid, pets): """ Updates the given species-booking grid with appointment slots marked by pet ids. """ for species, pet_id, row, col in pets: if grid[row][col] == species: grid[row][col] = str(pet_id) else: print(f'Booking failed f...
from solution import process_appointments def test_basic_functionality(): assert process_appointments(3, 5, ["A....", "AA..B", "....B"], 3, [('A', 101, 1, 0), ('B', 202, 1, 4), ('A', 303, 0, 1)]) == None def test_booking_conflict(): assert process_appointments(2, 3, [".C.", ".C."], 2, [('C', 101, 0, 1), ('C',...
[ { "docstring": "Updates the given species-booking grid with appointment slots marked by pet ids.", "function_declaration": "def update_appointment_grid(m, n, grid, pets):", "function_name": "update_appointment_grid", "parameter_list": "(m, n, grid, pets)" }, { "docstring": null, "functio...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def update_appointment_grid(m, n, grid, pets):\n \"\"\"\n Updates the given species-booking grid with appointment slots marked by pet ids.\n \"\"\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00043756", "row_id": 43756, "seed_ids": "[8764]" }
0.589626
Code_Contests_43756
I
[ "update_appointment_grid", "process_appointments" ]
2
[ [ "process_appointments", "update_appointment_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
227578918ff7b9835eb3ae462fcaafad88a1a950
b2cf286713d956a2716d70d4fe33cdee8aaa57f9
v1.0
instruct
Code_Contests
Code_Contests_43770_I
You are organizing a party and need to arrange seating for your guests. Given a list of guests, you need to assign them to tables such that no guest is left without a seat. Each table has a capacity limit for the number of guests. The goal is to minimize the number of tables used while ensuring everyone has a seat. W...
def min_tables_requirement(guests, capacity): guests.sort(reverse=True) tables = 0 available = [capacity] * len(guests) for guest in guests: for idx in range(tables): if available[idx] >= guest: available[idx] -= guest break else: ...
from solution import min_tables_requirement, process_datasets, parse_inputs, produce_outputs def test_min_tables_requirement(): assert min_tables_requirement([1, 2, 1, 2, 1, 2], 3) == 3 assert min_tables_requirement([3, 3, 3, 3, 3], 1) == 5 assert min_tables_requirement([1, 1, 1, 1], 2) == 2 assert min...
[ { "docstring": null, "function_declaration": "def min_tables_requirement(guests, capacity):", "function_name": "min_tables_requirement", "parameter_list": "(guests, capacity)" }, { "docstring": null, "function_declaration": "def process_datasets(datasets):", "function_name": "process...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_tables_required(guests, capacity):\n \"\"\"\n Returns the minimum number of tables required to seat all guests given their seating requiremen...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00043770", "row_id": 43770, "seed_ids": "[11546]" }
0.607375
Code_Contests_43770
I
[ "min_tables_requirement", "process_datasets", "parse_inputs", "produce_outputs" ]
4
[ [ "process_datasets", "min_tables_requirement" ] ]
1
[ "process_datasets", "parse_inputs" ]
false
[]
false
pytest
true
[]
true
a3f98a6d5b32f0392e46db62112fc2d98d8fc9a2
97f9beaf0fcd3eef2c2d71f69016e4c4cd31e6e4
v1.0
instruct
Code_Contests
Code_Contests_43854_I
You are given an integer N. Your task is to generate an N-by-N grid of integers that satisfies the conditions below: 1. All integers in the grid must be between 1 and 10^9, inclusive. 2. Each integer in the grid must be unique. 3. The sum of the elements in any row or column must be odd. It is guaranteed that a solut...
def generate_unique_grid(N): """ Generates an N x N grid of unique numbers between 1 and 10^9 such that each row and column sum to an odd number. """ grid = [[0] * N for _ in range(N)] current_number = 1 for i in range(N): for j in range(N): grid[i][j] = current_number ...
from solution import generate_odd_sum_unique_grid def test_generate_odd_sum_unique_grid_1(): N = 1 grid = generate_odd_sum_unique_grid(N) assert len(grid) == N assert len(grid[0]) == N assert sum(grid[0]) % 2 == 1 # row sum should be odd assert sum(grid[i][0] for i in range(N)) % 2 == 1 # col...
[ { "docstring": "Generates an N x N grid of unique numbers between 1 and 10^9 such that each row and column sum to an odd number.", "function_declaration": "def generate_unique_grid(N):", "function_name": "generate_unique_grid", "parameter_list": "(N)" }, { "docstring": "Adjusts the grid to s...
[ 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 generate_odd_sum_grid(N):\n \"\"\"\n Generate an N-by-N grid where the sum of elements in any row or column is odd.\n \"\"\"\n grid = []\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00043854", "row_id": 43854, "seed_ids": "[4459]" }
0.713512
Code_Contests_43854
I
[ "generate_unique_grid", "make_sums_odd", "generate_odd_sum_unique_grid", "main" ]
4
[ [ "generate_odd_sum_unique_grid", "generate_unique_grid" ], [ "generate_odd_sum_unique_grid", "make_sums_odd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6bae6ba726b63399e7d3f3f0c536432323befeee
6a5ec24584ba288035ce82fdcc11b70d157a07fc
v1.0
instruct
Code_Contests
Code_Contests_43873_I
**Railway Network** To improve the efficiency of the railway system, a railway company wants to analyze and possibly redesign their railway network. The network is represented as an undirected graph where nodes represent railway stations and edges represent the railway tracks between the stations. Each track has a cer...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_simple_case(): assert max_spanning_tree(4, 5, [(1, 2, 3), (1, 3, 4), (2, 3, 2), (3, 4, 5), (2, 4, 1)]) == [(3, 4), (1, 3), (1, 2)] def test_single_edge(): assert max_spanning_tree(2, 1, [(1, 2, 10)]) == [(1, 2)] def test_disconnected_graph(): assert max_spanning_tree(3, 1, [(1, 2, 10)]) == [(1, 2...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043873", "row_id": 43873, "seed_ids": "[7973]" }
0.678157
Code_Contests_43873
I
[ "find", "union", "kruskal_max_spanning_tree", "max_spanning_tree" ]
4
[ [ "kruskal_max_spanning_tree", "find" ], [ "kruskal_max_spanning_tree", "union" ], [ "max_spanning_tree", "kruskal_max_spanning_tree" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
b6e5d16ca3c6ef5fd35e082adeb3d8cc02a11e04
4b54ca5e7c5dba0184347e8dc24863a5430cd300
v1.0
instruct
Code_Contests
Code_Contests_43881_I
Given an array a1, a2, ..., an of n integers, find the smallest number in the array that is a prime number. A number x is said to be a prime number if it is greater than 1 and has no divisors other than 1 and itself. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the arra...
def is_prime(x): """ Returns True if x is a prime number, otherwise False. """ if x <= 1: return False if x == 2: return True if x % 2 == 0: return False for i in range(3, int(x**0.5) + 1, 2): if x % i == 0: return False return True def smalle...
from solution import is_prime, smallest_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-7) == Fa...
[ { "docstring": "Returns True if x is a prime number, otherwise False.", "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": "Returns the smallest prime number in the array.", "function_declaration": "def smallest_prime(arr):"...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "def is_prime(x):\n \"\"\"\n Returns True if x is a prime number, otherwise False.\n \"\"\"\n if x <= 1:\n retur...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00043881", "row_id": 43881, "seed_ids": "[3606]" }
0.72916
Code_Contests_43881
I
[ "is_prime", "smallest_prime" ]
2
[ [ "smallest_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3fce3a676b405504cc2f875076ed35cd6d4aaa26
155eecc3ac870d267b0bb77d509fb87890d9e80d
v1.0
instruct
Code_Contests
Code_Contests_43885_I
A prime number is a number greater than 1 with no divisors other than 1 and itself. Your task is to find the smallest prime number `p` that is greater than a given number `x`. Input A single integer `x` (1 ≤ x ≤ 10^9). Output A single integer `p`, the smallest prime number that is greater than `x`. Examples Input...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i +...
from solution import next_prime def test_next_prime(): assert next_prime(10) == 11 assert next_prime(100) == 101 assert next_prime(20) == 23 assert next_prime(1) == 2 assert next_prime(2) == 3 assert next_prime(13) == 17 assert next_prime(29) == 31 assert next_prime(998) == 1009 def te...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds the smallest prime number greater than x.", "function_declaration": "def next_prime(x):", "functi...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00043885", "row_id": 43885, "seed_ids": "[4205]" }
0.554806
Code_Contests_43885
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f69425fc100e6dd61abaad962c1ef55949cab87
629f07d1760e54232783f7631dcfe9a3a34d367e
v1.0
instruct
Code_Contests
Code_Contests_43892_I
Given a set of n triplets, where each triplet contains three numbers representing the XYZ coordinates. Your task is to determine the number of collinear points among these triplets. Two or more points are collinear if they lie on a single straight line. Input The first line of the input contains an integer n (2 ≤ n ≤...
def gcd(a, b): while b: a, b = b, a % b return a def are_collinear(p1, p2, p3): x1, y1, z1 = p1 x2, y2, z2 = p2 x3, y3, z3 = p3 return (x2 - x1)*(y3 - y1) == (y2 - y1)*(x3 - x1) and (x2 - x1)*(z3 - z1) == (z2 - z1)*(x3 - x1) and (y2 - y1)*(z3 - z1) == (z2 - z1)*(y3 - y1) def max_collin...
def test_max_collinear_points_case1(): points = [(1, 2, 3), (2, 4, 6), (3, 6, 9), (4, 8, 10)] assert max_collinear_points(points) == 3 def test_max_collinear_points_case2(): points = [(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 6, 7)] assert max_collinear_points(points) == 4 def test_max_collinear...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def are_collinear(p1, p2, p3):", "function_name": "are_collinear", "parameter_list": "(p1, p2, p3)" }, { "doc...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_collinear_points(triplets):\n from itertools import combinations\n from collections import defaultdict\n\n def are_collinear(p1, p2, p3):\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043892", "row_id": 43892, "seed_ids": "[887]" }
0.637904
Code_Contests_43892
I
[ "gcd", "are_collinear", "max_collinear_points" ]
3
[ [ "max_collinear_points", "are_collinear" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c9375d46bcb5c11eef7f5ee524ef1429a47a6c84
d1f7500b7bc251d81c8b94a31a0879854746957a
v1.0
instruct
Code_Contests
Code_Contests_43912_I
Given n points in a 2D plane, your task is to determine if there exists a subset of these points whose convex hull has exactly k vertices. A convex hull of a set of points is the smallest convex polygon that can enclose all the points. For example, given points that form a "star" shape, the convex hull would be the ou...
from itertools import combinations from math import atan2 def convex_hull(points): points = sorted(points, key=lambda p: (p[0], p[1])) def cross(o, a, b): return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) lower = [] for p in points: while len(lower) >= 2 and cross(l...
from solution import find_convex_hull_with_k_vertices def test_example_1(): n = 5 k = 3 points = [(0, 0), (1, 0), (0, 1), (1, 1), (2, 2)] result = find_convex_hull_with_k_vertices(n, k, points) assert result.startswith("YES") def test_example_2(): n = 4 k = 4 points = [(0, 0), (1, 0), ...
[ { "docstring": null, "function_declaration": "def convex_hull(points):", "function_name": "convex_hull", "parameter_list": "(points)" }, { "docstring": null, "function_declaration": "def find_convex_hull_with_k_vertices(n, k, points):", "function_name": "find_convex_hull_with_k_verti...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nfrom scipy.spatial import ConvexHull\n\ndef find_convex_hull_subset(n, k, points):\n # Check if it is possible to form a subset of k v...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043912", "row_id": 43912, "seed_ids": "[12766]" }
0.568338
Code_Contests_43912
I
[ "convex_hull", "find_convex_hull_with_k_vertices" ]
2
[ [ "find_convex_hull_with_k_vertices", "convex_hull" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1aeede1edba552f7f1beb4dd5d7cc70fc5ec44a3
0f667bcecc154be7e733b7371270d369ef5ee28c
v1.0
instruct
Code_Contests
Code_Contests_43957_I
The Fibonacci sequence is a famous and simple example of a series of numbers where every number after the first two is the sum of the two preceding ones. Given this, we can extend the Fibonacci sequence to a generalized Fibonacci sequence where you are given the first two numbers F1 and F2, and you are required to find...
MOD = 1000000007 def generalized_fibonacci(F1, F2, n): if n == 1: return F1 % MOD elif n == 2: return F2 % MOD dp = [0] * (n + 1) dp[1] = F1 dp[2] = F2 for i in range(3, n + 1): dp[i] = (dp[i-1] + dp[i-2]) % MOD return dp[n] def solve_generalized_...
from solution import generalized_fibonacci, solve_generalized_fibonacci def test_case1(): assert generalized_fibonacci(1, 1, 5) == 5 def test_case2(): assert generalized_fibonacci(3, 7, 4) == 17 def test_case3(): assert generalized_fibonacci(0, 1, 10) == 34 def test_case4(): assert generalized_fibon...
[ { "docstring": null, "function_declaration": "def generalized_fibonacci(F1, F2, n):", "function_name": "generalized_fibonacci", "parameter_list": "(F1, F2, n)" }, { "docstring": null, "function_declaration": "def solve_generalized_fibonacci(test_cases):", "function_name": "solve_gene...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "MOD = 1000000007\n\ndef generalized_fibonacci(F1, F2, n):\n if n == 1:\n return F1 % MOD\n elif n == 2:\n return F2 % MOD\n \n dp...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00043957", "row_id": 43957, "seed_ids": "[6006]" }
0.692141
Code_Contests_43957
I
[ "generalized_fibonacci", "solve_generalized_fibonacci", "read_input" ]
3
[ [ "solve_generalized_fibonacci", "generalized_fibonacci" ] ]
1
[ "read_input" ]
false
[]
false
pytest
true
[]
true
d2b5f4a48b996820a561469f990683b9f3e68255
761f6cd45640e7062facd9ab3b3ac2c3371e75f3
v1.0
instruct
Code_Contests
Code_Contests_43995_I
A palindrome is a word, number, phrase, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). For this coding task, you need to determine whether the given string is a valid palindrome by considering only alphanumeric characters and ignoring cases. ...
import re def is_valid_palindrome(s): """ Check if a given string s is a valid palindrome by considering only alphanumeric characters and ignoring cases. """ # Remove non-alphanumeric characters and convert to lowercase filtered_s = re.sub(r'[^a-zA-Z0-9]', '', s).lower() # Check if the filt...
import pytest from solution import process_palindromes def test_process_palindromes_basic(): t = 4 strings = [ "A man, a plan, a canal, Panama", "race a car", "Madam In Eden, I'm Adam", "No lemon, no melon" ] expected = ["Yes", "No", "Yes", "Yes"] assert process_pali...
[ { "docstring": "Check if a given string s is a valid palindrome by considering only\nalphanumeric characters and ignoring cases.", "function_declaration": "def is_valid_palindrome(s):", "function_name": "is_valid_palindrome", "parameter_list": "(s)" }, { "docstring": "Process a list of strin...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_palindrome(s):\n \"\"\"\n Returns 'Yes' if the given string s is a valid palindrome, otherwise returns 'No'.\n \"\"\"\n # Remove n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00043995", "row_id": 43995, "seed_ids": "[5001]" }
0.773585
Code_Contests_43995
I
[ "is_valid_palindrome", "process_palindromes" ]
2
[ [ "process_palindromes", "is_valid_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae334aaaeede7341e1b29bd2f4b4918c2892edae
509db9e4afe8c44cf2f593eef188ad5cb9e805af
v1.0
instruct
Code_Contests
Code_Contests_44031_I
A group of friends wants to purchase a series of cinema tickets online. They care about sitting together but are flexible regarding the order of tickets they buy. The website offers a grid-like seating layout, where each seat is either available ('A') or sold ('S'). Given that they always buy in such a way that they si...
def find_minimum_blocks(seating, R, C, K): def can_seat_block(row, col, dr, dc, K): for i in range(K): nr, nc = row + i * dr, col + i * dc if nr < 0 or nr >= R or nc < 0 or nc >= C or seating[nr][nc] == 'S': return False return True def check_all_blocks()...
from solution import parse_input, minimum_blocks_to_seat_groups def test_example_case(): input_str = "4 4 3\nA S A A\nA A S S\nA A A A\nS S A S\n3 4 2\nA S A A\nA A S S\nA A A S\n0" data_sets = parse_input(input_str) assert minimum_blocks_to_seat_groups(data_sets) == [1, 1] def test_no_available_blocks():...
[ { "docstring": null, "function_declaration": "def find_minimum_blocks(seating, R, C, K):", "function_name": "find_minimum_blocks", "parameter_list": "(seating, R, C, K)" }, { "docstring": null, "function_declaration": "def minimum_blocks_to_seat_groups(data_sets):", "function_name": ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_minimum_blocks(seating, R, C, K):\n def can_seat_block(row, col, dr, dc, K):\n for i in range(K):\n nr, nc = row + i * dr, co...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044031", "row_id": 44031, "seed_ids": "[4780]" }
0.592919
Code_Contests_44031
I
[ "find_minimum_blocks", "minimum_blocks_to_seat_groups", "parse_input" ]
3
[ [ "minimum_blocks_to_seat_groups", "find_minimum_blocks" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
6ca07954df36a494021f7ad2120192e7286e026b
16c62d4a587b8e2a0389d30eff32b23fdfd46d81
v1.0
instruct
Code_Contests
Code_Contests_44057_I
A large research laboratory is trying to optimize the workflow in one of its core departments. Each department in the lab consists of several interconnected rooms, which can be represented as nodes in a graph. The connections between rooms represent possible paths for scientists to move from one room to another, and th...
import heapq from collections import defaultdict, deque def find(parent, i): if parent[i] == i: return i else: root = find(parent, parent[i]) parent[i] = root return root def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x...
def test_min_diameter_spanning_tree(): M = 5 N = 6 edges = [ (0, 1, 3), (0, 2, 2), (1, 2, 4), (1, 3, 7), (2, 4, 1), (3, 4, 6) ] assert min_diameter_spanning_tree(M, N, edges) == 6 def test_single_edge(): M = 2 N = 1 edges = [ ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.143
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport itertools\n\nclass UnionFind:\n def __init__(self, size):\n self.root = list(range(size))\n self.rank = [1] * size\n\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00044057", "row_id": 44057, "seed_ids": "[12566]" }
0.667247
Code_Contests_44057
I
[ "find", "union", "kruskal", "bfs", "min_diameter_spanning_tree", "main" ]
6
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "min_diameter_spanning_tree", "bfs" ], [ "min_diameter_spanning_tree", "kruskal" ], [ "union", "find" ] ]
5
[]
false
[]
false
pytest
false
[]
true
218ac383512008593518bb81464f06a52c259037
cccd1ef81bbe1e7645f589b0f6a606be9e774c02
v1.0
instruct
Code_Contests
Code_Contests_44063_I
You are given a robot that is situated inside a rectangular grid of size n x m. The robot can move left, right, up, or down, but it is unable to visit the same cell more than once. The robot starts at the top-left corner of the grid (cell (1, 1)) and its goal is to reach the bottom-right corner (cell (n, m)). The grid...
def find_path(grid, n, m): directions = [(0, 1, 'R'), (1, 0, 'D'), (0, -1, 'L'), (-1, 0, 'U')] def is_valid(x, y): return 0 <= x < n and 0 <= y < m and grid[x][y] == '.' def dfs(x, y, path): if not is_valid(x, y): return False if (x, y) == (n-1, m-1): re...
def test_robot_grid_example_1(): n, m = 4, 4 grid = [ ['.', '.', '.', '.'], ['.', '#', '.', '.'], ['.', '.', '#', '.'], ['.', '.', '.', '.'] ] result = find_path(grid, n, m) assert result[0] == "Yes" def test_robot_grid_example_2(): n, m = 3, 3 grid = [ ...
[ { "docstring": null, "function_declaration": "def find_path(grid, n, m):", "function_name": "find_path", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def robot_grid(n, m, grid):", "function_name": "robot_grid", "parameter_list": "(n, m, grid)"...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_path(grid, n, m):\n directions = [(0, 1, 'R'), (1, 0, 'D'), (0, -1, 'L'), (-1, 0, 'U')]\n \n def is_valid(x, y):\n return 0 <= x <...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044063", "row_id": 44063, "seed_ids": "[2137]" }
0.754729
Code_Contests_44063
I
[ "find_path", "robot_grid" ]
2
[ [ "robot_grid", "find_path" ] ]
1
[]
false
[]
false
pytest
false
[]
true
aaa0cd8576704719a1431e50789248acc6fc5ec2
f63d9f81991703a3635bea7d8d3fed39069148ce
v1.0
instruct
Code_Contests
Code_Contests_44104_I
Design a function to rotate a given square matrix clockwise by 90 degrees. **Input** The first line of the input contains an integer n (1 ≤ n ≤ 100), the size of the square matrix. The next n lines contain n integers each, denoting the matrix elements. **Output** Output the matrix rotated clockwise by 90 degrees i...
def rotate_matrix_clockwise(matrix): """ Rotates a given n x n matrix clockwise by 90 degrees. :param matrix: List of lists representing the n x n matrix :return: New n x n matrix rotated clockwise by 90 degrees """ n = len(matrix) rotated_matrix = [[0] * n for _ in range(n)] for i...
def test_rotate_3x3_matrix(): input_matrix = '''3 1 2 3 4 5 6 7 8 9''' expected_output = '''7 4 1 8 5 2 9 6 3''' assert rotate_matrix(input_matrix) == expected_output def test_rotate_4x4_matrix(): input_matrix = '''4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16''' expected_output = '''13 9 5 1 14 10 6 2 ...
[ { "docstring": "Rotates a given n x n matrix clockwise by 90 degrees.\n\n:param matrix: List of lists representing the n x n matrix\n:return: New n x n matrix rotated clockwise by 90 degrees", "function_declaration": "def rotate_matrix_clockwise(matrix):", "function_name": "rotate_matrix_clockwise", ...
[ 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 rotate_90_clockwise(matrix):\n \"\"\"\n Rotates a given square matrix clockwise by 90 degrees.\n \n Args:\n matrix (list of list of int)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044104", "row_id": 44104, "seed_ids": "[11892]" }
0.600231
Code_Contests_44104
I
[ "rotate_matrix_clockwise", "read_matrix_input", "matrix_to_string", "rotate_matrix" ]
4
[ [ "rotate_matrix", "matrix_to_string" ], [ "rotate_matrix", "read_matrix_input" ], [ "rotate_matrix", "rotate_matrix_clockwise" ] ]
3
[]
false
[]
false
pytest
false
[]
true
a2dcf55b75ddb1aaefcadf7d9015b17af7f20eb9
1b460e6740351866b2e4713b5f8739180543bf46
v1.0
instruct
Code_Contests
Code_Contests_44158_I
Given a number n and n strings, determine if the given strings are valid hexadecimal color codes. A valid hexadecimal color code starts with a "#" followed by exactly 6 characters that can be digits (0-9) or letters (a-f, A-F). Input: - First line contains an integer n (1 ≤ n ≤ 100). - Next n lines each contain a st...
def is_valid_hex_color(code: str) -> str: """ Determines if a given string is a valid hexadecimal color code. Parameters: code (str): The string to validate. Returns: str: "VALID" if the string is a valid hex color code, "INVALID" otherwise. """ if len(code) != 7 or code[0] != ...
def test_is_valid_hex_color(): assert is_valid_hex_color("#1f1f1F") == "VALID" assert is_valid_hex_color("#Z12ZZZ") == "INVALID" assert is_valid_hex_color("#ABC123") == "VALID" assert is_valid_hex_color("#12abCK") == "INVALID" assert is_valid_hex_color("#aBcDeF") == "VALID" assert is_valid_hex_c...
[ { "docstring": "Determines if a given string is a valid hexadecimal color code.\n\nParameters:\ncode (str): The string to validate.\n\nReturns:\nstr: \"VALID\" if the string is a valid hex color code, \"INVALID\" otherwise.", "function_declaration": "def is_valid_hex_color(code):", "function_name": "is_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef validate_hex_color_codes(n, color_codes):\n \"\"\"\n Checks if the given strings are valid hexadecimal color codes.\n\n Parameter...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044158", "row_id": 44158, "seed_ids": "[3821]" }
0.521693
Code_Contests_44158
I
[ "is_valid_hex_color", "check_hex_codes" ]
2
[ [ "check_hex_codes", "is_valid_hex_color" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fbb019a85c1dc4e779bb9f38699738f7d419cbb5
e978acc13c94efc6c8fc0e9ccf2b7ef7ea03b7e9
v1.0
instruct
Code_Contests
Code_Contests_44169_I
You are given a binary tree with N nodes. Each node has a unique value between 1 and N. Determine if this binary tree is a height-balanced binary tree. A binary tree is height-balanced if for each node in the tree, the difference in the height of its left and right subtrees is at most 1. Constraints - The number of n...
class TreeNode: def __init__(self, val=0): self.val = val self.left = None self.right = None def build_tree(N, parents): nodes = [TreeNode(i) for i in range(1, N+1)] root = None for i, p in enumerate(parents): if p == -1: root = nodes[i] else: ...
from solution import is_balanced_binary_tree def test_balanced_tree_example_one(): assert is_balanced_binary_tree(5, [-1, 1, 1, 2, 2]) == "Yes" def test_unbalanced_tree_example_two(): assert is_balanced_binary_tree(3, [-1, 1, 2]) == "No" def test_single_node_tree(): assert is_balanced_binary_tree(1, [-1]...
[]
[ 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, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef build_tree(parents):\n nod...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044169", "row_id": 44169, "seed_ids": "[8411]" }
0.71925
Code_Contests_44169
I
[ "build_tree", "check_balanced_tree", "is_balanced_binary_tree" ]
3
[ [ "is_balanced_binary_tree", "build_tree" ], [ "is_balanced_binary_tree", "check_balanced_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
870023e46f5b41081a4241b9beb411cf3ad69743
137b10ec9e5b506b69bad8c72229011dadb22da4
v1.0
instruct
Code_Contests
Code_Contests_44228_I
Karan is fascinated by prime numbers and their arrangement in arrays. He gives you an array of size N and asks you to perform certain operations on it based on the provided queries to help him understand prime positions better. The array of size N contains positive integers. Each query contains two integers: `L` and `...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def preprocess_primes(arr): prime_count = ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False def test_preprocess_primes(): arr = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] prime_count = preprocess_primes(arr) assert prime_count == ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def preprocess_primes(arr):", "function_name": "preprocess_primes", "parameter_list": "(arr)" }, { "docst...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044228", "row_id": 44228, "seed_ids": "[10797]" }
0.67216
Code_Contests_44228
I
[ "is_prime", "preprocess_primes", "answer_queries", "prime_numbers_in_ranges" ]
4
[ [ "preprocess_primes", "is_prime" ], [ "prime_numbers_in_ranges", "answer_queries" ], [ "prime_numbers_in_ranges", "preprocess_primes" ] ]
3
[]
false
[]
false
pytest
false
[]
true
ee57b6227f1d0d930be67532ad098362aef04e34
7391bb007a991066506a23583b5c5ec11ea61060
v1.0
instruct
Code_Contests
Code_Contests_44240_I
Alice has a list of words and needs to find the longest word that can be formed by deleting some characters of another given string without reordering the remaining characters. She reached out to you for help in writing a program to accomplish this task. Given a list of words and a target string, find the longest word...
def is_subsequence(target, word): """ Check if the word is a subsequence of target. """ it = iter(target) return all(char in it for char in word) def longest_word_from_target(target, words): """ Find the longest word in the list that can be formed by deleting some characters of the target s...
def test_is_subsequence(): assert is_subsequence("abpcplea", "apple") == True assert is_subsequence("abpcplea", "plea") == True assert is_subsequence("abpcplea", "monkey") == False assert is_subsequence("abpcplea", "applz") == False def test_longest_word_from_target(): assert longest_word_from_targ...
[ { "docstring": "Check if the word is a subsequence of target.", "function_declaration": "def is_subsequence(target, word):", "function_name": "is_subsequence", "parameter_list": "(target, word)" }, { "docstring": "Find the longest word in the list that can be formed by deleting some characte...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(target, word):\n it = iter(target)\n return all(char in it for char in word)\n\ndef find_longest_word(target, words):\n longest...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044240", "row_id": 44240, "seed_ids": "[3721]" }
0.72273
Code_Contests_44240
I
[ "is_subsequence", "longest_word_from_target", "process_test_cases", "handle_input_output" ]
4
[ [ "handle_input_output", "process_test_cases" ], [ "longest_word_from_target", "is_subsequence" ], [ "process_test_cases", "longest_word_from_target" ] ]
3
[ "process_test_cases", "handle_input_output" ]
false
[]
false
pytest
true
[]
true
da59a3ab88c8ab8a338a76c357817a405b9c5199
4bc4d4fdb17a64f01426e94ba73c5322e7dd6848
v1.0
instruct
Code_Contests
Code_Contests_44250_I
You are given a string S consisting of lowercase English letters. Your task is to determine the length of the longest palindromic substring that can be obtained from S by deleting at most one character. A string is called a palindrome if it reads the same forward and backward. Constraints * 1 \leq |S| \leq 100 * S ...
def is_palindrome(s): return s == s[::-1] def longest_palindromic_substring_len(s): n = len(s) if is_palindrome(s): return n max_len = 0 for i in range(n): temp = s[:i] + s[i+1:] if is_palindrome(temp): max_len = max(max_len, n - 1) if ...
from solution import longest_palindromic_substring_len def test_palindromic_without_removing_anything(): assert longest_palindromic_substring_len("aaaa") == 4 def test_palindromic_by_removing_one(): assert longest_palindromic_substring_len("abca") == 3 def test_palindromic_with_no_good_scenario(): assert...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def longest_palindromic_substring_len(s):", "function_name": "longest_palindromic_substring_len", "para...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_substring_with_one_deletion(s):\n \"\"\"\n Returns the length of the longest palindromic substring that can be obtained by de...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044250", "row_id": 44250, "seed_ids": "[10810]" }
0.886236
Code_Contests_44250
I
[ "is_palindrome", "longest_palindromic_substring_len" ]
2
[ [ "longest_palindromic_substring_len", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dab2f51e59d5c4ff72d3a6d5f4217056b6bd70c7
100452ae89cab81988da2d9bd0c2b53de5565979
v1.0
instruct
Code_Contests
Code_Contests_44285_I
Alex is working in a network security team and is responsible for monitoring the network activity. The network can be represented as a 2D grid where each cell contains an integer value representing the severity of network traffic at a particular point in time. Alex needs to respond to a series of queries, where each qu...
def preprocess_grid(grid): """ Preprocess the grid to create a prefix sum array. """ r, c = len(grid), len(grid[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] = grid[i-1][j-1] + prefix_sum[i-1][...
from solution import preprocess_grid, sum_subgrid, network_severity 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 preproc...
[ { "docstring": "Preprocess the grid to create a prefix sum array.", "function_declaration": "def preprocess_grid(grid):", "function_name": "preprocess_grid", "parameter_list": "(grid)" }, { "docstring": "Calculate the sum of the subgrid using the prefix sum array.", "function_declaration...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preprocess_grid(grid):\n \"\"\"\n Preprocess the grid to create a 2D prefix sum array for efficient range sum queries.\n \"\"\"\n if not gr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044285", "row_id": 44285, "seed_ids": "[3010]" }
0.586532
Code_Contests_44285
I
[ "preprocess_grid", "sum_subgrid", "network_severity" ]
3
[ [ "network_severity", "preprocess_grid" ], [ "network_severity", "sum_subgrid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7eb227b446fa35bf99c42cc2d49258d70eb704bc
6ee252a1ce0f190a3b872621e46c0c456cca9933
v1.0
instruct
Code_Contests
Code_Contests_44296_I
You are given an integer array nums consisting of positive integers. You need to find the length of the longest subsequence such that all elements of the subsequence are coprime. Two integers are coprime if their greatest common divisor (gcd) is 1. In one move, you can select any non-empty subsequence of the array. ...
import math from collections import Counter def gcd(a, b): while b: a, b = b, a % b return a def longest_coprime_subsequence(nums): # If the array contains at least one prime number, then that is coprime with all other primes max_num = max(nums) # Sieve of Eratosthenes to find all pri...
import pytest from solution import solve def test_case_1(): assert solve([[10, 15, 20, 25]]) == [1] def test_case_2(): assert solve([[7, 11, 13, 17, 19]]) == [5] def test_case_3(): assert solve([[6, 10, 15]]) == [1] def test_case_4(): assert solve([ [10, 15, 20, 25], [7, 11, 13, 17, ...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def longest_coprime_subsequence(nums):", "function_name": "longest_coprime_subsequence", "parameter_list": "(nums)" ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom collections import defaultdict\n\ndef longest_coprime_subsequence(t, test_cases):\n # Check if two numbers are coprime\n d...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00044296", "row_id": 44296, "seed_ids": "[3987]" }
0.754016
Code_Contests_44296
I
[ "gcd", "longest_coprime_subsequence", "solve" ]
3
[ [ "solve", "longest_coprime_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61e0c19715f1db47f8da63ff6bdb42199f3b4826
231b6e9dd8502eba0f6ef7feba3d62733740bf29
v1.0
instruct
Code_Contests
Code_Contests_44399_I
In a distant galaxy, there exists a planet called Fibbonis where the Fibonacci sequence governs all aspects of life. The residents of Fibbonis have a unique tradition regarding their sequences and they have come up with an intriguing problem: Given a sequence of n integers a_0, a_1, ..., a_{n-1}, they want to determin...
MOD = 10**9 + 7 def fibonacci_sum_up_to(n): """ Returns the sum of all Fibonacci numbers up to and including F(n), modulo 10^9 + 7. """ if n == 0: return 0 elif n == 1: return 1 fib = [0] * (n + 1) fib[1] = 1 for i in range(2, n + 1): fib[i] = fib[i-1] + fib...
from solution import fibonacci_sequence_sum, fibonacci_sum_up_to def test_fibonacci_sum_up_to(): assert fibonacci_sum_up_to(0) == 0 assert fibonacci_sum_up_to(1) == 1 assert fibonacci_sum_up_to(2) == 2 # 0, 1, 1 -> 0+1+1 assert fibonacci_sum_up_to(3) == 4 # 0, 1, 1, 2 -> 0+1+1+2 assert fibonacci_...
[ { "docstring": "Returns the sum of all Fibonacci numbers up to and including F(n), modulo 10^9 + 7.", "function_declaration": "def fibonacci_sum_up_to(n):", "function_name": "fibonacci_sum_up_to", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def fibonacci_sequ...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fib_sequence_sum(n, a):\n MOD = 10**9 + 7\n \n # Generate the Fibonacci sequence up to the maximum value in a\n max_a = max(a)\n fibs = ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044399", "row_id": 44399, "seed_ids": "[12711]" }
0.683139
Code_Contests_44399
I
[ "fibonacci_sum_up_to", "fibonacci_sequence_sum", "main" ]
3
[ [ "fibonacci_sequence_sum", "fibonacci_sum_up_to" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8741d361242abf63b064865ddfd93f8ac9a47bf1
32c8f600e4174bb299c8eae0b9f0a8870ca3908b
v1.0
instruct
Code_Contests
Code_Contests_44400_I
The kingdom of Aruzia is renowned for its vast network of waterways that connect all its villages. These waterways are essentially straight canals, each linking a pair of villages. To keep the waterways functional, the kingdom employs maintenance boats. Each boat is assigned to a specific canal, but due to recent budge...
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] < rank[...
from solution import solve def test_case_1(): n, m = 4, 5 canals = [ (1, 2, 3), (2, 3, 2), (3, 4, 4), (4, 1, 1), (1, 3, 5) ] assert solve(n, m, canals) == (3, 6) def test_case_2(): n, m = 3, 3 canals = [ (1, 2, 10), (2, 3, 15), (1...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot = find(pare...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00044400", "row_id": 44400, "seed_ids": "[3267]" }
0.630513
Code_Contests_44400
I
[ "find", "union", "minimize_maintenance", "solve" ]
4
[ [ "minimize_maintenance", "find" ], [ "minimize_maintenance", "union" ], [ "solve", "minimize_maintenance" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
1dcd0d0c131125b3d16cff1a99d294a1c8b50243
3f12c250edaf0c727e27069321195bd35c279203
v1.0
instruct
Code_Contests
Code_Contests_44413_I
Alice and Bob are playing a game with two piles of stones. Alice starts first and then they alternate turns. When it's Alice's turn, she can remove 1 to x stones from the first pile or 1 to y stones from the second pile. Similarly, Bob can remove 1 to z stones from the first pile or 1 to w stones from the second pile. ...
def can_alice_win(piles, x, y): """ Determine if Alice has a winning strategy for the given pile configuration. """ a, b = piles # Calculate the nim-sum nim_sum = a ^ b # If the nim-sum is zero, it's a losing position for the player to move in an impartial game return nim_sum != 0 def d...
from solution import game def test_alice_wins(): assert game(1, [(3, 5, 2, 2)]) == ["Alice"] def test_bob_wins(): assert game(1, [(4, 4, 1, 1)]) == ["Bob"] def test_alice_wins_example_3(): assert game(1, [(1, 2, 2, 2)]) == ["Alice"] def test_combined_cases(): assert game(3, [(3, 5, 2, 2), (4, 4, 1, ...
[ { "docstring": "Determine if Alice has a winning strategy for the given pile configuration.", "function_declaration": "def can_alice_win(piles, x, y):", "function_name": "can_alice_win", "parameter_list": "(piles, x, y)" }, { "docstring": "Given the number of test cases and test cases for ea...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "def game_winner(t, test_cases):\n results = []\n for i in range(t):\n a, b, x, y = test_cases[i]\n \n #...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00044413", "row_id": 44413, "seed_ids": "[1393]" }
0.845495
Code_Contests_44413
I
[ "can_alice_win", "determine_winner", "game" ]
3
[ [ "determine_winner", "can_alice_win" ], [ "game", "determine_winner" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6e0496480ac5115d54585af14ca36a586a3d0489
65cc967a66ab232e45757433f32fbd5c548a9411
v1.0
instruct
Code_Contests
Code_Contests_44471_I
A company is developing a new automated warehouse system. In this system, items are stored in racks that have specific positions marked by coordinates in a 2D grid. The robot can navigate the grid to pick and place items. Each rack has a unique coordinate (x, y) representing its position. The warehouse grid is represe...
def find_item_positions(warehouse): item_positions = {} for i in range(len(warehouse)): for j in range(len(warehouse[0])): if warehouse[i][j] != 0: item_positions[warehouse[i][j]] = (i, j) return item_positions def manhattan_distance(x1, y1, x2, y2): return abs(x1 - ...
def test_find_item_positions(): warehouse = [ [1, 0, 3], [0, 2, 0], [4, 0, 5] ] expected_positions = {1: (0, 0), 3: (0, 2), 2: (1, 1), 4: (2, 0), 5: (2, 2)} assert find_item_positions(warehouse) == expected_positions def test_manhattan_distance(): assert manhattan_distance(0...
[ { "docstring": null, "function_declaration": "def find_item_positions(warehouse):", "function_name": "find_item_positions", "parameter_list": "(warehouse)" }, { "docstring": null, "function_declaration": "def manhattan_distance(x1, y1, x2, y2):", "function_name": "manhattan_distance"...
[ 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 robot_pickup_path(warehouse, start_x, start_y, item_ids):\n def manhattan_distance(x1, y1, x2, y2):\n return abs(x1 - x2) + abs(y1 - y2)\n\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044471", "row_id": 44471, "seed_ids": "[9773]" }
0.615283
Code_Contests_44471
I
[ "find_item_positions", "manhattan_distance", "robot_path" ]
3
[ [ "robot_path", "find_item_positions" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1a02fd0c72109941ccad97996e406ded01c17b33
08f072026a0aaf8be8aeadceedf32012f830065f
v1.0
instruct
Code_Contests
Code_Contests_44525_I
Write a function `find_next_happy_number` that takes an integer input `n` and returns the smallest happy number greater than `n`. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number eq...
def is_happy_number(n): """ Returns True if n is a happy number, else False. """ def get_next(number): return sum(int(char) ** 2 for char in str(number)) slow = n fast = get_next(n) while fast != 1 and slow != fast: slow = get_next(slow) fast = get_next(get_next(...
from solution import find_next_happy_number, is_happy_number def test_find_next_happy_number(): assert find_next_happy_number(100) == 103 assert find_next_happy_number(10) == 13 assert find_next_happy_number(95) == 97 assert find_next_happy_number(1) == 7 assert find_next_happy_number(7) == 10 def...
[ { "docstring": "Returns True if n is a happy number, else False.", "function_declaration": "def is_happy_number(n):", "function_name": "is_happy_number", "parameter_list": "(n)" }, { "docstring": "Finds the smallest happy number greater than n.", "function_declaration": "def find_next_ha...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_happy_number(n: int) -> bool:\n \"\"\"\n Returns True if n is a happy number, else False.\n \"\"\"\n seen = set()\n while n != 1 and ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044525", "row_id": 44525, "seed_ids": "[4136]" }
0.585413
Code_Contests_44525
I
[ "is_happy_number", "find_next_happy_number" ]
2
[ [ "find_next_happy_number", "is_happy_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
30174d0362ed9ff6591701ac979e1254f58925e4
ca48b0ad86c937b661c96fb92c0994765787094c
v1.0
instruct
Code_Contests
Code_Contests_44536_I
Given an array of positive integers and a target sum, determine the length of the shortest subarray with a sum that is greater than or equal to the target sum. A subarray is a contiguous part of an array. Input The first line contains two integers n and s (1 ≤ n ≤ 10^5, 1 ≤ s ≤ 10^9), where n is the number of element...
def shortest_subarray_with_sum(nums, s): n = len(nums) left = 0 current_sum = 0 min_length = float('inf') for right in range(n): current_sum += nums[right] while current_sum >= s: min_length = min(min_length, right - left + 1) current_sum -= nums...
def test_shortest_subarray_with_sum(): # Test case 1: Example 1 input_data = "6 7\n2 3 1 2 4 3" assert get_shortest_subarray_length(input_data) == 2 # Test case 2: Example 2 input_data = "5 11\n1 2 3 4 5" assert get_shortest_subarray_length(input_data) == 3 # Test case 3: Example 3...
[ { "docstring": null, "function_declaration": "def shortest_subarray_with_sum(nums, s):", "function_name": "shortest_subarray_with_sum", "parameter_list": "(nums, s)" }, { "docstring": null, "function_declaration": "def get_shortest_subarray_length(input_data):", "function_name": "get...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shortest_subarray_length(nums, target):\n \"\"\"\n Returns the length of the shortest subarray with sum >= target, or -1 if no such subarray exis...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044536", "row_id": 44536, "seed_ids": "[6798]" }
0.88445
Code_Contests_44536
I
[ "shortest_subarray_with_sum", "get_shortest_subarray_length" ]
2
[ [ "get_shortest_subarray_length", "shortest_subarray_with_sum" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8a6d223ed04e7d82b88d74ff87df7e66b7482341
3957381cce3770a6e2a3cd27d843c52dc458b9a5
v1.0
instruct
Code_Contests
Code_Contests_44543_I
You are given a sequence of positive integers. We define the "Beauty" of a sequence as the number of distinct integers in the sequence that has an even number of distinct prime factors. Your task is to determine the Beauty of the given sequence. Input The first line of input contains an integer n (1 ≤ n ≤ 100 000) – ...
def count_prime_factors(num): """Helper function to count distinct prime factors of a number""" factors = set() i = 2 while i * i <= num: while (num % i) == 0: factors.add(i) num //= i i += 1 if num > 1: factors.add(num) return len(factors) def ca...
from solution import count_prime_factors, calculate_beauty_of_sequence def test_single_prime(): # Test single prime numbers which should have 1 distinct prime factor assert count_prime_factors(2) == 1 assert count_prime_factors(3) == 1 assert count_prime_factors(5) == 1 def test_composite_numbers(): ...
[ { "docstring": "Helper function to count distinct prime factors of a number", "function_declaration": "def count_prime_factors(num):", "function_name": "count_prime_factors", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def calculate_beauty_of_sequence(n, se...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_prime_factors(n):\n \"\"\"\n Returns the number of distinct prime factors of n.\n \"\"\"\n count = 0\n factor = 2\n while facto...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00044543", "row_id": 44543, "seed_ids": "[7039]" }
0.599033
Code_Contests_44543
I
[ "count_prime_factors", "calculate_beauty_of_sequence" ]
2
[ [ "calculate_beauty_of_sequence", "count_prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75e0f4840f33d7850c7f03223596c4460bcb83fd
c259568a2f1e514b198b0474ea740ab861a4214f
v1.0
instruct
Code_Contests
Code_Contests_44593_I
In an enchanted forest, there are n magical creatures, each residing in its own unique tree. The trees are connected by n-1 gracious vines such that the entire forest forms a tree structure (connected and acyclic). The creatures communicate through these vines, and each vine has a magical strength that allows it to tra...
import heapq from collections import defaultdict def dijkstra(n, edges, s, t): """ Finds the minimum cost to send a message from node s to node t using Dijkstra's algorithm. :param n: Number of nodes :param edges: List of edges in the form (u, v, w) :param s: Starting node :param t: Target...
from solution import min_cost def test_case_1(): n = 5 edges = [(1, 2, 3), (1, 3, 4), (3, 4, 5), (2, 5, 6)] s, t = 1, 5 assert min_cost(n, edges, s, t) == 9 def test_case_2(): n = 3 edges = [(1, 2, 2), (2, 3, 4)] s, t = 1, 3 assert min_cost(n, edges, s, t) == 6 def test_case_3(): ...
[ { "docstring": "Finds the minimum cost to send a message from node s to node t using Dijkstra's algorithm.\n\n:param n: Number of nodes\n:param edges: List of edges in the form (u, v, w)\n:param s: Starting node\n:param t: Target node\n:return: Minimum cost to send the message from s to t", "function_declar...
[ 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\nfrom collections import defaultdict\n\ndef dijkstra(n, edges, s, t):\n \"\"\"\n Finds the minimum cost to send a message from node s to...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044593", "row_id": 44593, "seed_ids": "[10991]" }
0.588537
Code_Contests_44593
I
[ "dijkstra", "min_cost" ]
2
[ [ "min_cost", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fb3b44d7d61ec9d2030399bf33c9fcccdcf7be1
a99e49b9c73d5712eb1655c79a62d9510aadf358
v1.0
instruct
Code_Contests
Code_Contests_44595_I
Maxim the Farmer has recently built a series of connected barns for his cows. Each barn is a node, and each connection between two barns is an edge with a specific time it takes to travel between them. He wants to ensure that if a cow starts from a barn and goes through a sequence of connected barns, it should be able ...
import heapq def find_minimum_cycle(N, M, connections): def dijkstra(src): """ Run Dijkstra's algorithm from a source node """ dist = [float('inf')] * (N + 1) dist[src] = 0 priority_queue = [(0, src)] while priority_queue: current_dist, current_node = he...
from solution import find_minimum_cycle_helper def test_example_1(): N, M = 4, 4 connections = [ (1, 2, 4), (2, 3, 2), (3, 4, 3), (4, 2, 1) ] assert find_minimum_cycle_helper(N, M, connections) == 6 def test_example_2(): N, M = 3, 3 connections = [ (1, 2...
[ { "docstring": null, "function_declaration": "def find_minimum_cycle(N, M, connections):", "function_name": "find_minimum_cycle", "parameter_list": "(N, M, connections)" }, { "docstring": null, "function_declaration": "def find_minimum_cycle_helper(N, M, connections):", "function_nam...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nimport heapq\n\ndef find_min_cycle(N, M, connections):\n def dijkstra(start):\n dist = [sys.maxsize] * (N + 1)\n dist[start] =...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044595", "row_id": 44595, "seed_ids": "[2243]" }
0.63976
Code_Contests_44595
I
[ "find_minimum_cycle", "find_minimum_cycle_helper" ]
2
[ [ "find_minimum_cycle_helper", "find_minimum_cycle" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4bec0427f16b1dc958527c26af9fe26fcc00423c
b96ce40af317ba95682e23b08342b7797a2fb75d
v1.0
instruct
Code_Contests
Code_Contests_44597_I
Emily is a software developer who loves playing with strings. She recently came across a unique problem involving palindromes and now seeks your help to solve it. A palindrome is a word that reads the same forward and backward. Emily wants you to determine whether a string can be rearranged to form a palindrome. Give...
def can_be_palindrome(s): """ Determines if a string can be rearranged to form a palindrome. """ from collections import Counter count = Counter(s) odd_count = sum(1 for element in count.values() if element % 2 != 0) return odd_count <= 1 def check_strings_for_palindrome(N, strings): ""...
def test_can_be_palindrome(): assert can_be_palindrome("aabb") == True assert can_be_palindrome("abc") == False assert can_be_palindrome("racecar") == True assert can_be_palindrome("aabbccdde") == True assert can_be_palindrome("a") == True assert can_be_palindrome("ab") == False assert can_b...
[ { "docstring": "Determines if a string can be rearranged to form a palindrome.", "function_declaration": "def can_be_palindrome(s):", "function_name": "can_be_palindrome", "parameter_list": "(s)" }, { "docstring": "For each string in a list, prints \"Possible\" if the string can be rearrange...
[ 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 can_form_palindrome(strings):\n \"\"\"\n Determines if each string in the list can be rearranged to form a palindrome.\n \n :param strings:...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00044597", "row_id": 44597, "seed_ids": "[11940]" }
0.801902
Code_Contests_44597
I
[ "can_be_palindrome", "check_strings_for_palindrome" ]
2
[ [ "check_strings_for_palindrome", "can_be_palindrome" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b62964c15aff4f5e857eb4c2805aa0e1cd314f2c
4110a8a9caca9a909eadd579232cb0f260950043
v1.0
instruct
Code_Contests
Code_Contests_44628_I
You are given an undirected, weighted graph with N vertices and M edges. The vertices are numbered from 0 to N-1, and each edge connects two different vertices with a given weight. Your task is to determine the smallest number of edges that need to be removed in order to make the graph acyclic (i.e., free of cycles). ...
from collections import defaultdict 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 xroot != yroot: if rank[xroot] < rank[y...
from solution import minimum_edges_to_remove def test_case_1(): N = 5 edges = [ (0, 1, 4), (0, 2, 3), (1, 2, 1), (1, 3, 2), (3, 4, 6), (2, 4, 5) ] assert minimum_edges_to_remove(N, edges) == 2 def test_case_2(): N = 4 edges = [ (0, 1, 1),...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_parent(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find_parent(parent, parent[i])\n return parent...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00044628", "row_id": 44628, "seed_ids": "[12371]" }
0.659614
Code_Contests_44628
I
[ "find", "union", "minimum_edges_to_remove", "main" ]
4
[ [ "minimum_edges_to_remove", "find" ], [ "minimum_edges_to_remove", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f1d1e6daf5ac9559870ed2cb325d8989eecefbca
e44d262d540530cd76584608f40cc8e3c26517cb
v1.0
instruct
Code_Contests
Code_Contests_44637_I
Alex is preparing for a programming contest and came across a graph problem that he finds quite interesting. He has a graph with `n` vertices and `m` edges. The vertices are numbered from 1 to `n`. Each edge has a positive weight associated with it. Alex wants to know if there exists a path between vertex 1 and vertex...
import heapq def dijkstra(n, edges, start_vertex): # adjacency list representation of the graph graph = [[] for _ in range(n + 1)] for u, v, w in edges: graph[u].append((v, w)) graph[v].append((u, w)) # distances array, start with infinity distances = [float('inf')] * (n + 1) d...
from solution import min_path_weight def test_case_1(): n = 4 m = 4 edges = [(1, 2, 1), (2, 3, 2), (3, 4, 3), (1, 4, 10)] assert min_path_weight(n, m, edges) == 6 def test_case_2(): n = 3 m = 2 edges = [(1, 2, 4), (2, 3, 6)] assert min_path_weight(n, m, edges) == 10 def test_case_3():...
[ { "docstring": null, "function_declaration": "def dijkstra(n, edges, start_vertex):", "function_name": "dijkstra", "parameter_list": "(n, edges, start_vertex)" }, { "docstring": null, "function_declaration": "def min_path_weight(n, m, edges):", "function_name": "min_path_weight", ...
[ 0, 0, 0, 0, 0, 1, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_min_weight_path(n, m, edges):\n \"\"\"\n Finds the minimum weight path from vertex 1 to vertex n.\n \n Parameters:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00044637", "row_id": 44637, "seed_ids": "[7972]" }
0.837355
Code_Contests_44637
I
[ "dijkstra", "min_path_weight" ]
2
[ [ "min_path_weight", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
44a398fb480533ac02912c1bfc0d1a0f6ff09da6
84f73c54522bf626515dd399d8e5e14027cc8857
v1.0
instruct
Code_Contests
Code_Contests_44685_I
You are given an array of integers and two types of operations that can be performed on it. Your task is to write a program that can efficiently handle these operations and output the required results. Operation Types: 1. Increase the value of a given range by a given value. 2. Calculate the sum of a given range. Inp...
class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def update(self, index, delta): while index <= self.size: self.tree[index] += delta index += index & -index def prefix_sum(self, index): total = 0 whil...
def test_process_operations(): n = 5 operations = [ (2, 1, 3), (1, 2, 4, 1), (2, 2, 4), (1, 3, 5, 2), (2, 1, 5) ] array = [1, 2, 3, 4, 5] expected_output = [6, 12, 24] assert process_operations(n, operations, array) == expected_output def test_single_elem...
[]
[ 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 SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.tree = [0] * (2 * self.n)\n self.lazy = [0] * self.n\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044685", "row_id": 44685, "seed_ids": "[5378]" }
0.656883
Code_Contests_44685
I
[ "initialize_array_and_fenwick_tree", "increase_range", "sum_range", "process_operations" ]
4
[ [ "process_operations", "increase_range" ], [ "process_operations", "initialize_array_and_fenwick_tree" ], [ "process_operations", "sum_range" ] ]
3
[]
false
[ "FenwickTree" ]
true
pytest
false
[]
true
b3d0d7b00554cc35ef9886a0e05708a5b8d3c355
51184147c8243084471b42df0eb8509dcae70143
v1.0
instruct
Code_Contests
Code_Contests_44718_I
You are the manager of a recycling plant and are tasked with optimizing the waste sorting process. The plant receives a collection of mixed recyclable materials which need to be sorted based on their type. Each type of material is associated with a specific identifier, and every object in the pile of recyclables comes ...
def sort_recyclables(n, objects): from collections import defaultdict, OrderedDict material_bins = OrderedDict() for obj_id, material_type in objects: if material_type not in material_bins: material_bins[material_type] = [] material_bins[material_type].append(obj_id) ...
def test_sort_recyclables(): objects = [ (4, 7), (6, 3), (1, 7), (8, 2), (2, 3), (5, 2), (7, 3), (3, 2) ] expected_output = { 7: [1, 4], 3: [2, 6, 7], 2: [3, 5, 8] } assert sort_recyclables(8, objects) == expecte...
[ { "docstring": null, "function_declaration": "def sort_recyclables(n, objects):", "function_name": "sort_recyclables", "parameter_list": "(n, objects)" }, { "docstring": null, "function_declaration": "def process_input_and_output(n, objects):", "function_name": "process_input_and_out...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_recyclables(N, objects):\n from collections import defaultdict, OrderedDict\n \n material_dict = OrderedDict()\n \n for obj_id, mat...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044718", "row_id": 44718, "seed_ids": "[5508]" }
0.579577
Code_Contests_44718
I
[ "sort_recyclables", "process_input_and_output" ]
2
[ [ "process_input_and_output", "sort_recyclables" ] ]
1
[]
false
[]
false
pytest
false
[]
true
50000b3b054a273b5294bf642d4472c40efb89ec
66c7807b349484cc2ec645d3cc4d172481e2bf47
v1.0
instruct
Code_Contests
Code_Contests_44753_I
**Problem:** John is a passionate traveler who loves to visit various cities. However, John has a unique way of traveling. He always starts his journey from his home city and chooses the next city to visit based on the sum of the digits of the distance between the current city he is in and the next city. The city with...
def sum_of_digits(n): """ Returns the sum of the digits of a number. """ return sum(int(d) for d in str(n)) def johns_travel_order(distances): """ Given a list of distances, returns a list of distances in the order that John will visit the cities. """ order = sorted(distances, key=l...
from solution import johns_travel_order def test_basic_case(): distances = [34, 56, 12, 23, 45] assert johns_travel_order(distances) == [12, 23, 34, 45, 56] def test_single_city(): distances = [5] assert johns_travel_order(distances) == [5] def test_same_sum_digits(): distances = [19, 28, 37] ...
[ { "docstring": "Returns the sum of the digits of a number.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Given a list of distances, returns a list of distances in the order that\nJohn will visit the cities.", ...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def travel_order(n, distances):\n \"\"\"\n Returns the order in which John will visit the cities based on the sum of digits of the distances.\n \"...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00044753", "row_id": 44753, "seed_ids": "[7358]" }
0.760964
Code_Contests_44753
I
[ "sum_of_digits", "johns_travel_order" ]
2
[ [ "johns_travel_order", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c1038c9aefdbafae954a4a680c60629041e89ec
62c82b934f2256103c9b4c7cbe1836eef8ffa7e5
v1.0
instruct
Code_Contests
Code_Contests_44783_I
Palindrome Partitioning Given a string `s`, partition `s` such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of `s`. A palindrome is a string that reads the same forwards and backwards. Input: - The first line contains a single integer `T`, the number of test cas...
def is_palindrome(s: str) -> bool: return s == s[::-1] def partition(s: str): result = [] path = [] def backtrack(start): if start >= len(s): result.append(path[:]) return for end in range(start, len(s)): if is_palindrome(s[start:end+1]): ...
from solution import solve_palindrome_partitioning, partition, is_palindrome def test_is_palindrome(): assert is_palindrome("a") == True assert is_palindrome("aa") == True assert is_palindrome("aba") == True assert is_palindrome("abc") == False def test_partition(): assert partition("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...
[ 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_palindrome(substring):\n \"\"\"\n Checks if a given string is a palindrome.\n \"\"\"\n return substring == substring[::-1]\n\ndef partit...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00044783", "row_id": 44783, "seed_ids": "[419]" }
0.71261
Code_Contests_44783
I
[ "is_palindrome", "partition", "solve_palindrome_partitioning" ]
3
[ [ "partition", "is_palindrome" ], [ "solve_palindrome_partitioning", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2edb842790ac39c147d83921633f92e1d811f391
6174e7261211d2cc634debfdc81f42500ec1d79f
v1.0
instruct
Code_Contests
Code_Contests_44835_I
Given a list of `n` integers, you need to find the k-th smallest element in the list without sorting the entire list. Implement this using the Quickselect algorithm. ### Input - The first line contains two integers, `n` and `k` (1 ≤ k ≤ n ≤ 100,000), where `n` is the number of elements in the list and `k` is the posit...
def quickselect(arr, k): """ Returns the k-th smallest element in the array using Quickselect algorithm. """ def partition(left, right, pivot_index): pivot = arr[pivot_index] # Move pivot to end arr[pivot_index], arr[right] = arr[right], arr[pivot_index] store_index = le...
from solution import find_kth_smallest_element def test_example1(): n = 6 k = 2 arr = [7, 10, 4, 3, 20, 15] assert find_kth_smallest_element(n, k, arr) == 4 def test_example2(): n = 5 k = 3 arr = [7, 10, 4, 20, 15] assert find_kth_smallest_element(n, k, arr) == 10 def test_single_elem...
[ { "docstring": "Returns the k-th smallest element in the array using Quickselect algorithm.", "function_declaration": "def quickselect(arr, k):", "function_name": "quickselect", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def find_kth_smallest_element(n,...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quickselect(arr, low, high, k):\n if low == high: # If the list contains only one element,\n return arr[low] # return that element\n\n p...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044835", "row_id": 44835, "seed_ids": "[684]" }
0.553593
Code_Contests_44835
I
[ "quickselect", "find_kth_smallest_element" ]
2
[ [ "find_kth_smallest_element", "quickselect" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd60ad049b84bb5f44c2d38c48c20bd503f366cb
951249fda80eda6c186e6aaa5997e65774378e5a
v1.0
instruct
Code_Contests
Code_Contests_44882_I
In a kingdom far away, there are N knights standing in a row, numbered 1 through N. Each knight has a certain amount of armor represented by an integer array A of length N, where Ai denotes the armor value of the ith knight. The king has planned some operations to improve their armor or check their readiness for battle...
def update_armor(arr, l, r, k): for i in range(l, r + 1): arr[i] += k def calculate_sum(arr, l, r): return sum(arr[l:r + 1]) def perform_operations(N, M, armor_values, operations): results = [] for operation in operations: if operation[0] == 1: _, l, r, k = operatio...
from solution import perform_operations def test_operations_example_case(): N = 6 M = 5 armor_values = [10, 20, 30, 40, 50, 60] operations = [ [2, 1, 3], [1, 2, 4, 10], [2, 2, 5], [1, 3, 6, 5], [2, 1, 6] ] results = perform_operations(N, M, armor_val...
[ { "docstring": null, "function_declaration": "def update_armor(arr, l, r, k):", "function_name": "update_armor", "parameter_list": "(arr, l, r, k)" }, { "docstring": null, "function_declaration": "def calculate_sum(arr, l, r):", "function_name": "calculate_sum", "parameter_list":...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def update_knight_armor(N, M, armor_values, operations):\n \"\"\"\n Function to handle operations on knight armors\n \n Parameters:\n N (int...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044882", "row_id": 44882, "seed_ids": "[5460]" }
0.626997
Code_Contests_44882
I
[ "update_armor", "calculate_sum", "perform_operations" ]
3
[ [ "perform_operations", "calculate_sum" ], [ "perform_operations", "update_armor" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ee287ab893ca00c24e568e59a74aa99149d6372f
08f4324cc673f16bdb3912820ad937269ee1df83
v1.0
instruct
Code_Contests
Code_Contests_44885_I
You are given a grid of size n x n filled with non-negative integers. You need to perform the following operations: 1. Rotate the grid 90 degrees clockwise. 2. After rotation, find the sum of the elements in the main diagonal (from top-left to bottom-right). Note that you may need to perform the rotation and calculat...
def rotate_90_clockwise(grid): """ Rotates the grid 90 degrees clockwise and returns the new grid. """ n = len(grid) new_grid = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): new_grid[j][n - 1 - i] = grid[i][j] return new_grid def main_diagon...
from solution import rotate_90_clockwise, main_diagonal_sum, grid_diagonal_sum_after_k_rotations, process_queries def test_rotate_90_clockwise(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3] ] assert rotate_9...
[ { "docstring": "Rotates the grid 90 degrees clockwise and returns the new grid.", "function_declaration": "def rotate_90_clockwise(grid):", "function_name": "rotate_90_clockwise", "parameter_list": "(grid)" }, { "docstring": "Returns the sum of the main diagonal elements of the grid.", "...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_and_sum_diagonal(grid, n, rotations):\n \"\"\"\n Rotates the grid 90 degrees clockwise 'rotations' number of times and returns the sum\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044885", "row_id": 44885, "seed_ids": "[550]" }
0.643788
Code_Contests_44885
I
[ "rotate_90_clockwise", "main_diagonal_sum", "grid_diagonal_sum_after_k_rotations", "process_queries" ]
4
[ [ "grid_diagonal_sum_after_k_rotations", "main_diagonal_sum" ], [ "grid_diagonal_sum_after_k_rotations", "rotate_90_clockwise" ], [ "process_queries", "grid_diagonal_sum_after_k_rotations" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
6895ec38c22a07529f55042c74de0762bbe3f997
4ad1ac583cbb54ec00603584b8ccea313ac8404b
v1.0
instruct
Code_Contests
Code_Contests_44888_I
Tree Depth Calculation You are provided with a binary tree, and your task is to calculate its maximum depth. The depth of a node is defined as the number of edges on the path from the root node to the node. The depth of the tree is the maximum depth among all nodes in the tree. A binary tree is given in the form of a...
class Node: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(nodes): if not nodes: return None node_dict = {} for value, left, right in nodes: if value not in node_dict: node_dict...
import pytest from solution import calculate_tree_depth def test_example_case(): assert calculate_tree_depth(5, [ (1, 2, 3), (2, 4, 5), (3, 'null', 'null'), (4, 'null', 'null'), (5, 'null', 'null') ]) == 3 def test_single_node(): assert calculate_tree_depth(1, [ ...
[]
[ 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 Node:\n def __init__(self, value, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044888", "row_id": 44888, "seed_ids": "[5822]" }
0.607378
Code_Contests_44888
I
[ "build_tree", "max_depth", "calculate_tree_depth" ]
3
[ [ "calculate_tree_depth", "build_tree" ], [ "calculate_tree_depth", "max_depth" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
9ee283a091e76d14b66e822f5d879e7211844198
cc1c8cdabec3cda1155665270a9cc9b1dc8336bd
v1.0
instruct
Code_Contests
Code_Contests_44911_I
In the kingdom of Polygonia, a special kind of sequence is revered for its mathematical elegance. This sequence must satisfy a peculiar property based on the sum of neighboring elements. Given a sequence \( S \) of length \( n \), we define its magical property as follows: for every element \( S[i] \) (where \( 1 \leq ...
def magical_sequence(n): if n < 2: return -1 sequence = [] for i in range(1, n + 1): if i % 2 == 1: sequence.append(1) else: sequence.append(2) return sequence def print_magical_sequence(n): seq = magical_sequence(n) if seq == -1: ...
from solution import magical_sequence def test_magical_sequence_3(): assert magical_sequence(3) == [1, 2, 1] def test_magical_sequence_4(): assert magical_sequence(4) == [1, 2, 1, 2] def test_magical_sequence_minimum_n(): assert magical_sequence(2) == [1, 2] def test_magical_sequence_large_n(): resu...
[ { "docstring": null, "function_declaration": "def magical_sequence(n):", "function_name": "magical_sequence", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def print_magical_sequence(n):", "function_name": "print_magical_sequence", "parameter_list": "(n...
[ 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 magical_sequence(n):\n \"\"\"\n Given an integer n, returns a sequence of length n that satisfies the magical property.\n \"\"\"\n if n < 2...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00044911", "row_id": 44911, "seed_ids": "[54]" }
0.69262
Code_Contests_44911
I
[ "magical_sequence", "print_magical_sequence" ]
2
[ [ "print_magical_sequence", "magical_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75695fd6841e19491c2ab42d42b59f1c98b1a7a6
a8334e6b09ae0890d5eef5c4bb6a7532803ed449
v1.0
instruct
Code_Contests
Code_Contests_44941_I
You are given an array `arr` of size `n`. Your task is to determine whether the array can be considered "circularly increasing". An array is called circularly increasing if it can be rotated in such a way that each element is smaller than the next element, except for the largest element which should be smaller than the...
def is_circularly_increasing(arr): n = len(arr) increase_points = sum(arr[i] < arr[(i + 1) % n] for i in range(n)) return increase_points == n - 1 def solve(test_cases): results = [] for arr in test_cases: if is_circularly_increasing(arr): results.append("YES") else: ...
from solution import main def test_example_case(): raw_input = "4\n4\n3 4 1 2\n5\n2 3 4 5 1\n5\n1 3 5 2 4\n3\n10 20 30\n" expected_output = "YES\nYES\nNO\nYES" assert main(raw_input) == expected_output def test_all_same_elements(): raw_input = "1\n5\n5 5 5 5 5\n" expected_output = "NO" assert ...
[ { "docstring": null, "function_declaration": "def is_circularly_increasing(arr):", "function_name": "is_circularly_increasing", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", "parameter_list": "(test_c...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_circularly_increasing(arr):\n n = len(arr)\n for i in range(n):\n if all(arr[(i + k) % n] < arr[(i + k + 1) % n] for k in range(n - 1))...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00044941", "row_id": 44941, "seed_ids": "[744]" }
0.661732
Code_Contests_44941
I
[ "is_circularly_increasing", "solve", "process_input", "format_output", "main" ]
5
[ [ "solve", "is_circularly_increasing" ] ]
1
[ "process_input", "format_output" ]
false
[]
false
pytest
true
[]
true
d6e6c00e3613788ea6a4b607348e3d12097e10a3
b6a7d1c563e8eae999da2718c3b3ff437ffbba2e
v1.0
instruct
Code_Contests
Code_Contests_44970_I
Alice is learning about prime numbers and their applications. She found an interesting problem to solve: given a list of integers, determine how many of them are prime numbers. A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. Help Alice by writing a program that counts ...
def is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def count_primes(n, numbers): prime_count = 0 for number in numbers: if is_prime(number): prime_count += 1 return prime_co...
from solution import is_prime, count_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(29) == True assert is_prime(30) == False ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def count_primes(n, numbers):", "function_name": "count_primes", "parameter_list": "(n, numbers)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return T...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00044970", "row_id": 44970, "seed_ids": "[41]" }
0.706023
Code_Contests_44970
I
[ "is_prime", "count_primes" ]
2
[ [ "count_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4828b3eddef43414f8cc504f1ab78ceb56c88f5c
d41470175bafef486742d1930c3480e569a77c70
v1.0
instruct
Code_Contests
Code_Contests_44989_I
Given a scenic garden with several plants, each plant blooms at a regular interval of days. All the plants in the garden bloomed together on day 0. You need to determine how many days it will be until all the plants bloom together again. For example, if there are 3 plants with blooming intervals of 4, 5, and 6 days re...
import math from functools import reduce MODULO = 1000000007 def lcm(a, b): return abs(a * b) // math.gcd(a, b) def find_days_until_bloom(intervals): return reduce(lcm, intervals) % MODULO def solve(test_cases): results = [] for n, intervals in test_cases: days = find_days_until_bloom(interv...
from solution import main def test_sample_cases(): input_data = """2 3 3 7 9 4 2 3 5 7""" expected_output = [63, 210] assert main(input_data) == expected_output def test_single_plant(): input_data = """1 1 7""" expected_output = [7] assert main(input_data) == expected_output def test_large_nu...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def find_days_until_bloom(intervals):", "function_name": "find_days_until_bloom", "parameter_list": "(intervals)" }...
[ 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\nMODULO = 1000000007\n\ndef lcm(a, b):\n return abs(a * b) // math.gcd(a, b)\n\ndef find_days_until_bloom(in...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00044989", "row_id": 44989, "seed_ids": "[5072]" }
0.68937
Code_Contests_44989
I
[ "lcm", "find_days_until_bloom", "solve", "parse_input", "main" ]
5
[ [ "find_days_until_bloom", "lcm" ], [ "solve", "find_days_until_bloom" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
2b9e946b973d8e3b2117eb9d7708637ab7d36736
5512174aec7e0c8baae2fc669fab8da5a61a4e17
v1.0
instruct
Code_Contests
Code_Contests_45025_I
The city of Florapack is filled with delivery trucks that need to deliver packages to different sectors. Each package has a specific target sector assigned to it. The truck drivers are very busy and sometimes make mistakes—they might deliver a package to the wrong sector. There is a curious property in the city: if a s...
def can_form_palindrome(s): """ Determines if the input string s can be rearranged to form a palindrome. """ from collections import Counter char_count = Counter(s) odd_count = sum(1 for count in char_count.values() if count % 2 != 0) return odd_count <= 1 def logistics_palindrome(n, s): ...
from solution import can_form_palindrome, logistics_palindrome def test_can_form_palindrome(): assert can_form_palindrome('level') == True assert can_form_palindrome('abc') == False assert can_form_palindrome('a') == True assert can_form_palindrome('racecar') == True assert can_form_palindrome('aab...
[ { "docstring": "Determines if the input string s can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Determines if it is possible for the sequence of delivered pack...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome(n, s):\n \"\"\"\n Determines if the sequence of delivered packages can be rearranged to form a palindrome.\n \"\"\"\n f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045025", "row_id": 45025, "seed_ids": "[7148]" }
0.775814
Code_Contests_45025
I
[ "can_form_palindrome", "logistics_palindrome" ]
2
[ [ "logistics_palindrome", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56622f2241597316bdbb9f6b549b0cf71f37f0bf
0955071bef6e08e9932f698ba057037a3dd497cb
v1.0
instruct
Code_Contests
Code_Contests_45028_I
You are given a board of size n x m where each cell contains a number which is either 0 or 1. Your task is to find the largest rectangular subarray consisting entirely of 1s. The size of the board (n x m) and the contents of the board are provided as input. ### Input - The first line contains two integers n and m (1 ≤...
def maximalRectangle(board): if not board: return 0 n = len(board) m = len(board[0]) max_area = 0 heights = [0] * m for i in range(n): for j in range(m): if board[i][j] == '1': heights[j] += 1 else: heights[j] = 0 ...
from solution import maximalRectangle def test_maximal_rectangle_example(): board = ["10110", "10111", "11111", "10010"] assert maximalRectangle(board) == 6 def test_maximal_rectangle_large(): board = ["1" * 100] * 100 assert maximalRectangle(board) == 10000 def test_maximal_rectangle_no_ones(): ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(board):", "function_name": "maximalRectangle", "parameter_list": "(board)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(n, m, board):\n \"\"\"\n Returns the area of the largest rectangular subarray consisting entirely of 1s in a board of size n x m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045028", "row_id": 45028, "seed_ids": "[5432]" }
0.690847
Code_Contests_45028
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cf30b6bbf0e6a3af3fd850fa68b82115fa330810
b59239ec45e71024b50e9b8d5a4af34dbefa5feb
v1.0
instruct
Code_Contests
Code_Contests_45029_I
AtCoDeer the deer found N rows of matching cards on the table, each row containing a number of cards visible at varying positions. Each position is represented as an integer coordinate (x, y) on a two-dimensional plane, where 1 ≤ x, y ≤ 10^9. For each row, if two or more cards form a straight horizontal or vertical li...
def check_alignment(rows): """ For each row, determines if all the cards are aligned vertically or horizontally. Parameters: rows (list): A list of rows, where each row is a list of (x, y) tuples representing card positions. Returns: List[str]: A list of "YES" or "NO" indicating if the res...
import pytest from solution import parse_input, check_alignment, solve from io import StringIO import sys def test_check_alignment_all_vertical(): rows = [[(1, 2), (1, 3), (1, 4)], [(2, 2), (2, 3)]] assert check_alignment(rows) == ['YES', 'YES'] def test_check_alignment_all_horizontal(): rows = [[(1, 1), ...
[ { "docstring": "For each row, determines if all the cards are aligned vertically or horizontally.\n\nParameters:\nrows (list): A list of rows, where each row is a list of (x, y) tuples representing card positions.\n\nReturns:\nList[str]: A list of \"YES\" or \"NO\" indicating if the respective row is aligned or...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def check_alignment(rows):\n results = []\n for row in rows:\n if all(x == row[0][0] for x, y in row) or all(y == row[0][1] for x, y in row):\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045029", "row_id": 45029, "seed_ids": "[2795]" }
0.597904
Code_Contests_45029
I
[ "check_alignment", "parse_input", "solve" ]
3
[ [ "solve", "check_alignment" ], [ "solve", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
5a251916cd0967cf56e9003f9ed08374b02990ca
d13b4db8382eef459d215b0dd6da1810782b4951
v1.0
instruct
Code_Contests
Code_Contests_45038_I
You have a collection of n distinct books and you want to pack them into boxes such that the books in each box meet a specific condition. The condition is that the number of books in the box should be equal to the greatest common divisor (GCD) of the page counts of all books in that box. The page count of the i-th book...
def gcd(a, b): while b: a, b = b, a % b return a def max_boxes(t, test_cases): result = [] for i in range(t): n = test_cases[i][0] pages = test_cases[i][1] if n == 1: result.append(1) continue overall_gcd = pages[0] ...
from solution import gcd, max_boxes def test_gcd(): assert gcd(6, 8) == 2 assert gcd(12, 15) == 3 assert gcd(7, 3) == 1 assert gcd(10, 5) == 5 assert gcd(1, 1) == 1 def test_max_boxes_single_case(): assert max_boxes(1, [(4, [6, 4, 8, 12])]) == [2] assert max_boxes(1, [(3, [3, 5, 7])]) == [...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def max_boxes(t, test_cases):", "function_name": "max_boxes", "parameter_list": "(t, 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef max_boxes(t, test_cases):\n result = []\n for i in range(t):\n n = ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045038", "row_id": 45038, "seed_ids": "[4712]" }
0.708551
Code_Contests_45038
I
[ "gcd", "max_boxes" ]
2
[ [ "max_boxes", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b9ca938b3c4fe43cabeed2d87c319bfeadd0377
2a070327c97a246236a7f80891e0af8f81c7926e
v1.0
instruct
Code_Contests
Code_Contests_45081_I
The town of Algorville is arranging an annual marathon, and the organizers want to track the race progress at different checkpoints. Each runner has a unique bib number and their checkpoint times are recorded in hours, minutes, and seconds format. Your task is to create a system that processes these times and provides ...
from datetime import timedelta def process_race_data(runners): """ Processes race data to determine the fastest, the time difference between the fastest and second fastest, and the bib number of the slowest runner. Parameters: runners (list of tuples): List of tuples where each tuple contains ...
from solution import marathon_info def test_example_1(): input_data = [ "3", "45 2:15:38", "106 2:12:45", "374 2:20:01" ] assert marathon_info(input_data) == (106, '0:2:53', 374) def test_example_2(): input_data = [ "4", "12 1:05:20", "34 1:04:50...
[ { "docstring": "Processes race data to determine the fastest, the time difference between the fastest and second fastest,\nand the bib number of the slowest runner.\n\nParameters:\nrunners (list of tuples): List of tuples where each tuple contains the runner's bib number and their recorded time.\n\nReturns:\ntu...
[ 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 datetime import timedelta\n\ndef process_marathon_times(n, runner_times):\n def time_to_seconds(time_str):\n hours, minutes, seconds = map(i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045081", "row_id": 45081, "seed_ids": "[13263]" }
0.578618
Code_Contests_45081
I
[ "process_race_data", "marathon_info" ]
2
[ [ "marathon_info", "process_race_data" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b37f7c970993e65a9ed576c9c23a1435c21e15fa
a1fdab34ed3add2ee421f1f4e65d26525f300330
v1.0
instruct
Code_Contests
Code_Contests_45106_I
You are given a string s consisting of n lowercase Latin letters. Your task is to determine if it is possible to rearrange the letters of the string such that no two adjacent letters are the same. If it is possible, you should return one such rearrangement; otherwise, return -1. Input The first line contains an inte...
from collections import Counter import heapq def rearrange_string(s): """ Rearranges the string such that no two adjacent letters are the same. If not possible, returns -1. """ # Count the frequency of each character freq = Counter(s) # Create a max heap based on frequency max_heap = [(...
from solution import can_rearrange_string def test_example_1(): assert can_rearrange_string(7, "aabbccc") != -1 def test_example_2(): assert can_rearrange_string(6, "aaabbb") == "ababab" def test_example_3(): assert can_rearrange_string(3, "aaa") == -1 def test_single_char(): assert can_...
[ { "docstring": "Rearranges the string such that no two adjacent letters are the same.\nIf not possible, returns -1.", "function_declaration": "def rearrange_string(s):", "function_name": "rearrange_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def can_...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nfrom heapq import heappush, heappop\n\ndef rearrange_string(s):\n \"\"\"\n Returns a rearrangement of the string suc...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045106", "row_id": 45106, "seed_ids": "[2001]" }
0.805141
Code_Contests_45106
I
[ "rearrange_string", "can_rearrange_string" ]
2
[ [ "can_rearrange_string", "rearrange_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
33363616b662fda08e29a0141fedab832b76e856
35932866f17342dd0c7a8679c95b36a6eb82a62a
v1.0
instruct
Code_Contests
Code_Contests_45117_I
You are provided with a list of integers. Your task is to rearrange the integers so that they form the maximum possible integer. The output should be the largest integer that can be formed by concatenating the list of integers. Input - The first line contains an integer n (1 ≤ n ≤ 100) – the number of integers in the...
from functools import cmp_to_key def compare(x, y): # Custom comparator that decides the order based on concatenated result if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def max_number_from_list(numbers): # Convert all numbers to strings since we'l...
from solution import max_number_from_list def test_all_single_digits(): assert max_number_from_list([1, 2, 3, 4, 5]) == "54321" def test_different_length_numbers(): assert max_number_from_list([54, 546, 548]) == "54854654" def test_adjacent_different_ordering(): assert max_number_from_list([98, 9, 97]) =...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def max_number_from_list(numbers):", "function_name": "max_number_from_list", "parameter_list": "(numbers)" ...
[ 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 functools import cmp_to_key\n\ndef compare(x, y):\n # Custom comparator that decides the order based on concatenated result\n if x + y > y + x:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045117", "row_id": 45117, "seed_ids": "[5050]" }
0.660049
Code_Contests_45117
I
[ "compare", "max_number_from_list", "main" ]
3
[ [ "max_number_from_list", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83bb76bf1ed41a833290a7ea6e6fa34cd2d9e8c5
7dc3058dcc84115281c63eb145c1aa594884ad0b
v1.0
instruct
Code_Contests
Code_Contests_45130_I
Given a directed acyclic graph (DAG) with N nodes and M edges, you need to find the length of the longest path in the graph. A path is defined as a sequence of nodes where there is a direct edge from each node to the next in the sequence. Nodes are numbered from 1 to N. Constraints: * 1 \leq N \leq 1000 * 0 \leq M \...
def longest_path_in_dag(n, m, edges): from collections import defaultdict, deque # Build the graph graph = defaultdict(list) in_degree = [0] * (n + 1) for u, v in edges: graph[u].append(v) in_degree[v] += 1 # Topological Sort (Kahn's Algorithm) topo_order = [] queue = ...
import pytest from solution import longest_path_from_input def test_longest_path_example_1(): input_str = "4 4\n1 2\n2 3\n3 4\n1 3" assert longest_path_from_input(input_str) == 3 def test_longest_path_example_2(): input_str = "6 7\n1 2\n1 3\n2 5\n3 4\n4 5\n5 6\n3 5" assert longest_path_from_input(inpu...
[ { "docstring": null, "function_declaration": "def longest_path_in_dag(n, m, edges):", "function_name": "longest_path_in_dag", "parameter_list": "(n, m, edges)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "paramete...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_longest_path(N, M, edges):\n from collections import defaultdict, deque\n\n # Initialize the graph and in-degrees\n graph = defaultdict(l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045130", "row_id": 45130, "seed_ids": "[7059]" }
0.625634
Code_Contests_45130
I
[ "longest_path_in_dag", "parse_input", "longest_path_from_input" ]
3
[ [ "longest_path_from_input", "longest_path_in_dag" ], [ "longest_path_from_input", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
1f53a99f1b1467fd58cbd13ff89459c1ed2dfa52
82cd2c0ea09b68ddf9802e748ff5c4c6ff8a15a4
v1.0
instruct
Code_Contests
Code_Contests_45141_I
Given a list of integers, rearrange the integers to form the largest possible concatenated number. You should implement this function: ```python def largest_concatenated_number(nums: List[int]) -> str: ``` ### Input: - An array of integers `nums` (1 ≤ len(nums) ≤ 10^5, 0 ≤ nums[i] ≤ 10^9) ### Output: - Return the l...
from typing import List from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_concatenated_number(nums: List[int]) -> str: if not nums: return "" # Convert numbers to strings ...
from solution import largest_concatenated_number def test_example_case_1(): assert largest_concatenated_number([10, 2]) == "210" def test_example_case_2(): assert largest_concatenated_number([3, 30, 34, 5, 9]) == "9534330" def test_all_zeros(): assert largest_concatenated_number([0, 0, 0]) == "0" def te...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def largest_concatenated_number(nums):", "function_name": "largest_concatenated_number", "parameter_list": "(...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom functools import cmp_to_key\n\ndef compare(x, y):\n if x + y > y + x:\n return -1\n elif x + y < y + x:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00045141", "row_id": 45141, "seed_ids": "[2731]" }
0.682791
Code_Contests_45141
I
[ "compare", "largest_concatenated_number" ]
2
[ [ "largest_concatenated_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c0e5df49d62430b4e4eb66fe1168de8a8803ef7
6fd1eda3ece7630833fae692adc94043233d3be2
v1.0
instruct
Code_Contests
Code_Contests_45149_I
You are given two strings, `s1` and `s2`, both consisting of lowercase English letters. You are tasked with finding the length of the shortest string that can be formed which contains both `s1` and `s2` as subsequences. Input The first line contains the string `s1` (1 ≤ |s1| ≤ 100). The second line contains the strin...
def lcs_length(s1, s2): """ Helper function to find the length of the longest common subsequence between s1 and s2. """ m, n = len(s1), len(s2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if s1[i - 1] == s2[j - 1]: ...
from solution import shortest_supersequence_length def test_sample1(): assert shortest_supersequence_length("abc", "ac") == 3 def test_sample2(): assert shortest_supersequence_length("abc", "def") == 6 def test_overlap(): assert shortest_supersequence_length("abcd", "abef") == 6 def test_identical(): ...
[ { "docstring": "Helper function to find the length of the longest common subsequence between s1 and s2.", "function_declaration": "def lcs_length(s1, s2):", "function_name": "lcs_length", "parameter_list": "(s1, s2)" }, { "docstring": "Returns the length of the shortest string that contains ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def lcs(s1, s2):\n \"\"\"\n Returns the length of the longest common subsequence between s1 and s2.\n \"\"\"\n m, n = len(s1), len(s2)\n dp ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045149", "row_id": 45149, "seed_ids": "[9408]" }
0.70595
Code_Contests_45149
I
[ "lcs_length", "shortest_supersequence_length" ]
2
[ [ "shortest_supersequence_length", "lcs_length" ] ]
1
[]
false
[]
false
pytest
true
[]
true
acedfbc5f54518c59f3a387342f8c5752d980137
ac5fd5290b27d8bb6a597653cd12c457d80d0e82
v1.0
instruct
Code_Contests
Code_Contests_45159_I
You are given a permutation of the first n positive integers, 1 through n, represented as an array p. Your task is to reconstruct the original permutation from which this array was derived after performing a series of m operations. Each operation consists of choosing a subarray and reversing its order. Unfortunately, y...
def reverse_subarray(array, l, r): """ Given an array and indices l and r, reverse the subarray from index l to r. """ return array[:l-1] + array[l-1:r][::-1] + array[r:] def reconstruct_permutation(n, p): """ Given the length n and a permutation p, this function reconstructs the original permu...
# Assuming the solution is in a file named `solution.py` from solution import reverse_subarray, reconstruct_permutation def test_reverse_subarray(): assert reverse_subarray([1, 2, 3, 4, 5], 1, 5) == [5, 4, 3, 2, 1] assert reverse_subarray([1, 2, 3, 4, 5], 2, 4) == [1, 4, 3, 2, 5] assert reverse_subarray([1...
[ { "docstring": "Given an array and indices l and r, reverse the subarray from index l to r.", "function_declaration": "def reverse_subarray(array, l, r):", "function_name": "reverse_subarray", "parameter_list": "(array, l, r)" }, { "docstring": "Given the length n and a permutation p, this f...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reconstruct_permutation(p):\n n = len(p)\n \n # Initial Check if the array is already sorted\n if p == sorted(p):\n return \"!\" + ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00045159", "row_id": 45159, "seed_ids": "[4180]" }
0.726829
Code_Contests_45159
I
[ "reverse_subarray", "reconstruct_permutation" ]
2
[ [ "reconstruct_permutation", "reverse_subarray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e470022207d1eb0a0ee848d5afa0200c447eda06
0c4fd760fda94db275952a39d05a28fb15d78fed
v1.0
instruct
Code_Contests
Code_Contests_45203_I
Farmer John owns a rectangular farm that can be represented as a grid with n rows and m columns. Each cell in the grid can either be fertile (represented by `1`) or barren (represented by `0`). Farmer John can perform two types of operations: 1. Turn a specific barren cell into a fertile cell. 2. Query the largest...
def find_largest_region(grid, n, m): def dfs(x, y): stack = [(x, y)] size = 0 while stack: cx, cy = stack.pop() if 0 <= cx < n and 0 <= cy < m and grid[cx][cy] == 1 and not visited[cx][cy]: visited[cx][cy] = True size += 1 ...
from solution import manage_farm def test_manage_farm_example_1(): n, m, q = 3, 3, 6 operations = ["1 0 0", "1 0 1", "2", "1 1 0", "1 2 0", "2"] assert manage_farm(n, m, q, operations) == [2, 4] def test_manage_farm_single_cell(): n, m, q = 1, 1, 2 operations = ["1 0 0", "2"] assert manage_far...
[ { "docstring": null, "function_declaration": "def find_largest_region(grid, n, m):", "function_name": "find_largest_region", "parameter_list": "(grid, n, m)" }, { "docstring": null, "function_declaration": "def manage_farm(n, m, q, operations):", "function_name": "manage_farm", "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_fertile_region(grid, n, m):\n def dfs(x, y):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == 0:\n return 0\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045203", "row_id": 45203, "seed_ids": "[3171]" }
0.680328
Code_Contests_45203
I
[ "find_largest_region", "manage_farm" ]
2
[ [ "manage_farm", "find_largest_region" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a46ea4f16edbe1d1982c33df9c65876618f67a17
638ba0789bc3ca5760d5e188aceff21c8ab0532d
v1.0
instruct
Code_Contests
Code_Contests_45242_I
Matrix Chain Multiplication is a classic problem of dynamic programming. Given a sequence of matrices, the task is to find the most efficient way to multiply these matrices together. A matrix A[i] has dimensions p[i-1] x p[i]. You want to know in which order to multiply the matrices so that the total number of scalar ...
def matrix_chain_order(p): """ Function to find the minimum number of scalar multiplications needed to compute the matrix chain product. Parameters: p (list): A list of integers where p[i] is the dimension of the matrix. Returns: int: The minimum number of scalar multiplications ne...
def test_matrix_chain_order(): assert min_matrix_mult(4, [1, 2, 3, 4, 5]) == 38 assert min_matrix_mult(3, [10, 20, 30, 40]) == 18000 assert min_matrix_mult(2, [10, 100, 5]) == 5000 assert min_matrix_mult(5, [4, 10, 3, 12, 20, 7]) == 1344 assert min_matrix_mult(4, [2, 3, 6, 4, 5]) == 124 def test_ma...
[ { "docstring": "Function to find the minimum number of scalar multiplications needed\nto compute the matrix chain product.\n\nParameters:\np (list): A list of integers where p[i] is the dimension of the matrix.\n\nReturns:\nint: The minimum number of scalar multiplications needed.", "function_declaration": ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_chain_order(p):\n \"\"\"\n Returns the minimum number of scalar multiplications needed to multiply\n a sequence of matrices.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045242", "row_id": 45242, "seed_ids": "[974]" }
0.538894
Code_Contests_45242
I
[ "matrix_chain_order", "min_matrix_mult" ]
2
[ [ "min_matrix_mult", "matrix_chain_order" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ab3b046e8d1133ffb1e666dda101d0f108b41a3d
74b4951b60b4fd9b0d8d4d8209753fbdf42cd1fd
v1.0
instruct
Code_Contests
Code_Contests_45264_I
In a certain magical land, there is a series of bridges connecting different islands. These islands and bridges can be represented as an undirected graph where islands are vertices and bridges are edges. Unfortunately, some of the bridges are fragile and will collapse if used. You have to help the inhabitants check fo...
def find_connected_components(n, edges, to_remove): from collections import defaultdict, deque # Create the adjacency list for the graph adj_list = defaultdict(list) for u, v in edges: adj_list[u].append(v) adj_list[v].append(u) # Remove the specified edges for u, v in to_r...
def test_find_connected_components(): # Test case 1 n = 7 m = 6 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)] k = 2 to_remove = [(2, 3), (4, 5)] assert count_components_after_edge_removal(n, m, edges, k, to_remove) == 3 # Test case 2 n = 5 m = 4 edges = [(1, 2), (...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, edges, to_remove):", "function_name": "find_connected_components", "parameter_list": "(n, edges, to_remove)" }, { "docstring": null, "function_declaration": "def count_components_after_edge_removal(n, m, edges...
[ 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_connected_components(n, edges, to_remove):\n from collections import defaultdict, deque\n\n # Initialize adjacency list\n graph = defaul...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00045264", "row_id": 45264, "seed_ids": "[8608]" }
0.65684
Code_Contests_45264
I
[ "find_connected_components", "count_components_after_edge_removal" ]
2
[ [ "count_components_after_edge_removal", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a3747d23809b49be31194741b1bda764419e37ef
331cb879e1fb7ae9ee8fd9258a66546155d34339
v1.0
instruct
Code_Contests
Code_Contests_45274_I
You are given an infinite 2D grid. In each cell, there can be some gold coins. Given an initial position (x, y) on the grid, you need to find the maximum amount of gold you can collect if you're only allowed to move right or down from any cell. Initially, you are given n coordinates, each specifying a cell in the grid...
def calculate_max_gold(x, y, grid): """ Returns the maximum gold that can be collected starting from (x, y). """ max_gold = 0 for (a, b), g in grid.items(): if a >= x and b >= y: max_gold = max(max_gold, g) return max_gold def process_updates(x, y, initial_gold, updates): ...
def test_calculate_max_gold(): grid = { (0, 1): 5, (1, 0): 10, (1, 1): 15 } assert calculate_max_gold(0, 0, grid) == 15 assert calculate_max_gold(0, 1, grid) == 15 assert calculate_max_gold(1, 0, grid) == 15 assert calculate_max_gold(1, 1, grid) == 15 assert calculate...
[ { "docstring": "Returns the maximum gold that can be collected starting from (x, y).", "function_declaration": "def calculate_max_gold(x, y, grid):", "function_name": "calculate_max_gold", "parameter_list": "(x, y, grid)" }, { "docstring": "Process each update and return a list of maximum go...
[ 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_gold_collectable(x, y, gold_cells, updates):\n \"\"\"\n Calculate the maximum gold collectable on a 2D grid from a starting position (x, y).\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045274", "row_id": 45274, "seed_ids": "[7622]" }
0.66047
Code_Contests_45274
I
[ "calculate_max_gold", "process_updates" ]
2
[ [ "process_updates", "calculate_max_gold" ] ]
1
[]
false
[]
false
pytest
false
[]
true
fe1a385cd59375bc5fe7855118596967be8bc4e2
7f7bb7697c0f68155e31fc32533d3fbb3f1af0fd
v1.0
instruct
Code_Contests
Code_Contests_45286_I
You are given a grid with n rows and m columns, where each cell contains a lowercase English letter. Your task is to perform queries on this grid to determine if a specified pattern of consecutive letters can be found as a subsequence in any row of the grid. ### Queries Each query will consist of a string pattern. Yo...
def is_subsequence(s: str, t: str) -> bool: """ Check if string s is a subsequence of string t. Args: s: str - the subsequence string. t: str - the string to check against. Returns: bool - True if s is a subsequence of t, False otherwise. """ iter_t = iter(t) return all(char in ...
import pytest from solution import find_subsequence_in_grid, is_subsequence def test_is_subsequence(): assert is_subsequence("abc", "abcde") == True assert is_subsequence("fhi", "fghij") == True assert is_subsequence("xyz", "abcde") == False assert is_subsequence("ace", "abcde") == True assert is_s...
[ { "docstring": "Check if string s is a subsequence of string t.\nArgs:\ns: str - the subsequence string.\nt: str - the string to check against.\n\nReturns:\nbool - True if s is a subsequence of t, False otherwise.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence", ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(sub, main_str):\n # Function to check if `sub` is a subsequence of `main_str`\n it = iter(main_str)\n return all(char in it for...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00045286", "row_id": 45286, "seed_ids": "[2440]" }
0.693249
Code_Contests_45286
I
[ "is_subsequence", "find_subsequence_in_grid" ]
2
[ [ "find_subsequence_in_grid", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
212e388a48584b9965f7f3d31f2cbe39a741ae47
0f442abd9e0ad9ad6d41e531f1e4a03001b03467