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_3308_I
Alex is building a new bookshelf and needs to organize `N` books in a specific order. Each book has a unique ID from 1 to N and a designated position that specifies a partial order they should follow. Given this partial order, determine if you can arrange all books in such a way that satisfies the conditions provided....
from collections import defaultdict, deque def find_lexicographically_smallest_order(N, M, constraints): """ Determines the lexicographically smallest order of books given the constraints. Parameters: N (int): Number of books M (int): Number of constraints constraints (list of tuples): Eac...
from solution import bookshelf_order def test_bookshelf_order_example_1(): input_str = "4 3\n1 3\n2 3\n1 4" assert bookshelf_order(input_str) == "1 2 3 4" def test_bookshelf_order_example_2(): input_str = "4 2\n2 3\n3 2" assert bookshelf_order(input_str) == "-1" def test_bookshelf_order_example_3(): ...
[ { "docstring": "Determines the lexicographically smallest order of books given the constraints.\n\nParameters:\nN (int): Number of books\nM (int): Number of constraints\nconstraints (list of tuples): Each tuple contains (p, q) which represents book p should be before book q\n\nReturns:\nlist or int: Lexicograph...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_lexicographically_smallest_order(N, M, constraints):\n # Create adjacency list and in-degree list...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003308", "row_id": 3308, "seed_ids": "[11430]" }
0.738933
Code_Contests_3308
I
[ "find_lexicographically_smallest_order", "bookshelf_order" ]
2
[ [ "bookshelf_order", "find_lexicographically_smallest_order" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e6e811619dd2e1847a409058c6808fad877360a9
a6288048fbb7d01ad6797d0eb02377d3bae50f37
v1.0
instruct
Code_Contests
Code_Contests_3351_I
String Permutation Puzzle Alice loves solving puzzles with strings. Today, she has come across a new type of puzzle which involves permuting substrings. Given a string S, she wants to figure out in how many different ways she can rearrange its characters so that no character ends up in its original position. This kin...
from math import factorial def count_derangements(n): """ Calculate the number of derangements for a sequence of length n using the formula: !n = (n-1) * (!(n-1) + !(n-2)) """ if n == 0: return 1 elif n == 1: return 0 elif n == 2: return 1 derangements = [0]...
from solution import derangement_count def test_derangement_count_single_letter(): assert derangement_count("A") == 0 def test_derangement_count_two_letters(): assert derangement_count("AB") == 1 def test_derangement_count_five_letters(): assert derangement_count("ABCDE") == 44 def test_derangement_coun...
[ { "docstring": "Calculate the number of derangements for a sequence of length n using the formula:\n!n = (n-1) * (!(n-1) + !(n-2))", "function_declaration": "def count_derangements(n):", "function_name": "count_derangements", "parameter_list": "(n)" }, { "docstring": "Given a string `s`, com...
[ 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 factorial\n\ndef derangement(n):\n if n == 0:\n return 1\n if n == 1:\n return 0\n d = [0] * (n + 1)\n d[0] = 1\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003351", "row_id": 3351, "seed_ids": "[3533]" }
0.651206
Code_Contests_3351
I
[ "count_derangements", "derangement_count" ]
2
[ [ "derangement_count", "count_derangements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
634e1089a443abc2f454d7a6a176a3b4d1cfbe5c
98609a5d45a91c68bb5f598af2574450c6362fd2
v1.0
instruct
Code_Contests
Code_Contests_3363_I
Given a string S and a set of words D, find the longest word in D that is a subsequence of S. A subsequence is defined as a new string generated from the original string with some characters(can be none) deleted without changing the relative order of the remaining characters. Input: - The first line contains the st...
def is_subsequence(s, word): it = iter(s) return all(char in it for char in word) def find_longest_word(s, d): d.sort(key=lambda x: (-len(x), x)) for word in d: if is_subsequence(s, word): return word return ''
from solution import find_longest_word def test_case_1(): s = "abppplee" d = ["able", "ale", "apple"] assert find_longest_word(s, d) == "apple" def test_case_2(): s = "abppplee" d = ["a", "b", "c"] assert find_longest_word(s, d) == "a" def test_case_3(): s = "abppplee" d = ["bpp", "bp...
[ { "docstring": null, "function_declaration": "def is_subsequence(s, word):", "function_name": "is_subsequence", "parameter_list": "(s, word)" }, { "docstring": null, "function_declaration": "def find_longest_word(s, d):", "function_name": "find_longest_word", "parameter_list": "(...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(s, word):\n \"\"\"\n Helper function to check if 'word' is a subsequence of 's'.\n \"\"\"\n it = iter(s)\n return all(cha...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003363", "row_id": 3363, "seed_ids": "[7398]" }
0.781344
Code_Contests_3363
I
[ "is_subsequence", "find_longest_word" ]
2
[ [ "find_longest_word", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
45794fc84b7b4117b1f5c39f6b044622abfa83cc
c0ee9e4077b76fefec1f6ad253f5b6c0befe952d
v1.0
instruct
Code_Contests
Code_Contests_3382_I
problem In a binary tree, each node contains an integer value. Let's define the depth of a binary tree node as the number of edges from the node to the tree's root. The root node has a depth of 0. Define the "depth sum" of a node as the product of the node's value and its depth. For example, in the following tree: ``...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(nodes_info): if not nodes_info: return None node_list = [TreeNode(val) for val, _, _ in nodes_info] for index, (val, left, right...
import pytest from solution import total_depth_sum def test_example(): N = 5 nodes_info = [ (1, 1, 2), (2, 3, 4), (3, -1, -1), (4, -1, -1), (5, -1, -1) ] assert total_depth_sum(N, nodes_info) == 23 def test_single_node(): N = 1 nodes_info = [ (10...
[]
[ 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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.value = key\n\ndef build_tree(node_descrip...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003382", "row_id": 3382, "seed_ids": "[90]" }
0.701453
Code_Contests_3382
I
[ "build_tree", "calculate_depth_sum", "total_depth_sum" ]
3
[ [ "total_depth_sum", "build_tree" ], [ "total_depth_sum", "calculate_depth_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e81583eef44685627847084cb31280da47f2cdc3
bb0f72fdb220bb60f4b6ba50ef80e4820898a0ee
v1.0
instruct
Code_Contests
Code_Contests_3414_I
Polycarp recently discovered that some websites handle URLs in a way that they redirect to canonical URLs. Specifically, some websites leverage URL shortening services, others might consider URLs with www and without www as the same, and some even ignore or change parameters in the URL query string except specific para...
from urllib.parse import urlparse, parse_qsl def canonical_url(url): """ Converts a URL into its canonical form by: - Removing 'www.' if it exists - Sorting the query parameters """ parsed_url = urlparse(url) # Remove 'www.' if it exists netloc = parsed_url.netloc.replace('www.', '...
from solution import merge_urls def test_merge_urls_example(): n = 6 urls = [ "http://example.com/path?a=1&b=2", "https://example.com/path?a=1&b=2", "http://www.example.com/path?b=2&a=1", "http://example.com/otherpath?p=5&q=4", "http://www.example.com/path?a=2&b=1", ...
[ { "docstring": "Converts a URL into its canonical form by:\n- Removing 'www.' if it exists\n- Sorting the query parameters", "function_declaration": "def canonical_url(url):", "function_name": "canonical_url", "parameter_list": "(url)" }, { "docstring": "Groups the URLs into their respective...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from urllib.parse import urlparse, parse_qs\n\ndef normalize_url(url):\n parsed = urlparse(url)\n protocol = parsed.scheme\n domain = parsed.netlo...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00003414", "row_id": 3414, "seed_ids": "[8692]" }
0.458471
Code_Contests_3414
I
[ "canonical_url", "group_urls", "merge_urls" ]
3
[ [ "group_urls", "canonical_url" ], [ "merge_urls", "group_urls" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3f3495d1b0cb8e3af207b2e2edcc0dc71e3ecc0e
16ad52e8da710ef6fb0a7b737f1f6811c8138d77
v1.0
instruct
Code_Contests
Code_Contests_3452_I
Alex and Sam are working on a security system that requires them to periodically update their credentials. They have multiple passwords, each with a unique reset interval. They want to find the earliest time when all passwords will need to be reset simultaneously after a certain starting point in time (t=0). Here is t...
from math import gcd from functools import reduce def lcm(a, b): return abs(a * b) // gcd(a, b) def lcm_multiple(numbers): return reduce(lcm, numbers) def earliest_password_reset(T, test_cases): results = [] modulo = 1000000007 for i in range(T): n, intervals = test_cases[i] resul...
from solution import earliest_password_reset def test_earliest_password_reset(): T = 1 test_cases = [(3, [5, 10, 15])] assert earliest_password_reset(T, test_cases) == [30] def test_single_interval(): T = 1 test_cases = [(1, [7])] assert earliest_password_reset(T, test_cases) == [7] def test_...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm_multiple(numbers):", "function_name": "lcm_multiple", "parameter_list": "(numbers)" }, { "docstring":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\nMOD = 1000000007\n\ndef lcm(a, b):\n return (a * b) // math.gcd(a, b)\n\ndef find_reset_time(n, intervals):\n reset_time = intervals[0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003452", "row_id": 3452, "seed_ids": "[5072]" }
0.574766
Code_Contests_3452
I
[ "lcm", "lcm_multiple", "earliest_password_reset" ]
3
[ [ "earliest_password_reset", "lcm_multiple" ], [ "lcm_multiple", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a582b9c23629a613de6babc5149e95083b44315d
2b40e1905180968d4e48ce5fe0ddf9207e61320f
v1.0
instruct
Code_Contests
Code_Contests_3464_I
Given an undirected tree with N nodes, your task is to determine the maximum path sum in the tree. Each node has a value associated with it and the path sum is defined as the sum of the values of the nodes along the path. Input format: - The first line contains the integer N, the number of nodes in the tree. - The sec...
from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(node, parent, adjacency_list, values): max_single_path = values[node] max_top_path = values[node] max_child1 = max_child2 = float('-inf') for neighbor in adjacency_list[node]: if neighbor == parent: ...
from solution import max_path_sum def test_example1(): n = 5 node_values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (3, 5)] assert max_path_sum(n, node_values, edges) == 15 def test_example2(): n = 3 node_values = [-1, -2, -3] edges = [(1, 2), (1, 3)] assert max_path_sum(n, nod...
[ { "docstring": null, "function_declaration": "def dfs(node, parent, adjacency_list, values):", "function_name": "dfs", "parameter_list": "(node, parent, adjacency_list, values)" }, { "docstring": null, "function_declaration": "def max_path_sum(n, node_values, edges):", "function_name...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nimport sys\nsys.setrecursionlimit(200000)\n\ndef find_maximum_path_sum(n, node_values, edges):\n tree = defaultdict...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00003464", "row_id": 3464, "seed_ids": "[8535]" }
0.719152
Code_Contests_3464
I
[ "dfs", "max_path_sum" ]
2
[ [ "max_path_sum", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
187c1312b2b590b9388495b81bb637ae340253f0
e4333508c01689df2cf48d1fbeff4a9bdb5486b6
v1.0
instruct
Code_Contests
Code_Contests_3474_I
In a distant land, there lived a passionate gardener named Sofia, who loved to plant trees in her garden. Sofia's favorite type of tree is the "Binary Tree." A Binary Tree is a data structure in which each node has at most two children, typically distinguished as "left" and "right." One day, Sofia decided to make her ...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree_from_input(input_lines): nodes = {} for line in input_lines: if line == '-1 -1 -1': break value, left, right = map(int, line.split()) i...
from solution import solution def test_balanced_tree(): input_lines = [ "1 2 3", "2 -1 4", "4 -1 -1", "3 -1 5", "5 -1 -1", "-1 -1 -1" ] assert solution(input_lines) == "YES" def test_unbalanced_tree(): input_lines = [ "1 2 3", "2 4 -1", ...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree_from_inp...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003474", "row_id": 3474, "seed_ids": "[8759]" }
0.814055
Code_Contests_3474
I
[ "build_tree_from_input", "is_balanced", "solution" ]
3
[ [ "solution", "build_tree_from_input" ], [ "solution", "is_balanced" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0f9b33dea987a5d6d9761aba0ac75747dcfba23a
692c910a84ba9c33f8a0f0c598617e61abf5e84f
v1.0
instruct
Code_Contests
Code_Contests_3510_I
Problem Statement: Alex is exploring number theory and has encountered the concept of prime numbers. He is particularly interested in understanding the distribution of prime numbers within a specified range. He decides to write a program that determines the number of prime numbers between two given integers, inclusive....
def sieve_of_eratosthenes(limit): """ Generates a list of boolean values, where index indicates number and value indicates if it's prime. Uses the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers for ...
def test_sieve_of_eratosthenes(): sieve = sieve_of_eratosthenes(20) assert sieve[2] == True assert sieve[3] == True assert sieve[4] == False assert sieve[5] == True assert sieve[6] == False assert sieve[17] == True assert sieve[18] == False assert sieve[19] == True def test_count_pr...
[ { "docstring": "Generates a list of boolean values, where index indicates number and value indicates if it's prime.\nUses the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, {...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generates a list of boolean values, where index indicates number and value indicates if it's prime.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003510", "row_id": 3510, "seed_ids": "[11737]" }
0.654646
Code_Contests_3510
I
[ "sieve_of_eratosthenes", "count_primes_in_range", "count_primes_in_ranges" ]
3
[ [ "count_primes_in_ranges", "count_primes_in_range" ], [ "count_primes_in_ranges", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
false
[]
true
7448063240f62361b0bcd938815da50eedc88ed9
39832958395e91ada623ef8655965be22f4a817b
v1.0
instruct
Code_Contests
Code_Contests_3527_I
Zara, the Zebra, loves playing with numbers. She has recently come up with a fascinating number game involving prime numbers and sums. The game starts with an array b of length m consisting of positive integers. Zara’s goal is to determine whether there exists a subset of numbers within b whose sum is a prime number. ...
from itertools import combinations def is_prime(n): """ Checks if a number n (n > 1) 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: ...
from solution import solve def test_example_cases(): test_cases = [ (4, [1, 2, 3, 4]), (3, [8, 10, 12]), (5, [4, 3, 6, 9, 11]) ] results = solve(test_cases) assert results == ["YES", "NO", "YES"] def test_single_element_cases(): test_cases = [ (1, [2]), (1, ...
[ { "docstring": "Checks if a number n (n > 1) is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of integers b, checks if there is a subset with a prime sum.", "function_declaration": "def subset_pri...
[ 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 itertools import combinations\nfrom math import isqrt\n\ndef is_prime(n):\n \"\"\"Returns True if n is a prime number, else False.\"\"\"\n if n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003527", "row_id": 3527, "seed_ids": "[5024]" }
0.596798
Code_Contests_3527
I
[ "is_prime", "subset_prime_sum_exists", "solve" ]
3
[ [ "solve", "subset_prime_sum_exists" ], [ "subset_prime_sum_exists", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2e47f2afa1fd17ef234f09bbafe1d23ae14dff49
5f539b69b6caa06ea3c49ff8a8d29e0cef9d3941
v1.0
instruct
Code_Contests
Code_Contests_3542_I
You are given an array of n integers. You need to answer several queries about the sum of the integers in the array within certain ranges. Each query consists of two integers l and r (1 ≤ l ≤ r ≤ n), and you need to find the sum of the array elements from index l to index r (inclusive). Your task is to process q queri...
def preprocess_prefix_sums(arr): """ Preprocess the prefix sums of the array. Returns a list where prefix_sums[i] is the sum of elements from arr[0] to arr[i-1]. """ n = len(arr) prefix_sums = [0] * (n + 1) for i in range(1, n + 1): prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1] ...
from solution import preprocess_prefix_sums, range_sum, process_queries def test_preprocess_prefix_sums(): arr = [1, 2, 3, 4, 5] expected = [0, 1, 3, 6, 10, 15] assert preprocess_prefix_sums(arr) == expected def test_range_sum(): prefix_sums = [0, 1, 3, 6, 10, 15] assert range_sum(prefix_sums, 1, ...
[ { "docstring": "Preprocess the prefix sums of the array.\nReturns a list where prefix_sums[i] is the sum of elements from arr[0] to arr[i-1].", "function_declaration": "def preprocess_prefix_sums(arr):", "function_name": "preprocess_prefix_sums", "parameter_list": "(arr)" }, { "docstring": "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_prefix_sums(array):\n # Compute prefix sums for the array\n prefix_sums = [0] * (len(array) + 1)\n for i in range(1, len(array) + 1):\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003542", "row_id": 3542, "seed_ids": "[4216]" }
0.683211
Code_Contests_3542
I
[ "preprocess_prefix_sums", "range_sum", "process_queries" ]
3
[ [ "process_queries", "preprocess_prefix_sums" ], [ "process_queries", "range_sum" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
58d9e61d072800dd915cd1bc82cc269f75ff07b5
f4b82cdd84c7811a3a4e0e62aba11eb688e79f7e
v1.0
instruct
Code_Contests
Code_Contests_3564_I
You are given a grid of size N x M filled with some characters. You are also given a list of words. Your task is to find out how many times each word appears in the grid. A word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are those horizontally or vertically neighboring. The...
def find_word_in_grid(grid, word): rows, cols = len(grid), len(grid[0]) word_len = len(word) def backtrack(r, c, index): if index == word_len: return True if r < 0 or r >= rows or c < 0 or c >= cols or grid[r][c] == '#': return False if word[index] ...
import pytest from solution import word_count_grid def test_example_1(): n, m = 3, 4 grid = ["abce", "sfcs", "adee"] words = ["see", "bee", "sad"] expected_output = [1, 0, 1] assert word_count_grid(n, m, grid, len(words), words) == expected_output def test_example_2(): n, m = 4, 5 grid = [...
[ { "docstring": null, "function_declaration": "def find_word_in_grid(grid, word):", "function_name": "find_word_in_grid", "parameter_list": "(grid, word)" }, { "docstring": null, "function_declaration": "def word_count_grid(n, m, grid, num_words, words):", "function_name": "word_count...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_words(grid, words):\n def dfs(board, word, x, y, index, visited):\n if index == len(word):\n return True\n if (x < 0 o...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003564", "row_id": 3564, "seed_ids": "[5191]" }
0.689089
Code_Contests_3564
I
[ "find_word_in_grid", "word_count_grid" ]
2
[ [ "word_count_grid", "find_word_in_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac768f9a457a350e2e096c00abd76cff8a80e0e3
7850ad230b65c07c54d1f9e6b6a24ae4ac37bb0e
v1.0
instruct
Code_Contests
Code_Contests_3594_I
You are given an array of integers. One integer from the array occurs odd number of times while all others occur even number of times. Find the integer which occurs odd number of times. Input The first line contains a single integer n (1 ≤ n ≤ 10^5), the number of elements in the array. The second line contains n spa...
def find_odd_occurrence(arr): """ Returns the integer that occurs odd number of times in the array. """ result = 0 for number in arr: result ^= number return result def find_odd_occurrence_from_input(input_str): """ Processes the input string and returns the integer that occurs ...
def test_find_odd_occurrence(): assert find_odd_occurrence([1, 2, 3, 2, 3]) == 1 assert find_odd_occurrence([4, 4, 4, 5, 5, 5, 5]) == 4 assert find_odd_occurrence([10]) == 10 assert find_odd_occurrence([2, 2, 3, 3, 4]) == 4 assert find_odd_occurrence([9, 12, 12, 9, 15, 15, 16, 16, 16]) == 16 def te...
[ { "docstring": "Returns the integer that occurs odd number of times in the array.", "function_declaration": "def find_odd_occurrence(arr):", "function_name": "find_odd_occurrence", "parameter_list": "(arr)" }, { "docstring": "Processes the input string and returns the integer that occurs odd...
[ 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_odd_occurrence(arr):\n \"\"\"\n Finds the integer which occurs odd number of times in the array.\n \n Args:\n arr: List of integers...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003594", "row_id": 3594, "seed_ids": "[1576]" }
0.70541
Code_Contests_3594
I
[ "find_odd_occurrence", "find_odd_occurrence_from_input" ]
2
[ [ "find_odd_occurrence_from_input", "find_odd_occurrence" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a27ce1ddcb6395e9183188c1081b46326a59b8b2
65717786c38b4ba004c37e414e261e4d74868dcd
v1.0
instruct
Code_Contests
Code_Contests_3632_I
A strictly increasing sequence of integers a1, a2, ..., an is called a magical sequence if it satisfies the following conditions: 1. a1 = 1. 2. For every integer m ≥ 1, am + 1 is the smallest integer that is greater than am and cannot be represented as the sum of 1 or more (not necessarily distinct) elements from the s...
def magical_sequence(n): """ Generates the first n elements of the magical sequence. """ seq = [1] for _ in range(1, n): next_element = seq[-1] + 1 while not is_non_summable(next_element, seq): next_element += 1 seq.append(next_element) return seq def is_non_...
from solution import magical_sequence def test_magical_sequence_5(): assert magical_sequence(5) == [1, 2, 4, 8, 16] def test_magical_sequence_10(): assert magical_sequence(10) == [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] def test_magical_sequence_1(): assert magical_sequence(1) == [1] def test_magical_seq...
[ { "docstring": "Generates the first n elements of the magical sequence.", "function_declaration": "def magical_sequence(n):", "function_name": "magical_sequence", "parameter_list": "(n)" }, { "docstring": "Checks if a number cannot be represented as the sum of one or more\nelements in the se...
[ 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 magical_sequence(n):\n \"\"\"\n Generates the first n elements of the magical sequence.\n \"\"\"\n seq = [1]\n for _ in range(1, n):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003632", "row_id": 3632, "seed_ids": "[4334]" }
0.570843
Code_Contests_3632
I
[ "magical_sequence", "is_non_summable" ]
2
[ [ "magical_sequence", "is_non_summable" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aece11f1712f450777e26b1899ec1b12875c92c6
1aaaec91cfc2d000b15a2c5e241f6fd2e1f63f84
v1.0
instruct
Code_Contests
Code_Contests_3648_I
**Problem Statement:** Alice loves collecting gemstones. She has a large collection of gemstones, where each gemstone is represented by a positive integer. Alice wants to distribute her collection of gemstones in such a way that each group of gemstones contains the same gemstones with the same count as in the original...
def gcd(a, b): while b: a, b = b, a % b return a def find_max_groups(N, gemstone_counts): if N == 1: return gemstone_counts[0] result_gcd = gemstone_counts[0] for count in gemstone_counts[1:]: result_gcd = gcd(result_gcd, count) return result_gcd def gemstone_...
def test_simple_case(): T = 1 cases = [(3, [2, 4, 6])] assert gemstone_groups(T, cases) == [2] def test_another_case(): T = 1 cases = [(4, [6, 3, 9, 12])] assert gemstone_groups(T, cases) == [3] def test_single_gem_type(): T = 1 cases = [(1, [100])] assert gemstone_groups(T, cases)...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def find_max_groups(N, gemstone_counts):", "function_name": "find_max_groups", "parameter_list": "(N, gemstone_counts...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\nfrom math import gcd\n\ndef possible_groups(N, counts):\n \"\"\"\n Determines the number of ways Alice can...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003648", "row_id": 3648, "seed_ids": "[730]" }
0.656227
Code_Contests_3648
I
[ "gcd", "find_max_groups", "gemstone_groups" ]
3
[ [ "find_max_groups", "gcd" ], [ "gemstone_groups", "find_max_groups" ] ]
2
[]
false
[]
false
pytest
false
[]
true
b660820dafc5e0fec36c36d007b22b98da44e346
14d2fb616860b0aee11660faaa4f6063f236c095
v1.0
instruct
Code_Contests
Code_Contests_3667_I
In a distant future, engineers are working on a highly efficient and budget-friendly set of N interconnected cities with well-defined highways. Each highway connects one city to another directly, and there’s exactly one unique path between any pair of cities, ensuring no cycles in the network. Due to a recent alien at...
from collections import deque def bfs_longest_path(adj_list, start_node): """ Perform BFS to compute the farthest node and the distance from start_node """ n = len(adj_list) distances = [-1] * n queue = deque([start_node]) distances[start_node] = 0 farthest_node = start_node while ...
import pytest from solution import solve def test_example_case_1(): test_cases = [ { "n": 4, "m": 3, "highways": [ (1, 2), (2, 3), (3, 4) ] } ] assert solve(test_cases) == [3] def test_example_c...
[ { "docstring": "Perform BFS to compute the farthest node and the distance from start_node", "function_declaration": "def bfs_longest_path(adj_list, start_node):", "function_name": "bfs_longest_path", "parameter_list": "(adj_list, start_node)" }, { "docstring": "Computes the longest path in 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": "from collections import deque\n\ndef bfs_longest_path(adj_list, start_node):\n \"\"\"\n Perform BFS to compute the farthest node and the distance fro...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003667", "row_id": 3667, "seed_ids": "[11107]" }
0.730424
Code_Contests_3667
I
[ "bfs_longest_path", "longest_path", "solve" ]
3
[ [ "longest_path", "bfs_longest_path" ], [ "solve", "longest_path" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f549d4bb2948ff5d636a142bc03ae4de3d338e3a
b0a6d5cb6dfef1aac4069de0884d3dc3a3c04718
v1.0
instruct
Code_Contests
Code_Contests_3705_I
## Problem: Magical Tree Traversal Jon is practicing his tree traversal algorithms in the magical forest of Norland. The forest is represented as a binary tree where each node has a value and can have up to two child nodes (a left child and a right child). However, the tree can behave magically in such a way that any ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def max_path_sum(root): if not root: return 0 left_sum = max_path_sum(root.left) right_sum = max_path_sum(root.right) return root.value + max(...
from solution import magical_tree_traversal def test_example_case(): n = 5 nodes_info = [(10, 1, 2), (2, -1, -1), (10, 3, 4), (1, -1, -1), (5, -1, -1)] assert magical_tree_traversal(n, nodes_info) == 25 def test_single_node_tree(): n = 1 nodes_info = [(10, -1, -1)] assert magical_tree_traversa...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=-1, right=-1):\n self.value = value\n self.left = left\n self.right = right\n\nd...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003705", "row_id": 3705, "seed_ids": "[3747]" }
0.672032
Code_Contests_3705
I
[ "max_path_sum", "build_tree", "magical_tree_traversal" ]
3
[ [ "magical_tree_traversal", "build_tree" ], [ "magical_tree_traversal", "max_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
3ed809cdc0f7431e4dc803572695dc7dd01ce0d4
a748961da1a315fa8843f46b3c5a236992124543
v1.0
instruct
Code_Contests
Code_Contests_3736_I
In a far-off kingdom, there resides a wise mathematician named Aria. Aria loves playing with numbers, especially focusing on prime numbers and their properties. She has recently discovered an interesting property concerning prime factors and wants to explore it further. Given an integer n (1 ≤ n ≤ 10^6), Aria wants to...
def find_prime_factors(n): """ Returns the list of prime factors of n. """ prime_factors = [] # Check for number of 2s that divide n while n % 2 == 0: prime_factors.append(2) n = n // 2 # n must be odd at this point so a skip of 2 (i = i + 2) can be used for i in ran...
import pytest from solution import find_prime_factors, max_prime_factor_diff, process_test_cases def test_find_prime_factors(): assert find_prime_factors(6) == [2, 3] assert find_prime_factors(15) == [3, 5] assert find_prime_factors(13) == [13] assert find_prime_factors(28) == [2, 7] assert find_pr...
[ { "docstring": "Returns the list of prime factors of n.", "function_declaration": "def find_prime_factors(n):", "function_name": "find_prime_factors", "parameter_list": "(n)" }, { "docstring": "Returns the maximum difference between any two prime factors of n.", "function_declaration": "...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n is_prime = [True] * (limit + 1)\n p = 2\n while p * p <= limit:\n if is_prime[p]:\n for i in...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00003736", "row_id": 3736, "seed_ids": "[2420]" }
0.66139
Code_Contests_3736
I
[ "find_prime_factors", "max_prime_factor_diff", "process_test_cases" ]
3
[ [ "max_prime_factor_diff", "find_prime_factors" ], [ "process_test_cases", "max_prime_factor_diff" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
e00928781eb9811edbba72663d627360df944b25
7d2debfb369ab7384484a27d0cb6f7b8f8132ea5
v1.0
instruct
Code_Contests
Code_Contests_3740_I
Alice is a researcher and developer who specializes in exploring sequences and their properties. She recently encountered a sequence transformation problem and needs your assistance. Define a function g(a) where `a` is a sequence of positive integers. Function g(a) returns the transformed sequence based on the followi...
def sum_of_digits(n): """ Returns the sum of the digits of a number n. """ return sum(int(digit) for digit in str(n)) def g(a): """ Transforms the sequence a by replacing each element with the sum of its digits. """ return [sum_of_digits(num) for num in a] def find_Ym(Y, m): """ ...
from solution import sum_of_digits, g, find_Ym, Y_sequence def test_sum_of_digits(): assert sum_of_digits(123) == 6 assert sum_of_digits(29) == 11 assert sum_of_digits(7) == 7 assert sum_of_digits(11111) == 5 def test_g(): assert g([123, 29, 7]) == [6, 11, 7] assert g([999]) == [27] assert...
[ { "docstring": "Returns the sum of the digits of a number n.", "function_declaration": "def sum_of_digits(n):", "function_name": "sum_of_digits", "parameter_list": "(n)" }, { "docstring": "Transforms the sequence a by replacing each element with the sum of its digits.", "function_declara...
[ 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 digit_sum(n):\n \"\"\"\n Returns the sum of the digits of number n in base-10 representation.\n \"\"\"\n return sum(int(digit) for digit in...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003740", "row_id": 3740, "seed_ids": "[7333]" }
0.673459
Code_Contests_3740
I
[ "sum_of_digits", "g", "find_Ym", "Y_sequence" ]
4
[ [ "Y_sequence", "find_Ym" ], [ "find_Ym", "g" ], [ "g", "sum_of_digits" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c1eee4a24ed4cf823259d7dc713ffee71863319d
c9dd84488f06637ae26b60d77d3ab326275c57c5
v1.0
instruct
Code_Contests
Code_Contests_3761_I
Given an array of integers, determine the length of the longest subarray whose elements form a contiguous sequence (not necessarily distinct). Input Format: The first line contains an integer T, the number of test cases. Each of the next T test cases contains two lines: - The first line contains an integer N, the siz...
def longest_contiguous_subarray(arr): """ Determine the length of the longest subarray whose elements form a contiguous sequence. """ n = len(arr) max_len = 0 for i in range(n): min_elem, max_elem = arr[i], arr[i] for j in range(i, n): min_elem = min(min_elem, ar...
from solution import get_results_from_input, longest_contiguous_subarray, process_test_cases def test_longest_contiguous_subarray_single_case(): assert longest_contiguous_subarray([1, 2, 3, 5, 6]) == 3 assert longest_contiguous_subarray([10, 12, 11, 14, 13]) == 5 assert longest_contiguous_subarray([1, 1, 1...
[ { "docstring": "Determine the length of the longest subarray whose elements form a contiguous sequence.", "function_declaration": "def longest_contiguous_subarray(arr):", "function_name": "longest_contiguous_subarray", "parameter_list": "(arr)" }, { "docstring": null, "function_declarati...
[ 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_longest_contiguous_subarray_length(array):\n \"\"\"\n Returns length of the longest subarray with contiguous elements.\n \"\"\"\n\n de...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003761", "row_id": 3761, "seed_ids": "[4972]" }
0.788154
Code_Contests_3761
I
[ "longest_contiguous_subarray", "process_test_cases", "get_results_from_input" ]
3
[ [ "get_results_from_input", "process_test_cases" ], [ "process_test_cases", "longest_contiguous_subarray" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
2bf8a70f92e0e81001ea7821d412ed02e3842a46
700fd9b30e4d8a756f0c42fde8ad14725ee10590
v1.0
instruct
Code_Contests
Code_Contests_3764_I
You are given a list of cities with their respective coordinates on a 2D plane. Your task is to find the optimal way to connect all the cities using roads, so that the total length of the roads is minimized. This is essentially a Minimum Spanning Tree (MST) problem where each city is a vertex and the roads between citi...
import math import heapq def calculate_distance(x1, y1, x2, y2): return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def minimum_spanning_tree(cities): N = len(cities) if N == 0: return 0.0 # Initialize the adjacency list for the graph edges = [(0, i, 0) for i in range(N)] visited =...
from solution import solve_minimum_roads def test_example(): input_data = "4\n0 0\n0 1\n1 0\n1 1" output_data = solve_minimum_roads(input_data) assert output_data == 3.00 def test_single_city(): input_data = "1\n0 0" output_data = solve_minimum_roads(input_data) assert output_data == 0.00 def...
[ { "docstring": null, "function_declaration": "def calculate_distance(x1, y1, x2, y2):", "function_name": "calculate_distance", "parameter_list": "(x1, y1, x2, y2)" }, { "docstring": null, "function_declaration": "def minimum_spanning_tree(cities):", "function_name": "minimum_spanning...
[ 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": "import math\nimport heapq\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003764", "row_id": 3764, "seed_ids": "[10407]" }
0.689984
Code_Contests_3764
I
[ "calculate_distance", "minimum_spanning_tree", "solve_minimum_roads" ]
3
[ [ "minimum_spanning_tree", "calculate_distance" ], [ "solve_minimum_roads", "minimum_spanning_tree" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a3ffe9efc87310d1165a06cfefa6e5c9942bf42e
e41956588eb194b67403429156ebfc20d22ce361
v1.0
instruct
Code_Contests
Code_Contests_3779_I
Game Level Generator You are developing a game that includes a level generator. Each level is represented by a grid with rows and columns filled with various tiles. Each tile is assigned a number, representing different types of terrain or obstacles. The level generator must ensure that certain constraints are met for...
def validate_grid(grid, r, c): def is_connected(grid, r, c): def dfs(x, y): stack = [(x, y)] while stack: cx, cy = stack.pop() if visited[cx][cy]: continue visited[cx][cy] = True for nx, ny in ((cx + ...
import pytest from solution import main, parse_input, game_level_validator def test_main(): input_str = """4 5 2 1 0 2 2 1 2 2 0 1 2 2 1 1 1 1 1 1 2 2 2 2 3 10 1 5 10 3 3 1 1 1 1 1 0 1 1 1 1 1 6 6 0 0 0""" expected_output = "VALID\nINVALID" assert main(input_str) == expected_output def test_game_level_val...
[ { "docstring": null, "function_declaration": "def validate_grid(grid, r, c):", "function_name": "validate_grid", "parameter_list": "(grid, r, c)" }, { "docstring": null, "function_declaration": "def check_key_tiles(grid, r, c, key_constraints):", "function_name": "check_key_tiles", ...
[ 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_connected(grid, r, c):\n from collections import deque\n \n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n # Find first non-zer...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003779", "row_id": 3779, "seed_ids": "[2178]" }
0.690408
Code_Contests_3779
I
[ "validate_grid", "check_key_tiles", "game_level_validator", "parse_input", "main" ]
5
[ [ "game_level_validator", "check_key_tiles" ], [ "game_level_validator", "validate_grid" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
4c8e17de0fbc76fde8138e3bcf24d96d0a1fd030
7768ecb1dac7354ebd9133ce6295a21dc7f963fc
v1.0
instruct
Code_Contests
Code_Contests_3801_I
A company has an event scheduling system that allows employees to create, edit, or cancel events. Each event is represented by its start time and end time. However, events cannot overlap; that is, an employee cannot have two events scheduled at the same time. You are given a list of events, where each event is represe...
def to_minutes(time): hours, minutes = map(int, time.split(":")) return hours * 60 + minutes def can_add_event(existing_events, new_event): new_start = to_minutes(new_event[0]) new_end = to_minutes(new_event[1]) for event in existing_events: start = to_minutes(event[0]) end = to_mi...
def test_can_add_event_no_overlap(): existing_events = [("09:00", "10:30"), ("11:00", "12:00"), ("14:00", "15:30")] new_event = ("12:15", "13:45") assert can_add_event(existing_events, new_event) == True def test_can_add_event_overlap(): existing_events = [("09:00", "10:30"), ("11:00", "12:00"), ("14:0...
[ { "docstring": null, "function_declaration": "def to_minutes(time):", "function_name": "to_minutes", "parameter_list": "(time)" }, { "docstring": null, "function_declaration": "def can_add_event(existing_events, new_event):", "function_name": "can_add_event", "parameter_list": "(...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_add_event(existing_events, new_event):\n \"\"\"\n Checks if a new event can be added to the existing events list without any time conflicts.\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003801", "row_id": 3801, "seed_ids": "[10016]" }
0.610916
Code_Contests_3801
I
[ "to_minutes", "can_add_event" ]
2
[ [ "can_add_event", "to_minutes" ] ]
1
[]
false
[]
false
pytest
false
[]
true
866a6dca614ec630f84b708e7dc3f38e01dad58d
75f76b3296208666d0e3b49fd74a4ec1e27c065b
v1.0
instruct
Code_Contests
Code_Contests_3802_I
Samuel is an enthusiast for prime numbers and loves constructing prime chains. A prime chain of length n is a sequence of n distinct prime numbers in which each prime number is strictly greater than the previous one. He has a unique rule though: he wants all the prime numbers in the chain to have the same number of dig...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def generate_primes_with_d_digits(d): star...
from solution import find_prime_chain def test_prime_chain_with_two_digits_and_length_three(): assert find_prime_chain(2, 3) == '11 13 17' def test_prime_chain_with_two_digits_and_length_six(): assert find_prime_chain(2, 6) == '11 13 17 19 23 29' def test_prime_chain_with_three_digits_and_length_ten(): a...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_primes_with_d_digits(d):", "function_name": "generate_primes_with_d_digits", "parameter_list": "(d)"...
[ 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 sieve_of_eratosthenes(max_num):\n \"\"\"\n Generate a list of prime numbers up to max_num (inclusive) using the Sieve of Eratosthenes.\n \"\"\...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00003802", "row_id": 3802, "seed_ids": "[484]" }
0.595418
Code_Contests_3802
I
[ "is_prime", "generate_primes_with_d_digits", "find_prime_chain" ]
3
[ [ "find_prime_chain", "generate_primes_with_d_digits" ], [ "generate_primes_with_d_digits", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2a658453d468b67fec095840c7bed61207adaac3
fdb5d75ab7cd570cdf4e3bf7687111e5766093f5
v1.0
instruct
Code_Contests
Code_Contests_3821_I
You are tasked with organizing a series of events in a museum. There are n events and each event has a specific start time and end time. You need to find out the maximum number of events you can attend if you can only attend one event at a time. Input The first line contains an integer n (1 ≤ n ≤ 1000), the number of...
def max_events(events): """ Returns the maximum number of events one can attend. """ events.sort(key=lambda x: x[1]) # Sort events by their end time count = 0 last_end_time = -1 for start, end in events: if start >= last_end_time: count += 1 last_end_tim...
from solution import max_events def test_example_1(): events = [(1, 3), (2, 5), (4, 6), (6, 8), (9, 10)] assert max_events(events) == 4 def test_example_2(): events = [(1, 2), (2, 3), (3, 4)] assert max_events(events) == 3 def test_single_event(): events = [(1, 2)] assert max_events(events) =...
[ { "docstring": "Returns the maximum number of events one can attend.", "function_declaration": "def max_events(events):", "function_name": "max_events", "parameter_list": "(events)" }, { "docstring": null, "function_declaration": "def solve():", "function_name": "solve", "paramet...
[ 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_events(n, events):\n \"\"\"\n Returns the maximum number of events that can be attended without overlaps.\n \n Parameters:\n n (int)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003821", "row_id": 3821, "seed_ids": "[2953]" }
0.681371
Code_Contests_3821
I
[ "max_events", "solve" ]
2
[ [ "solve", "max_events" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3afa06187dcc5861c9de0d63bce5c494491353ae
566cdc003dc1145665914ec7f96c9b9b1cc2f15c
v1.0
instruct
Code_Contests
Code_Contests_3867_I
Ann has another task which she needs to complete to prepare for her upcoming programming exam. She has to solve different questions related to strings. This time she will deal with two specific types of strings: palindromes and repeating segments. A string is a palindrome if it reads the same backward as forward. For ...
def is_palindrome(s): """ Check if a string s is a palindrome """ return s == s[::-1] def has_repeating_segment(s): """ Check if a string s has a repeating segment """ n = len(s) for i in range(1, n // 2 + 1): if n % i == 0: if s == s[:i] * (n // i): ...
from solution import longest_palindrome_or_repeating_segment def test_example_1(): assert longest_palindrome_or_repeating_segment("racecarbanana") == "racecar" def test_example_2(): assert longest_palindrome_or_repeating_segment("abcabcabc") == "abcabcabc" def test_example_3(): assert longest_palindrome_...
[ { "docstring": "Check if a string s is a palindrome", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Check if a string s has a repeating segment", "function_declaration": "def has_repeating_segment(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 is_palindrome(s):\n return s == s[::-1]\n\ndef has_repeating_segment(s):\n n = len(s)\n for i in range(1, n // 2 + 1):\n if n % i == 0:...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00003867", "row_id": 3867, "seed_ids": "[7442]" }
0.821375
Code_Contests_3867
I
[ "is_palindrome", "has_repeating_segment", "longest_palindrome_or_repeating_segment" ]
3
[ [ "longest_palindrome_or_repeating_segment", "has_repeating_segment" ], [ "longest_palindrome_or_repeating_segment", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
54c516f880c137f448cceac999be228e1ea9861b
c93ea905f39a123670f2ad767cc14118f0b0f6fc
v1.0
instruct
Code_Contests
Code_Contests_3901_I
In a galaxy far away, there is a circular planet known as Planet X which is divided into n sectors numbered from 1 to n. Each sector has a unique resource, and the inhabitants of Planet X have built m pipelines to distribute these resources among the sectors. Each pipeline can only connect two different sectors. The i...
def find_connected_components(n, pipelines): from collections import defaultdict, deque graph = defaultdict(list) for u, v in pipelines: graph[u].append(v) graph[v].append(u) visited = [False] * (n + 1) components = 0 def bfs(node): queue = deque([...
from solution import minimum_pipelines_required def test_example_1(): assert minimum_pipelines_required(5, 3, [(1, 2), (2, 3), (4, 5)]) == "Yes 1" def test_example_2(): assert minimum_pipelines_required(6, 5, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]) == "Yes 0" def test_example_3(): assert minimum_pipeli...
[ { "docstring": null, "function_declaration": "def find_connected_components(n, pipelines):", "function_name": "find_connected_components", "parameter_list": "(n, pipelines)" }, { "docstring": null, "function_declaration": "def minimum_pipelines_required(n, m, pipelines):", "function_...
[ 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_connected_components(n, pipelines):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n \n for u, v in pi...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003901", "row_id": 3901, "seed_ids": "[11781]" }
0.599917
Code_Contests_3901
I
[ "find_connected_components", "minimum_pipelines_required" ]
2
[ [ "minimum_pipelines_required", "find_connected_components" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e2dd16a5f723ff6b696d7208f81b049c678c6de7
940cf4e7c9f7d84233fb9508fe5eac478c63808a
v1.0
instruct
Code_Contests
Code_Contests_3911_I
A teacher needs to allocate seats for students in an exam hall. The seating arrangement must be done in a way that no two students with the same last names sit adjacent to each other in any row. The teacher has provided the list of students and their last names. Your task is to determine if it is possible to allocate ...
from collections import Counter def can_allocate_seats(student_list): """ Determine if it is possible to arrange the seats according to the rules. Args: student_list: List of strings where each string represents a student's "first_last" name. Returns: 'YES' if it is possible to arrang...
from solution import determine_seating_possible def test_single_student(): input_str = "1\njohn_smith" assert determine_seating_possible(input_str) == "YES" def test_all_unique_last_names(): input_str = "4\njohn_smith\nemma_jones\nliam_taylor\nolivia_brown" assert determine_seating_possible(input_str)...
[ { "docstring": "Determine if it is possible to arrange the seats according to the rules.\n\nArgs:\nstudent_list: List of strings where each string represents a student's \"first_last\" name.\n\nReturns:\n'YES' if it is possible to arrange the seating as per the rules, otherwise 'NO'.", "function_declaration...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef can_allocate_seats(student_list):\n \"\"\"\n Determine if it is possible to arrange the seats according to the...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00003911", "row_id": 3911, "seed_ids": "[3420]" }
0.676957
Code_Contests_3911
I
[ "can_allocate_seats", "determine_seating_possible" ]
2
[ [ "determine_seating_possible", "can_allocate_seats" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b784966c2693e9fe990681cefe7716e303475968
69d0e5768678c41b8032ede01af76c130cd3b988
v1.0
instruct
Code_Contests
Code_Contests_3932_I
In a distant kingdom, there are `n` castles connected by `m` bidirectional roads. Each road has a travel cost associated with it. The King decided to renovate the road network and needs to ensure that his knights can travel between any two castles at the minimum possible cost. As the royal engineer, your task is to de...
def find(parent, i): if parent[i] == i: return i 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[yroot] = xroot ...
from solution import minimum_cost_to_connect_castles def test_example1(): n = 4 m = 5 roads = [ (1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (1, 4, 5) ] assert minimum_cost_to_connect_castles(n, m, roads) == 6 def test_example2(): n = 3 m = 1 road...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003932", "row_id": 3932, "seed_ids": "[7128]" }
0.690948
Code_Contests_3932
I
[ "find", "union", "minimum_cost_to_connect_castles" ]
3
[ [ "minimum_cost_to_connect_castles", "find" ], [ "minimum_cost_to_connect_castles", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
596dd63c2923e3ec3e22092259c01df771108bc8
faca3b2be8001cfe6b7bcdaab552b1176c42795d
v1.0
instruct
Code_Contests
Code_Contests_3933_I
Hermione is at it again, preparing for her Arithmancy exams, and she has come across a challenging new problem related to prime numbers. She has asked you to write a program that will help her solve it. As a Muggle-born, you know this is a chance to impress her with your coding skills. The problem is as follows: Give...
def sieve_of_eratosthenes(max_value): is_prime = [True] * (max_value + 1) is_prime[0] = is_prime[1] = False p = 2 while p * p <= max_value: if is_prime[p]: for i in range(p * p, max_value + 1, p): is_prime[i] = False p += 1 prime_count = [0] * (m...
from solution import solve_number_of_primes def test_single_case(): assert solve_number_of_primes([10]) == [4] assert solve_number_of_primes([5]) == [3] def test_multiple_cases(): assert solve_number_of_primes([10, 5]) == [4, 3] assert solve_number_of_primes([100, 500, 1000]) == [25, 95, 168] def tes...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_value):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_value)" }, { "docstring": null, "function_declaration": "def count_primes_up_to(max_value):", "function_name": "count_primes_up_to",...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_n):\n \"\"\"\n Returns an array prime_count where prime_count[i] is the number of primes <= i.\n \"\"\"\n is_prim...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003933", "row_id": 3933, "seed_ids": "[174]" }
0.626559
Code_Contests_3933
I
[ "sieve_of_eratosthenes", "count_primes_up_to", "solve_number_of_primes" ]
3
[ [ "count_primes_up_to", "sieve_of_eratosthenes" ], [ "solve_number_of_primes", "count_primes_up_to" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e56380f0a91bbc02d4d24b7078820847a850a5cb
5baf09e4cd1dd633fcb572905ff30204de987681
v1.0
instruct
Code_Contests
Code_Contests_3951_I
Sarah is a software engineer who participates in a coding contest every month. In each contest, she can solve a variable number of problems. By solving these problems, Sarah accumulates points that correspond to the difficulty level of each problem. The contest organizers have a unique scoring system where points for e...
def fibonacci(n): """ Returns the nth Fibonacci number. """ a, b = 0, 1 for _ in range(n): a, b = b, a + b return a def total_score(n, problems): """ Returns the total score accumulated based on the solved problems' Fibonacci indices. """ total = 0 for p in problems:...
from solution import fibonacci, total_score def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(6) == 8 assert fibonacci(7) == 13 assert fibonacci...
[ { "docstring": "Returns the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Returns the total score accumulated based on the solved problems' Fibonacci indices.", "function_declaration": "def to...
[ 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 fibonacci(n):\n # Function to return nth Fibonacci number\n if n == 0:\n return 0\n elif n == 1:\n return 1\n a, b = 0, 1\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00003951", "row_id": 3951, "seed_ids": "[9614]" }
0.669577
Code_Contests_3951
I
[ "fibonacci", "total_score" ]
2
[ [ "total_score", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f16c4d8a5b439363aace292ba6511613a73b890
ba393c224f70fa5a262fb0636d356c3de72eddc1
v1.0
instruct
Code_Contests
Code_Contests_3987_I
Dr. Strange is a mathematician and recently he found a mysterious sequence which he calls a "Magic Progression". A Magic Progression is an arithmetic progression (AP) where the sum of all its terms is a prime number. Being a mathematician, Dr. Strange wants to perform operations on this progression. He will provide you...
def is_prime(num): """ Check if a given number is a prime number. """ 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...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(30) == False def test_sum_of_ap(): assert sum_of_ap(1, 1, 3) == 6 assert sum_of_ap(3, 5, 2) == 11 assert sum_of_ap(2, 3, 4) == 26 assert...
[ { "docstring": "Check if a given number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Calculate the sum of an arithmetic progression.", "function_declaration": "def sum_of_ap(a, d, n):", "f...
[ 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 math\n\ndef is_prime(num):\n \"\"\"Helper function to check if a given number is prime.\"\"\"\n if num <= 1:\n return False\n if num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00003987", "row_id": 3987, "seed_ids": "[2819]" }
0.543085
Code_Contests_3987
I
[ "is_prime", "sum_of_ap", "is_magic_progression", "check_magic_progressions" ]
4
[ [ "check_magic_progressions", "is_magic_progression" ], [ "is_magic_progression", "is_prime" ], [ "is_magic_progression", "sum_of_ap" ] ]
3
[]
false
[]
false
pytest
false
[]
true
277a18ec2fa69100ef96c2efbd7b22b603ad24a0
de1f34c5ca411a940f98523987e809468e974180
v1.0
instruct
Code_Contests
Code_Contests_4010_I
Create a program that, given a string of alphabets, checks if it can be transformed into a palindrome by rearranging its characters. A palindrome is a word, phrase, number, or other sequences of characters that reads the same forwards and backwards. You can ignore spaces, punctuation, and letter casing while determinin...
import re from collections import Counter def can_form_palindrome(s): """ Returns "YES" if the characters in the string s can be rearranged to form a palindrome, otherwise "NO". """ # Remove non-alphabetic characters and convert to lower case cleaned_str = re.sub(r'[^a-zA-Z]', '', s).lower() ...
from solution import can_form_palindrome, check_palindrome_formation def test_is_palindrome_rearrangeable(): assert can_form_palindrome('A Santa at Nasa') == 'YES' assert can_form_palindrome("Madam In Eden, I'm Adam") == 'YES' assert can_form_palindrome('A man, a plan, a canal, Panama!') == 'YES' asser...
[ { "docstring": "Returns \"YES\" if the characters in the string s can be rearranged to form a palindrome, otherwise \"NO\".", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declarati...
[ 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 can_form_palindrome(s):\n \"\"\"\n Given a string s, check if it can be rearranged to form a palindrome.\n Ignores spaces, punctuation, and is...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004010", "row_id": 4010, "seed_ids": "[13103]" }
0.787281
Code_Contests_4010
I
[ "can_form_palindrome", "check_palindrome_formation" ]
2
[ [ "check_palindrome_formation", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
194fe7e61d2a793d8e691f3589c7f8e5a5e5dcca
4a85111c41a1194c2c56700c58418d9c98a84e1c
v1.0
instruct
Code_Contests
Code_Contests_4027_I
You are given an integer n (1 ≤ n ≤ 1000). Find all pairs of positive integers (a, b) such that: - a is a divisor of n. - b is a divisor of n. - a * b = n. For each test case, output all pairs (a, b) in non-decreasing order of a. If there are no such pairs, output "NO" (without quotes). Input The first line contain...
def find_divisor_pairs(n): """ Given an integer n, finds all pairs of positive integers (a, b) such that: - a is a divisor of n. - b is a divisor of n. - a * b = n. Returns a list of tuples containing the pairs (a, b) in non-decreasing order of a. If no such pairs exist, returns an empty lis...
from solution import find_divisor_pairs, find_pairs_for_all_cases def test_find_divisor_pairs(): assert find_divisor_pairs(6) == [(1, 6), (2, 3)] assert find_divisor_pairs(12) == [(1, 12), (2, 6), (3, 4)] assert find_divisor_pairs(19) == [(1, 19)] # since 19 is a prime number assert find_divisor_pairs(...
[ { "docstring": "Given an integer n, finds all pairs of positive integers (a, b) such that:\n- a is a divisor of n.\n- b is a divisor of n.\n- a * b = n.\nReturns a list of tuples containing the pairs (a, b) in non-decreasing order of a.\nIf no such pairs exist, returns an empty list.", "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 find_pairs(t, test_cases):\n results = []\n for n in test_cases:\n pairs = []\n for a in range(1, n + 1):\n if n % a == ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004027", "row_id": 4027, "seed_ids": "[2004]" }
0.699556
Code_Contests_4027
I
[ "find_divisor_pairs", "find_pairs_for_all_cases" ]
2
[ [ "find_pairs_for_all_cases", "find_divisor_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
65bf2d3b237db73706d98adf82d409de727ec0fe
1ffd3198bae53e4b3ff44bc23c1f1826ffba11ff
v1.0
instruct
Code_Contests
Code_Contests_4029_I
You are given a collection of numbers, and you need to determine the size of the largest subset in which the greatest common divisor (GCD) of all the numbers is greater than 1. Input The first line contains an integer T - the number of test cases. The first line of each test case contains an integer n - the number of ...
import math from collections import defaultdict from functools import reduce from typing import List def gcd(a, b): """ Returns the greatest common divisor of a and b. """ while b: a, b = b, a % b return a def find_factors(n): """ Finds all prime factors of the given number n. ...
from solution import largest_subset_with_gcd_greater_than_one, process_test_cases import pytest def test_gcd_single_element(): assert largest_subset_with_gcd_greater_than_one([1]) == 0 assert largest_subset_with_gcd_greater_than_one([6]) == 0 def test_gcd_no_gcd_greater_than_one(): assert largest_subset_w...
[ { "docstring": "Returns the greatest common divisor of a and b.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Finds all prime factors of the given number n.", "function_declaration": "def find_factors(n):", "function...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom collections import defaultdict\n\ndef largest_subset_with_gcd_greater_than_one(test_cases):\n def calculate_gcd(a, b):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004029", "row_id": 4029, "seed_ids": "[1114]" }
0.672249
Code_Contests_4029
I
[ "gcd", "find_factors", "largest_subset_with_gcd_greater_than_one", "process_test_cases" ]
4
[ [ "largest_subset_with_gcd_greater_than_one", "find_factors" ], [ "process_test_cases", "largest_subset_with_gcd_greater_than_one" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
a10f96ac87a31fafbd48bfbdd97385fdc6935518
d588db0b072beeca74b7b5f38cae566401a45a81
v1.0
instruct
Code_Contests
Code_Contests_4041_I
**C - Optimal Energy Consumption** Problem Statement You are managing a factory that operates across multiple machines, and energy consumption is a critical factor. Each machine operates based on certain schedules and consumes energy at different rates throughout the day. Your goal is to optimize the energy consumpti...
def is_optimizable(N, E, schedules): """ Determine if it's possible to rearrange the schedules such that the energy consumption never exceeds E at any given time slot. Parameters: N (int): Number of machines E (int): Maximum allowable energy consumption at any time schedules (list): Li...
def test_optimal_energy_consumption(): input1 = "3 150\n3\n1 50\n2 50\n3 50\n2\n1 50\n2 70\n4\n1 30\n2 30\n3 30\n4 30" input2 = "2 100\n2\n1 60\n2 60\n2\n2 50\n3 50" assert optimal_energy_consumption(input1) == "Optimizable" assert optimal_energy_consumption(input2) == "Not Optimizable" def test_n...
[ { "docstring": "Determine if it's possible to rearrange the schedules such that the energy \nconsumption never exceeds E at any given time slot.\n\nParameters:\nN (int): Number of machines\nE (int): Maximum allowable energy consumption at any time\nschedules (list): List of machines' schedules, where each sched...
[ 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_optimizable(N, E, schedules):\n # Create a list to store the total energy consumption for each time slot\n energy_consumption = [0] * 25 # Ti...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004041", "row_id": 4041, "seed_ids": "[8741]" }
0.734422
Code_Contests_4041
I
[ "is_optimizable", "optimal_energy_consumption" ]
2
[ [ "optimal_energy_consumption", "is_optimizable" ] ]
1
[]
false
[]
false
pytest
false
[]
true
38f099a44c7a43e549d5d57dd54b7b623f4c629b
0ce1250f7cee7f60793ad8ad38ed9d42eb3c0432
v1.0
instruct
Code_Contests
Code_Contests_4048_I
N is a positive integer indicating the number of days Alice wants to save fruits for, inclusive of the first day. Each day, starting from the first day, a certain number of fruits will be added to her stockpile. Her goal is to eat the maximum number of fruits each day, so that her stockpile is never reduced to zero b...
def max_fruits_per_day(N, fruits): low, high = 0, max(fruits) result = 0 while low <= high: mid = (low + high) // 2 if can_consume(mid, N, fruits): result = mid low = mid + 1 else: high = mid - 1 return result def can_consume(k, N, fruits...
from solution import max_fruits_per_day def test_example_1(): assert max_fruits_per_day(5, [7, 3, 4, 6, 2]) == 4 def test_example_2(): assert max_fruits_per_day(3, [5, 2, 10]) == 3 def test_example_3(): assert max_fruits_per_day(4, [6, 6, 6, 6]) == 6 def test_single_day(): assert max_fruits_per_day(...
[ { "docstring": null, "function_declaration": "def max_fruits_per_day(N, fruits):", "function_name": "max_fruits_per_day", "parameter_list": "(N, fruits)" }, { "docstring": null, "function_declaration": "def can_consume(k, N, fruits):", "function_name": "can_consume", "parameter_l...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_fruits_per_day(N, fruits):\n low, high = 0, max(fruits)\n result = 0\n \n while low <= high:\n mid = (low + high) // 2\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004048", "row_id": 4048, "seed_ids": "[11243]" }
0.727289
Code_Contests_4048
I
[ "max_fruits_per_day", "can_consume" ]
2
[ [ "max_fruits_per_day", "can_consume" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c039fdeb3bbff8258f46341fd1c0643f04fb9168
b56d300752fed4e32eae56bbaf03866149aa77de
v1.0
instruct
Code_Contests
Code_Contests_4053_I
A robotics company is building a factory automation system that involves a network of conveyor belts. Each conveyor belt connects two machines and has a specific duration for which it can transport materials from one machine to another. The company needs to determine the optimal time to complete certain tasks from an i...
import heapq def find_minimum_duration(T, test_cases): results = [] for case in test_cases: N, M = case['N'], case['M'] edges = case['edges'] S, F = case['S'], case['F'] # Create adjacency list graph = [[] for _ in range(N + 1)] for x, y, d in edges...
def test_find_minimum_duration(): input_data = """1 4 5 1 2 4 1 3 2 2 3 1 2 4 5 3 4 3 1 4""" expected_output = "5" assert solve(input_data) == expected_output def test_find_minimum_duration_impossible(): input_data = """1 4 1 1 2 5 3 4""" expected_output = "IMPOSSIBLE" assert solve(input_data) ...
[ { "docstring": null, "function_declaration": "def find_minimum_duration(T, test_cases):", "function_name": "find_minimum_duration", "parameter_list": "(T, test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_optimal_duration(T, test_cases):\n def dijkstra(n, graph, start, end):\n queue = [(0, start)]\n dist = {i: float(...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004053", "row_id": 4053, "seed_ids": "[1638]" }
0.770401
Code_Contests_4053
I
[ "find_minimum_duration", "process_input", "solve" ]
3
[ [ "solve", "find_minimum_duration" ], [ "solve", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
55311baeb8057d48f0d673de685bcd07375ed24a
0253dd4e1babb3199287c8bff219e214bef30a7a
v1.0
instruct
Code_Contests
Code_Contests_4061_I
Martin is playing a game on his computer in which he builds connected networks of towns. Each town is represented by a node, and each connection between two towns is represented by an edge. Initially, no towns are connected, and Martin can select from a given list of possible connections (edges). He wants to form a net...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[root_y] = root_x elif r...
from solution import minimum_cost_to_connect_towns def test_example_1(): n = 4 m = 5 connections = [ (1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (2, 4, 5) ] assert minimum_cost_to_connect_towns(n, m, connections) == 6 def test_example_2(): n = 3 m = ...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004061", "row_id": 4061, "seed_ids": "[2444]" }
0.751605
Code_Contests_4061
I
[ "find", "union", "minimum_cost_to_connect_towns" ]
3
[ [ "minimum_cost_to_connect_towns", "find" ], [ "minimum_cost_to_connect_towns", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f7f98c6a46c69662f19ffb4aba3cff2edd4b2b5e
a430bbfe809772da2275b320121d4f9123a05c8f
v1.0
instruct
Code_Contests
Code_Contests_4100_I
Rescue the Robot In a distant future, there are automated robots designed to explore and gather data from various terrains. Unfortunately, one of the robots has malfunctioned during its mission on a gridded terrain. Your task is to design a program that can help this robot reach the target location and then return to ...
def parse_grid(): import sys input = sys.stdin.read data = input().splitlines() index = 0 results = [] while True: width, height = map(int, data[index].split()) if width == 0 and height == 0: break grid = [] for i in range(1, height + 1): ...
def test_rescue_robot(): import sys from io import StringIO # Original stdin original_stdin = sys.stdin # Sample input input_data = """\ 5 3 ##### #S.T# ##### 5 3 ##### #S#T# ##### 0 0 """ sys.stdin = StringIO(input_data) # Sample output expected_output = [ "T...
[ { "docstring": null, "function_declaration": "def parse_grid():", "function_name": "parse_grid", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def find_position(grid, char):", "function_name": "find_position", "parameter_list": "(grid, char)" }, { ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_within_bounds(x, y, width, height):\n return 0 <= x < width and 0 <= y < height\n\ndef bfs(grid, start, target):...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004100", "row_id": 4100, "seed_ids": "[2909]" }
0.645155
Code_Contests_4100
I
[ "parse_grid", "find_position", "valid_moves", "bfs", "rescue_robot" ]
5
[ [ "bfs", "valid_moves" ], [ "rescue_robot", "bfs" ], [ "rescue_robot", "find_position" ], [ "rescue_robot", "parse_grid" ] ]
4
[]
false
[]
false
pytest
false
[]
true
c74d6e2500597c4351365d1413bebdd749744c61
a107c74d0cf79d9c1d229f41d854f2b15ad64f92
v1.0
instruct
Code_Contests
Code_Contests_4104_I
A company is designing a secure login system. Each user can have multiple login attempts, each with a different password. A password is considered strong if it satisfies the following criteria: 1. It has at least 8 characters. 2. It contains at least one lowercase letter. 3. It contains at least one uppercase letter. ...
import re def is_strong_password(password): 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.search(r'\d', password): return False if not re.search(r'[!@#$%^&*()\-+]', p...
import pytest from solution import is_strong_password, count_strong_weak_passwords def test_is_strong_password_with_strong_passwords(): assert is_strong_password("Password123!") == True assert is_strong_password("Stronger@1") == True assert is_strong_password("Secure#Password1") == True def test_is_strong...
[ { "docstring": null, "function_declaration": "def is_strong_password(password):", "function_name": "is_strong_password", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def count_strong_weak_passwords(n, passwords):", "function_name": "count_strong_wea...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_strong_and_weak_passwords(n, passwords):\n def is_strong_password(password):\n if len(password) < 8:\n return False\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00004104", "row_id": 4104, "seed_ids": "[3559]" }
0.576094
Code_Contests_4104
I
[ "is_strong_password", "count_strong_weak_passwords" ]
2
[ [ "count_strong_weak_passwords", "is_strong_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f5cb4478f5f6a75b0bc7bf32dcf353a3b96d30ad
3ef93a1c5b566a51883331ee70b99f7809ba0ee1
v1.0
instruct
Code_Contests
Code_Contests_4111_I
A software company is launching a new loyalty points system. Each time a customer makes a purchase, they receive a number of points based on their total purchase amount. However, there are specific rules governing how points are accumulated depending on whether the total purchase amount can be represented as the produc...
def is_product_of_two_integers_greater_than_one(n): """ Determines if the number n can be represented as the product of two integers greater than 1. """ if n < 4: # The smallest product of integers > 1 is 2 * 2 = 4 return False for i in range(2, int(n**0.5) + 1): if n % i == 0 and n...
from solution import calculate_loyalty_points, is_product_of_two_integers_greater_than_one def test_is_product_of_two_integers_greater_than_one(): assert is_product_of_two_integers_greater_than_one(10) == True assert is_product_of_two_integers_greater_than_one(7) == False assert is_product_of_two_integers_...
[ { "docstring": "Determines if the number n can be represented as the product of two integers greater than 1.", "function_declaration": "def is_product_of_two_integers_greater_than_one(n):", "function_name": "is_product_of_two_integers_greater_than_one", "parameter_list": "(n)" }, { "docstrin...
[ 0, 0, 0, 0, 0, 1, 1, 0, 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 can_be_product_of_two_integers_greater_than_one(n):\n \"\"\"\n Check if a number n can be expressed as the product of two integers greater than 1...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004111", "row_id": 4111, "seed_ids": "[10369]" }
0.698463
Code_Contests_4111
I
[ "is_product_of_two_integers_greater_than_one", "calculate_loyalty_points" ]
2
[ [ "calculate_loyalty_points", "is_product_of_two_integers_greater_than_one" ] ]
1
[]
false
[]
false
pytest
true
[]
true
35c9b77b81d4e822bbfc2b9a8248a825ed9fa677
cd69e8d376cb46e5b217d368eff1b35a7635b148
v1.0
instruct
Code_Contests
Code_Contests_4133_I
A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward. When working with numbers, a palindromic number is a number that remains the same when its digits are reversed. We define a base-10 integer as a Strobogrammatic number if the number remains the same when ro...
def is_strobogrammatic(num): """ Checks whether a number is strobogrammatic. """ strobo_map = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'} str_num = str(num) rotated_str = ''.join(strobo_map.get(ch, '') for ch in reversed(str_num)) return str_num == rotated_str def next_strobogrammati...
from solution import is_strobogrammatic, next_strobogrammatic_number def test_is_strobogrammatic(): assert is_strobogrammatic(69) == True assert is_strobogrammatic(96) == True assert is_strobogrammatic(818) == True assert is_strobogrammatic(9966) == True assert is_strobogrammatic(10) == False a...
[ { "docstring": "Checks whether a number is strobogrammatic.", "function_declaration": "def is_strobogrammatic(num):", "function_name": "is_strobogrammatic", "parameter_list": "(num)" }, { "docstring": "Returns the next strobogrammatic number greater than n.", "function_declaration": "def...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_strobogrammatic(num):\n \"\"\"\n Checks whether a number is strobogrammatic.\n \"\"\"\n strobo_map = {'0': '0', '1': '1', '6': '9', '8':...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004133", "row_id": 4133, "seed_ids": "[7901]" }
0.689868
Code_Contests_4133
I
[ "is_strobogrammatic", "next_strobogrammatic_number" ]
2
[ [ "next_strobogrammatic_number", "is_strobogrammatic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f5df778a93e29b2443e6f4b5caf020bc207bf1b6
aecaf9fad25dbd96fda7136ef00dc7387de8843c
v1.0
instruct
Code_Contests
Code_Contests_4164_I
Write a function that takes an integer `n` between 5 and 30 inclusive, and returns a list of the first `n` prime numbers in ascending order. Prime numbers are integers greater than 1 that have no divisors other than 1 and themselves. Constraints * 5 \leq n \leq 30 Input The input is provided from Standard Input in ...
def is_prime(num): """Returns True if num is a prime number, otherwise False.""" 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 pr...
from solution import prime_numbers def test_prime_numbers_5(): assert prime_numbers(5) == [2, 3, 5, 7, 11] def test_prime_numbers_10(): assert prime_numbers(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_prime_numbers_15(): assert prime_numbers(15) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41...
[ { "docstring": "Returns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of the first `n` prime numbers in ascending order.", "function_declaration": "d...
[ 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 \"\"\"Returns True if num is a prime number, otherwise False.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004164", "row_id": 4164, "seed_ids": "[3829]" }
0.754446
Code_Contests_4164
I
[ "is_prime", "prime_numbers" ]
2
[ [ "prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd2595ebb5d76c1a92a46e7fb6b01d5ae86e547c
3ab21487ba36171fa0f6709d98de91d9c06d26d9
v1.0
instruct
Code_Contests
Code_Contests_4232_I
In a certain village, there is a festival where a peculiar game is played. The game involves a tree with `n` vertices, where each vertex represents a house. Villagers use the vertices to encode news passing. The news starts at a root house (vertex 1) and spreads to other houses as per certain rules dictated by integers...
import heapq import sys from collections import defaultdict def time_to_reach_all_houses(n, edges): graph = defaultdict(list) for a, b, t in edges: graph[a].append((b, t)) graph[b].append((a, t)) dist = {i: sys.maxsize for i in range(1, n + 1)} dist[1] = 0 heap = [(0,...
from solution import time_to_reach_all_houses def test_example1(): n = 5 edges = [ (1, 2, 1), (1, 3, 2), (2, 4, 4), (3, 5, 3) ] assert time_to_reach_all_houses(n, edges) == ([0, 1, 2, 5, 5], [4, 5]) def test_example2(): n = 4 edges = [ (1, 2, 1), ...
[ { "docstring": null, "function_declaration": "def time_to_reach_all_houses(n, edges):", "function_name": "time_to_reach_all_houses", "parameter_list": "(n, edges)" }, { "docstring": null, "function_declaration": "def solution(n, edge_list):", "function_name": "solution", "paramet...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef time_to_reach_all_houses(n, edges):\n graph = defaultdict(list)\n \n for a, b...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004232", "row_id": 4232, "seed_ids": "[891]" }
0.598945
Code_Contests_4232
I
[ "time_to_reach_all_houses", "solution" ]
2
[ [ "solution", "time_to_reach_all_houses" ] ]
1
[]
false
[]
false
pytest
true
[]
true
423eec0360a9cf2944549fa54ec754b6a700d1c2
726a1a6e32379e09b074dd9d565709bf35c6f840
v1.0
instruct
Code_Contests
Code_Contests_4255_I
In the magical world, a wizard needs to create a special potion that requires exactly m liters of a particular ingredient, which is available in bottles of various capacities. The wizard can use each bottle an infinite number of times. Given the capacities of the bottles and the total amount of potion required, determi...
def min_bottles(n, m, bottles): dp = [float('inf')] * (m + 1) dp[0] = 0 # No bottles needed to measure 0 liters for bottle in bottles: for j in range(bottle, m + 1): dp[j] = min(dp[j], dp[j - bottle] + 1) return dp[m] if dp[m] != float('inf') else -1 def potion_measurement(n, m, ...
def test_min_bottles_example_1(): assert potion_measurement(3, 11, [1, 3, 5]) == 3 def test_min_bottles_example_2(): assert potion_measurement(2, 7, [2, 6]) == -1 def test_min_bottles_single_bottle_exact(): assert potion_measurement(1, 7, [7]) == 1 def test_min_bottles_multiple_ways(): assert potion_...
[ { "docstring": null, "function_declaration": "def min_bottles(n, m, bottles):", "function_name": "min_bottles", "parameter_list": "(n, m, bottles)" }, { "docstring": null, "function_declaration": "def potion_measurement(n, m, bottles):", "function_name": "potion_measurement", "pa...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_bottles_to_measure(n, m, capacities):\n \"\"\"\n Function to determine the minimum number of bottles needed to measure exactly m liters using...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004255", "row_id": 4255, "seed_ids": "[3708]" }
0.681161
Code_Contests_4255
I
[ "min_bottles", "potion_measurement" ]
2
[ [ "potion_measurement", "min_bottles" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6d300a43d067e9818aeb601ffb2bae937f2110e5
556381726834c4516e596d85c4e31b3c7ae5c2d3
v1.0
instruct
Code_Contests
Code_Contests_4334_I
Palindrome Maze Story In the mysterious land of Palindor, there's a maze designed with a peculiar set of rules. The maze is comprised of cells, each containing a character that can be an alphabet letter. The maze-keeper, Palax, loves palindromes and has designed the maze such that one can only move from cell to cell ...
def is_palindrome(s): return s == s[::-1] def dfs(maze, x, y, path, visited, x_end, y_end): if (x, y) == (x_end, y_end): if is_palindrome(path): return True return False visited.add((x, y)) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] for dx, dy in direction...
import pytest from solution import can_reach_palindrome def test_sample_input_1(): maze = [ 'ababa', 'bcccb', 'dadad', 'bcccb', 'ababa' ] assert can_reach_palindrome(maze, 0, 0, 4, 4) == "Yes" def test_sample_input_2(): maze = [ 'abcd', 'bcdb', ...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def dfs(maze, x, y, path, visited, x_end, y_end):", "function_name": "dfs", "parameter_list": "(maze, x...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef dfs(maze, x, y, path, visited, x_end, y_end):\n if (x, y) == (x_end, y_end):\n if is_palind...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004334", "row_id": 4334, "seed_ids": "[10200]" }
0.707983
Code_Contests_4334
I
[ "is_palindrome", "dfs", "can_reach_palindrome" ]
3
[ [ "can_reach_palindrome", "dfs" ], [ "dfs", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
499e756db8c6c240d5b7b3dba41c71506d6fa904
ac390a19b4322ddf784358e801ae52b078b86dc0
v1.0
instruct
Code_Contests
Code_Contests_4408_I
Your task is to write a function that, given a list of integers, returns a new list containing only the integers that are prime numbers. ### Function Signature ```python def filter_primes(numbers: List[int]) -> List[int]: ``` ### Input - `numbers`: A list of integers. `2 <= len(numbers) <= 100` and `-10^6 <= number...
from typing import List def is_prime(n: int) -> bool: """ Helper function to determine if a given number n is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n**0.5) + 1 for d in range(3, max_divisor, 2): ...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, -7, 10, 13, 17, 23, 9, 11]) == [2, 3, 5, 13, 17, 23, 11] def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,...
[ { "docstring": "Helper function to determine if a given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, return a new list containing only the prime numbers.", "function_decl...
[ 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 typing import List\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004408", "row_id": 4408, "seed_ids": "[4678]" }
0.669526
Code_Contests_4408
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb782b029124c7e7298e55be948a2735ea8faed2
cff4708b8db38318ddcfea10525c281fba5de4d3
v1.0
instruct
Code_Contests
Code_Contests_4411_I
You are given a directed graph with n vertices and m edges. Each vertex represents a room at a party, and each edge represents a one-way passage between two rooms. A unique caterer is stationed in one of these rooms initially. The caterer has to deliver food to each room exactly once before returning to the initial roo...
from itertools import permutations def is_hamiltonian_cycle(graph, start, n): for perm in permutations(range(1, n + 1)): if perm[0] == start: cycle = perm + (start,) is_valid = True for i in range(n): if graph[cycle[i]][cycle[i + 1]] == 0: ...
import pytest from solution import caterer_route def test_case_1(): n = 4 m = 5 edges = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)] s = 1 result = caterer_route(n, m, edges, s) assert result == "Possible\n1 2 3 4 1" def test_case_2(): n = 4 m = 3 edges = [(1, 2), (2, 3), (3, 4)] s...
[ { "docstring": null, "function_declaration": "def is_hamiltonian_cycle(graph, start, n):", "function_name": "is_hamiltonian_cycle", "parameter_list": "(graph, start, n)" }, { "docstring": null, "function_declaration": "def solve(n, m, edges, s):", "function_name": "solve", "param...
[ 0, 0, 0, 1 ]
1
hard
0.25
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef check_hamiltonian_cycle(n, m, edges, s):\n # Create adjacency matrix\n adj = [[0] ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00004411", "row_id": 4411, "seed_ids": "[5690]" }
0.6375
Code_Contests_4411
I
[ "is_hamiltonian_cycle", "solve", "caterer_route" ]
3
[ [ "caterer_route", "solve" ], [ "solve", "is_hamiltonian_cycle" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c24358a8c920aa63e381f11042d269f458051b8b
9d2c658ef0591f32e80088c4208ac3b7107e8658
v1.0
instruct
Code_Contests
Code_Contests_4419_I
A university has n students, each with a unique ID number from 1 to n. The university cafeteria offers m different types of dishes, numbered from 1 to m. Each student has a list of their preferred dishes. Your task is to determine the minimum number of different dish types needed so that each student gets at least one ...
from itertools import combinations def min_dishes_required(n, m, student_preferences): # Construct the list containing sets of preferences for each student student_sets = [] for pref in student_preferences: student_sets.append(set(pref[1:])) # Generate all possible combinations of dishes a...
def test_min_dishes_required_example(): assert solve(4, 5, [ [3, 1, 2, 3], [2, 2, 4], [2, 3, 5], [1, 4] ]) == 2 def test_min_dishes_required_single_student(): assert solve(1, 3, [ [2, 1, 2] ]) == 1 def test_min_dishes_required_all_dishes_needed(): assert...
[ { "docstring": null, "function_declaration": "def min_dishes_required(n, m, student_preferences):", "function_name": "min_dishes_required", "parameter_list": "(n, m, student_preferences)" }, { "docstring": null, "function_declaration": "def solve(n, m, preferences):", "function_name"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef min_dish_types(n, m, preferences):\n all_dishes = set(range(1, m + 1))\n for k in range(1, m + 1):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004419", "row_id": 4419, "seed_ids": "[6987]" }
0.764551
Code_Contests_4419
I
[ "min_dishes_required", "solve" ]
2
[ [ "solve", "min_dishes_required" ] ]
1
[]
false
[]
false
pytest
false
[]
true
70fd1be2e572a63a56813c8d94d6e2e31a427055
a58067c1901dc1315270504fb3af124a6e34b491
v1.0
instruct
Code_Contests
Code_Contests_4425_I
Sara is fascinated by prime numbers. She defines a "prime sum" of a number as the sum of its prime factors where each prime factor is counted only once, regardless of its multiplicity. For example, the prime sum of 12 is 5 since the prime factors of 12 are 2 and 3, and 2 + 3 = 5. Sara also defines a "prime sum chain" ...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for i in range(3, max_divisor, 2): if n % i == 0: return False return True def prime_factors(n): factors = set() while ...
from solution import is_prime, prime_factors, prime_sum, prime_sum_chain 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(9) == False def test_prime_factors(): assert prime_factors(12) == {2, 3} ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def prime_factors(n):", "function_name": "prime_factors", "parameter_list": "(n)" }, { "docstring": null,...
[ 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 if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n max_divisor = in...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004425", "row_id": 4425, "seed_ids": "[8563]" }
0.66073
Code_Contests_4425
I
[ "is_prime", "prime_factors", "prime_sum", "prime_sum_chain" ]
4
[ [ "prime_sum", "prime_factors" ], [ "prime_sum_chain", "is_prime" ], [ "prime_sum_chain", "prime_sum" ] ]
3
[]
false
[]
false
pytest
true
[]
true
f8c2fa9a14c98939e43c9ca1932c9712d29c8bc2
21d37bcd09a14253d153cbb0be40ca506cc51fca
v1.0
instruct
Code_Contests
Code_Contests_4429_I
Polycarp is a big fan of unique and interesting numbers. He calls a number interesting if it contains all the digits from 0 to 9 exactly once (you cannot skip or repeat any digit from 0 to 9). Given an integer n, Polycarp wants to know the smallest interesting number that is greater than or equal to n. Input The firs...
def is_interesting(number): """ Checks if the number is interesting, which means it contains each digit from 0 to 9 exactly once. """ number_str = str(number) return len(number_str) == 10 and set(number_str) == set('0123456789') def next_interesting_number(n): """ Returns the smallest inter...
from solution import next_interesting_number, is_interesting def test_is_interesting(): assert is_interesting(1234567890) == True assert is_interesting(1023456789) == True assert is_interesting(9876543210) == True assert is_interesting(123456789) == False # Less than 10 digits assert is_interestin...
[ { "docstring": "Checks if the number is interesting, which means it contains each digit from 0 to 9 exactly once.", "function_declaration": "def is_interesting(number):", "function_name": "is_interesting", "parameter_list": "(number)" }, { "docstring": "Returns the smallest interesting numbe...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_interesting(number):\n \"\"\"\n Checks if the given number is an interesting number.\n An interesting number contains all digits from 0 to ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004429", "row_id": 4429, "seed_ids": "[12353]" }
0.59224
Code_Contests_4429
I
[ "is_interesting", "next_interesting_number" ]
2
[ [ "next_interesting_number", "is_interesting" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b64d82a3f5d7c1d77e04f345318c5398a48dc0bf
e0e15b3d816381a6ea08481575c7979ba35da20c
v1.0
instruct
Code_Contests
Code_Contests_4442_I
In a bustling city, street intersections are represented on a grid of `m` rows and `n` columns. Each intersection can be represented as a cell in an `m x n` grid. Cars are allowed to travel either north, south, east, or west, but they cannot move diagonally. There are no traffic lights, so cars can only turn at an inte...
def dfs(grid, m, n, i, j, visited): if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] == 1 or visited[i][j]: return False if i == m - 1 and j == n - 1: return True visited[i][j] = True if dfs(grid, m, n, i + 1, j, visited): # down return True if dfs(grid, m, n, i...
from solution import process_input def test_case_1(): input_data = "3 3\n0 0 0\n1 1 0\n0 0 0\n" assert process_input(input_data) == ["YES"] def test_case_2(): input_data = "4 4\n0 1 0 0\n0 1 1 0\n0 0 0 0\n0 1 0 0\n" assert process_input(input_data) == ["YES"] def test_case_3(): input_data = "3...
[ { "docstring": null, "function_declaration": "def dfs(grid, m, n, i, j, visited):", "function_name": "dfs", "parameter_list": "(grid, m, n, i, j, visited)" }, { "docstring": null, "function_declaration": "def is_path_possible(m, n, grid):", "function_name": "is_path_possible", "p...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs(grid, m, n, i, j, visited):\n if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] == 1 or visited[i][j]:\n return False\n if i == m - ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004442", "row_id": 4442, "seed_ids": "[13208]" }
0.673778
Code_Contests_4442
I
[ "dfs", "is_path_possible", "process_input" ]
3
[ [ "is_path_possible", "dfs" ], [ "process_input", "is_path_possible" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
b8e6123439a30c5d658216d68ea0ff1fe3260271
a451a4eae443dd928cab14b43d5701eb0850e1e2
v1.0
instruct
Code_Contests
Code_Contests_4462_I
Problem Description: If you know what is a Prime Number and Sieve of Eratosthenes you can skip to problem statement. What is a Prime Number? A prime number is a natural number greater than 1 that is not formed by multiplying two smaller natural numbers. In other words, a prime number is one which has exactly two dist...
def sieve_of_eratosthenes(limit): """ Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False p = 2 while p * p <= limit: if is_prime[p]: for i in range(p * p,...
from solution import sieve_of_eratosthenes, count_primes_up_to_n, count_primes def test_sieve_of_eratosthenes_base_cases(): primes = sieve_of_eratosthenes(10) assert primes == [False, False, True, True, False, True, False, True, False, False, False] primes = sieve_of_eratosthenes(20) assert primes == [...
[ { "docstring": "Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(limit):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(limit)" }, { "docstring": "Counts the number of prim...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004462", "row_id": 4462, "seed_ids": "[7503]" }
0.609102
Code_Contests_4462
I
[ "sieve_of_eratosthenes", "count_primes_up_to_n", "count_primes" ]
3
[ [ "count_primes", "count_primes_up_to_n" ], [ "count_primes", "sieve_of_eratosthenes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
31d49b2e79d71cb3191b8b663036a583926f53a1
3ec601d98521b58ba819b4222fa6a6944b881d66
v1.0
instruct
Code_Contests
Code_Contests_4513_I
Tom is interested in analyzing trends in temperature data. He has collected temperature readings from various sensors. Each sensor provides a reading taken at the same time, and he wants to analyze the difference between the highest and lowest readings for each time slot (session) and for each location. Each session c...
def temperature_difference(sessions): result = [] for readings in sessions: max_temp = max(readings) min_temp = min(readings) difference = max_temp - min_temp result.append(difference) return result def process_sessions(input_data): lines = input_data.strip().split("\n")...
from solution import process_sessions def test_single_session(): input_data = "1\n3\n-10 0 5\n" expected_output = [15] assert process_sessions(input_data) == expected_output def test_multiple_sessions(): input_data = "2\n3\n-10 0 5\n4\n15 -20 35 10\n" expected_output = [15, 55] assert process_...
[ { "docstring": null, "function_declaration": "def temperature_difference(sessions):", "function_name": "temperature_difference", "parameter_list": "(sessions)" }, { "docstring": null, "function_declaration": "def process_sessions(input_data):", "function_name": "process_sessions", ...
[ 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 temperature_differences(sessions):\n \"\"\"\n Calculate the difference between \n the maximum and minimum temperature readings for each sessio...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004513", "row_id": 4513, "seed_ids": "[9338]" }
0.584684
Code_Contests_4513
I
[ "temperature_difference", "process_sessions" ]
2
[ [ "process_sessions", "temperature_difference" ] ]
1
[]
false
[]
false
pytest
true
[]
true
09f3b6d52dca2145fc2aad936aa83f88fee8cd4d
74b650d4c6cfc51d4fbce31617b472749426ab02
v1.0
instruct
Code_Contests
Code_Contests_4522_I
Archaeologist Alex is exploring an ancient temple. In one of the rooms, he discovers a mosaic made up of colored tiles arranged in a rectangular grid. The room guardian informs Alex that the mosaic follows a special pattern defined by the sum of the digits of the grid coordinates. The tiles are positioned in an m x n ...
def sum_of_digits(x): """ Calculates the sum of the digits of a given number x. """ return sum(int(digit) for digit in str(x)) def generate_mosaic(m, n): """ Generates an m x n grid of tiles based on the color scheme rule. """ mosaic = [] for i in range(1, m + 1): row = [] ...
def test_sum_of_digits(): assert sum_of_digits(1) == 1 assert sum_of_digits(10) == 1 assert sum_of_digits(123) == 6 assert sum_of_digits(99) == 18 def test_generate_mosaic(): result = generate_mosaic(3, 4) expected = [ ['W', 'B', 'W', 'B'], ['B', 'W', 'B', 'W'], ['W', 'B...
[ { "docstring": "Calculates the sum of the digits of a given number x.", "function_declaration": "def sum_of_digits(x):", "function_name": "sum_of_digits", "parameter_list": "(x)" }, { "docstring": "Generates an m x n grid of tiles based on the color scheme rule.", "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 digit_sum(x):\n \"\"\"\n Returns the sum of the digits of an integer x.\n \"\"\"\n return sum(int(digit) for digit in str(x))\n\ndef mosaic...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004522", "row_id": 4522, "seed_ids": "[7088]" }
0.704438
Code_Contests_4522
I
[ "sum_of_digits", "generate_mosaic" ]
2
[ [ "generate_mosaic", "sum_of_digits" ] ]
1
[]
false
[]
false
pytest
false
[]
true
71b67b9ec9ba26edf8b90418a0e001c447a2295e
ecda1e48bf594318c9e6b8c2e88d37f67156f923
v1.0
instruct
Code_Contests
Code_Contests_4524_I
Your task is to write a function that takes a list of customer order records and sorts them based on customer priority and order placement time. Each record consists of a customer name, customer ID number, priority level, and a timestamp indicating when the order was placed. The order records should be sorted first by ...
def sort_customer_orders(order_records): """ Sorts the customer order records based on customer priority and order placement time. Args: order_records (list of tuples): List of customer records in the format (customer name, customer ID number, priority level, ti...
from solution import sort_customer_orders, process_orders def test_sort_customer_orders(): orders = [ ('JohnDoe', 123456, 3, '2022-08-01T12:00:00'), ('JaneSmith', 234567, 7, '2022-08-01T11:30:00'), ('AliceJones', 345678, 5, '2022-08-01T11:45:00'), ('BobBrown', 456789, 5, '2022-08-01...
[ { "docstring": "Sorts the customer order records based on customer priority and order placement time.\n\nArgs:\norder_records (list of tuples): List of customer records in the format \n (customer name, customer ID number, priority level, timestamp)\n\nReturns:\nlist of tuples: Sor...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_customer_orders(n, orders):\n \"\"\"\n Sorts customer orders based on priority and timestamp.\n \n Args:\n - n (int): the number of...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00004524", "row_id": 4524, "seed_ids": "[5197]" }
0.615241
Code_Contests_4524
I
[ "sort_customer_orders", "process_orders" ]
2
[ [ "process_orders", "sort_customer_orders" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6eb4dc5596489c864372c9c306a2a19c2ad4c430
df8952f2fa6e0da563c91e685d6f814baa16fbad
v1.0
instruct
Code_Contests
Code_Contests_4535_I
In a mystical land called Wonderland, people speak in a special language known as "Wondrous Talk". In this language, there is a unique way of encoding words using a method called "Palindromify". The process works as follows: 1) The given word is converted into a palindrome by appending the minimum number of characters ...
def is_palindrome(s): return s == s[::-1] def palindromify(word): n = len(word) if is_palindrome(word): return word for length in range(n): if is_palindrome(word[length:]): return word + word[:length][::-1] return word # Should never reach here since the loop should cov...
from solution import is_palindrome, palindromify, process_test_cases def test_is_palindrome(): assert is_palindrome("abcba") == True assert is_palindrome("racecar") == True assert is_palindrome("hello") == False assert is_palindrome("a") == True assert is_palindrome("ab") == False def test_palindr...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def palindromify(word):", "function_name": "palindromify", "parameter_list": "(word)" }, { "doc...
[ 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 palindromify(word):\n \"\"\"\n Converts a given word into a palindrome by appending the minimum number \n of characters at the end of the word...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00004535", "row_id": 4535, "seed_ids": "[5902]" }
0.765986
Code_Contests_4535
I
[ "is_palindrome", "palindromify", "process_test_cases" ]
3
[ [ "palindromify", "is_palindrome" ], [ "process_test_cases", "palindromify" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
e34f9f95e510deec351427dc9a0ab3f6b692fbdd
a1de45d94798250c1f9da4f60961449564590064
v1.0
instruct
Code_Contests
Code_Contests_4540_I
You are given a grid consisting of N rows and M columns. Each cell in the grid can either be '0' (empty) or '1' (occupied). You need to find the largest rectangular subgrid that contains only '1's and return its area. Input: The first line of input contains two integers, N and M, representing the number of rows and co...
def maximal_rectangle(matrix): if not matrix: return 0 n = len(matrix) m = len(matrix[0]) max_area = 0 heights = [0] * m for row in matrix: for i in range(m): if row[i] == '1': heights[i] += 1 else: heights[i] = 0 ...
def test_largest_rectangle_area_1(): grid = [ "101101", "111111", "011011", "111010", "110101" ] assert find_largest_rectangle_area(5, 6, grid) == 6 def test_largest_rectangle_area_2(): grid = [ "1" ] assert find_largest_rectangle_area(1, 1, grid)...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 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 maximalRectangle(matrix):\n if not matrix:\n return 0\n \n n, m = len(matrix), len(matrix[0])\n max_area = 0\n dp = [0] * m\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00004540", "row_id": 4540, "seed_ids": "[12600]" }
0.738757
Code_Contests_4540
I
[ "maximal_rectangle", "largest_rectangle_area", "find_largest_rectangle_area" ]
3
[ [ "find_largest_rectangle_area", "maximal_rectangle" ], [ "maximal_rectangle", "largest_rectangle_area" ] ]
2
[]
false
[]
false
pytest
false
[]
true
1eb36ea213b646b3c5385c709fddbd1ebbb23207
fc38bb10babcea0017f6ad1d0e64604a1225a25c
v1.0
instruct
Code_Contests
Code_Contests_4542_I
Given a decimal number system, you need to perform certain operations on the numbers, such as reversing and adding until the number becomes a palindrome. A palindrome is a number that reads the same forward and backward. For example, 121 is a palindrome, while 123 is not. The operation that needs to be performed is:...
def reverse_number(n): """ Reverses the digits of an integer. """ return int(str(n)[::-1]) def is_palindrome(n): """ Checks if an integer is a palindrome. """ return str(n) == str(n)[::-1] def find_palindrome(n): """ Finds the palindrome by reversing and adding the digits of th...
from solution import reverse_number, is_palindrome, find_palindrome def test_reverse_number(): assert reverse_number(123) == 321 assert reverse_number(4567) == 7654 assert reverse_number(0) == 0 assert reverse_number(1000) == 1 def test_is_palindrome(): assert is_palindrome(121) == True assert...
[ { "docstring": "Reverses the digits of an integer.", "function_declaration": "def reverse_number(n):", "function_name": "reverse_number", "parameter_list": "(n)" }, { "docstring": "Checks if an integer is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_number(n):\n \"\"\"\n Returns the reverse of the given number.\n \"\"\"\n return int(str(n)[::-1])\n\ndef is_palindrome(n):\n \"...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004542", "row_id": 4542, "seed_ids": "[1371]" }
0.783984
Code_Contests_4542
I
[ "reverse_number", "is_palindrome", "find_palindrome" ]
3
[ [ "find_palindrome", "is_palindrome" ], [ "find_palindrome", "reverse_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b5352dfb1a768c3e9a7267dfb3bfb0347413458a
4f1579e414839f36cd7bc82dac2b87b5a580d7e8
v1.0
instruct
Code_Contests
Code_Contests_4605_I
The Mysterious Cave Problem Statement A cave is represented as an undirected graph where each node represents a chamber and each edge represents a tunnel between chambers. There are N chambers and M tunnels within the cave. The cave system starts at chamber 1, and two adventurers are trying to find the shortest path...
import heapq def dijkstra(graph, start, N): dist = [float('inf')] * (N + 1) dist[start] = 0 pq = [(0, start)] while pq: current_dist, node = heapq.heappop(pq) if current_dist > dist[node]: continue for v, weight in graph[node]: dist...
from solution import mysterious_cave def test_example_1(): N = 5 M = 7 tunnels = [ (1, 2, 2), (1, 3, 3), (2, 3, 1), (2, 4, 2), (3, 4, 1), (4, 5, 3), (3, 5, 5) ] assert mysterious_cave(N, M, tunnels) == 7 def test_example_2(): N = 4 M ...
[ { "docstring": null, "function_declaration": "def dijkstra(graph, start, N):", "function_name": "dijkstra", "parameter_list": "(graph, start, N)" }, { "docstring": null, "function_declaration": "def solve(N, M, tunnels):", "function_name": "solve", "parameter_list": "(N, M, tunne...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, start):\n N = len(graph)\n dist = [float('inf')] * N\n dist[start] = 0\n priority_queue = [(0, start)]\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004605", "row_id": 4605, "seed_ids": "[514]" }
0.668012
Code_Contests_4605
I
[ "dijkstra", "solve", "mysterious_cave" ]
3
[ [ "mysterious_cave", "solve" ], [ "solve", "dijkstra" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c68423b6434c991b8d589925426e6b9b1e9f20e9
01db347650056aa51c910021ad15752fd1f6fe20
v1.0
instruct
Code_Contests
Code_Contests_4641_I
Draco is designing a new coding challenge platform called CodeFlare. Participants are scored based on their code submission, where the score is derived from running time and memory consumption. Draco wants to determine if a participants' score after solving a problem meets certain criteria. Every participant gets a s...
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...
from solution import qualifies def test_qualifies_prime_palindrome(): # 7 is a prime and a palindrome assert qualifies(7) == "YES" def test_qualifies_prime_sum_of_digits_prime(): # 23 is prime and sum of digits (2+3=5) is also prime assert qualifies(23) == "YES" def test_does_not_qualify_not_prime():...
[ { "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", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004641", "row_id": 4641, "seed_ids": "[7871]" }
0.640306
Code_Contests_4641
I
[ "is_prime", "is_palindrome", "sum_of_digits", "qualifies" ]
4
[ [ "qualifies", "is_palindrome" ], [ "qualifies", "is_prime" ], [ "qualifies", "sum_of_digits" ] ]
3
[]
false
[]
false
pytest
true
[]
true
25fd148f5612a640e841b0ab56c95998c0642932
98666412a90234ca8732e7e141a5c8d238571094
v1.0
instruct
Code_Contests
Code_Contests_4705_I
A company is planning to install a series of utility poles along a new highway to provide electrical and communication services. The distance between consecutive utility poles should be the same to ensure uniformity. The company has M candidate locations where the poles can be installed. Since some of the locations ma...
def gcd(a, b): while b: a, b = b, a % b return a def longest_distance(M, positions): positions.sort() diffs = [positions[i] - positions[i - 1] for i in range(1, M)] d = diffs[0] for i in range(1, M - 1): d = gcd(d, diffs[i]) if d == 1: return 1 return d
from solution import longest_distance def test_example_1(): M = 5 positions = [1, 3, 7, 9, 13] assert longest_distance(M, positions) == 2 def test_example_2(): M = 4 positions = [5, 10, 15, 20] assert longest_distance(M, positions) == 5 def test_example_3(): M = 3 positions = [1, 2, 4...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def longest_distance(M, positions):", "function_name": "longest_distance", "parameter_list": "(M, positions)" } ]
[ 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_longest_distance(M, positions):\n \"\"\"\n Returns the longest possible distance D such that we can install a pole \n at every D-th locat...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004705", "row_id": 4705, "seed_ids": "[2207]" }
0.656445
Code_Contests_4705
I
[ "gcd", "longest_distance" ]
2
[ [ "longest_distance", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7252621974d538b346eb46ed59974722bae57988
8ba4d75d570611f509b7af00da40e7db9cd2736d
v1.0
instruct
Code_Contests
Code_Contests_4749_I
You are tasked with reading multiple lines of input where each line represents a mathematical expression in prefix notation. Your job is to evaluate each expression and produce the result. Prefix notation (also known as Polish notation) is a way of writing mathematical expressions where the operator precedes their oper...
def evaluate_prefix(expression): """ Evaluates a single prefix expression. """ stack = [] # Split the expression on whitespace tokens = expression.split() # Reverse tokens to process them from right to left tokens.reverse() # Define the operations def operate(op, a, b): ...
from solution import evaluate_prefix, evaluate_multiple_prefix_expressions def test_evaluate_prefix_addition(): assert evaluate_prefix("+ 10 2") == 12 def test_evaluate_prefix_subtraction(): assert evaluate_prefix("- 10 2") == 8 def test_evaluate_prefix_multiplication(): assert evaluate_prefix("* 3 2") =...
[ { "docstring": "Evaluates a single prefix expression.", "function_declaration": "def evaluate_prefix(expression):", "function_name": "evaluate_prefix", "parameter_list": "(expression)" }, { "docstring": "Evaluates multiple prefix expressions.", "function_declaration": "def evaluate_multi...
[ 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 evaluate_prefix(expression):\n \"\"\"\n Evaluates a single prefix expression and returns the result.\n \"\"\"\n stack = []\n tokens = ex...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004749", "row_id": 4749, "seed_ids": "[683]" }
0.566671
Code_Contests_4749
I
[ "evaluate_prefix", "evaluate_multiple_prefix_expressions" ]
2
[ [ "evaluate_multiple_prefix_expressions", "evaluate_prefix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78062e565294caf7a73c3ec06fc894e7f25790c5
cfce8addd8d3dcdab59e56d8cc502a05f4644929
v1.0
instruct
Code_Contests
Code_Contests_4797_I
Consider a network of computers where certain pairs are directly connected by cables. You are given the number of computers and a list of pairs of computers that are directly connected. Two computers are said to be connected if there is a direct cable between them. Your task is to determine the minimum number of cables...
def find(parent, i): if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if root_x != root_y: if rank[root_x] > rank[root_y]: parent[r...
from solution import min_cables_to_add def test_case_1(): assert min_cables_to_add(5, 3, [(1, 2), (2, 3), (4, 5)]) == 1 def test_case_2(): assert min_cables_to_add(5, 1, [(1, 2)]) == 3 def test_case_3(): assert min_cables_to_add(1, 0, []) == 0 def test_case_4(): assert min_cables_to_add(4, 2, [(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)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004797", "row_id": 4797, "seed_ids": "[4418]" }
0.687455
Code_Contests_4797
I
[ "find", "union", "min_cables_to_add" ]
3
[ [ "min_cables_to_add", "find" ], [ "min_cables_to_add", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b24ff3e2ad44afeca41ed676634c726258390e70
09fbd618f3ba2284dccee75e74fc1986deb912ca
v1.0
instruct
Code_Contests
Code_Contests_4800_I
You are given an undirected graph represented as an adjacency list, in which each node contains a lowercase English letter as its value. Your task is to determine if there exists a path between any two nodes such that the concatenation of all node values along the path forms a palindrome. A palindrome is a string that...
from collections import defaultdict, deque def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def dfs(graph, visited, node, path, values, result): """ Depth-first search to find if any path forms a palindrome. """ if result[0]: # If a palindr...
import pytest from solution import has_palindrome_path def test_example_1(): assert has_palindrome_path(5, 5, "abcba", [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)]) == "YES" def test_example_2(): assert has_palindrome_path(3, 2, "abc", [(0, 1), (1, 2)]) == "NO" def test_single_node(): assert has_palindrome_p...
[ { "docstring": "Helper function to check if a given string is a palindrome. ", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Depth-first search to find if any path forms a palindrome. ", "function_declaration...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef is_palindrome(s):\n \"\"\" Helper function to check if a given string is a palindrome. \"\"\"\n ret...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004800", "row_id": 4800, "seed_ids": "[78]" }
0.726877
Code_Contests_4800
I
[ "is_palindrome", "dfs", "has_palindrome_path" ]
3
[ [ "dfs", "is_palindrome" ], [ "has_palindrome_path", "dfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ed1660703db85f9fc4c5361554545856ae1c8a66
bb1ae1d7139c02a8f489f83e838d5b2ee9346c87
v1.0
instruct
Code_Contests
Code_Contests_4824_I
You are given an undirected graph with n vertices and m edges. Each edge connects two different vertices and has an integer weight. The graph might contain loops or multiple edges with different weights. You want to choose a subset of the edges such that it forms a tree that spans all the vertices. A tree is a connect...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) ...
from solution import solve def test_example_1(): n, m = 4, 4 edge_list = [ (1, 2, 3), (2, 3, 1), (3, 4, 4), (4, 1, 2) ] assert solve(n, m, edge_list) == 6 def test_example_2(): n, m = 4, 3 edge_list = [ (1, 2, 3), (1, 3, 4), (1, 4, 5) ...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(par...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00004824", "row_id": 4824, "seed_ids": "[11074]" }
0.816876
Code_Contests_4824
I
[ "kruskal_minimum_spanning_tree", "solve" ]
2
[ [ "solve", "kruskal_minimum_spanning_tree" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
true
[]
true
6f7ca99665a7e889c7d4c4a6111c194bdc17266e
348c8d0d44a61376d739d5969969313994cb1fce
v1.0
instruct
Code_Contests
Code_Contests_4913_I
Alex has a rectangular grid consisting of '1's and '0's. He wants to find the maximum area of a rectangle (containing only '1's) that can be formed within this grid. The rectangular grid is represented as a list of strings, where each string represents a row in the grid and contains only the characters '1' or '0'. Yo...
def maximal_rectangle(grid): if not grid: return 0 n = len(grid) m = len(grid[0]) max_area = 0 heights = [0] * (m + 1) for row in grid: for i in range(m): heights[i] = heights[i] + 1 if row[i] == '1' else 0 stack = [-1] for i in range(m + 1): ...
def test_max_rectangle_1(): assert compute_max_rectangle(4, 4, ["1010", "1011", "1111", "0111"]) == 6 def test_max_rectangle_2(): assert compute_max_rectangle(2, 3, ["001", "111"]) == 3 def test_max_rectangle_3(): assert compute_max_rectangle(3, 3, ["110", "110", "001"]) == 4 def test_max_rectangle_empty...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(grid):", "function_name": "maximal_rectangle", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def compute_max_rectangle(n, m, grid_lines):", "function_name": "compute_max_rectangle", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximal_rectangle(grid):\n if not grid:\n return 0\n\n n = len(grid)\n m = len(grid[0])\n max_area = 0\n heights = [0] * (m + 1)\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00004913", "row_id": 4913, "seed_ids": "[3550]" }
0.710705
Code_Contests_4913
I
[ "maximal_rectangle", "compute_max_rectangle" ]
2
[ [ "compute_max_rectangle", "maximal_rectangle" ] ]
1
[]
false
[]
false
pytest
false
[]
true
23b605c01225c917cc265896a0ad13537d94db79
cd79f49a3531451ea2c91ab8c8fd115698cd81c2
v1.0
instruct
Code_Contests
Code_Contests_4943_I
A submarine needs to navigate through a grid representing the ocean floor. The grid is represented as a matrix of size `N x N`, where each cell is either water (denoted by ‘.’) or an obstacle (denoted by ‘#’). The submarine can start at any water cell and needs to navigate to the other side of the grid. The submarine c...
from collections import deque def min_navigation_moves(grid): N = len(grid) directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Four possible movements def is_valid(x, y): return 0 <= x < N and 0 <= y < N and grid[x][y] == '.' # Initialize distance matrix with a large number (infinity) dist...
def test_min_navigation_moves(): data = "2\n3\n..#\n.#.\n...\n3\n###\n.#.\n..#\n" result = solve(data) expected = "2\n-1" assert result == expected def test_single_cell_grid(): data = "1\n1\n.\n" result = solve(data) expected = "0" assert result == expected def test_no_valid_starting_p...
[ { "docstring": null, "function_declaration": "def min_navigation_moves(grid):", "function_name": "min_navigation_moves", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def navigate_submarine(test_cases):", "function_name": "navigate_submarine", "param...
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef min_moves_to_cross(grid, N):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n \n def is_valid(x, y):\n ...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00004943", "row_id": 4943, "seed_ids": "[1150]" }
0.760221
Code_Contests_4943
I
[ "min_navigation_moves", "navigate_submarine", "parse_input", "solve" ]
4
[ [ "navigate_submarine", "min_navigation_moves" ], [ "solve", "navigate_submarine" ], [ "solve", "parse_input" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
false
[]
true
c24e446d41e9b721f454402db853d02b26d4c0c9
032193a205ba0ee99c37eba86ed388d4228f3573
v1.0
instruct
Code_Contests
Code_Contests_4958_I
Sophie is fascinated by prime numbers and their properties. She recently stumbled upon the concept of twin primes – pairs of prime numbers that have a difference of two (e.g., 3 and 5, 11 and 13). She is curious to find all the twin primes up to a given number n. Write a program to assist Sophie by listing all twin pr...
def sieve_of_eratosthenes(n): """ Generates a list of primes up to n using the Sieve of Eratosthenes. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 return [p for ...
from solution import process_test_cases, sieve_of_eratosthenes, find_twin_primes def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_find_twin_primes(): assert find_twin_primes(10) == [(3, 5), (5, 7)] ...
[ { "docstring": "Generates a list of primes up to n using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Finds all twin prime pairs up to n.", "function_declaration"...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generates a list of boolean values indicating prime numbers up to n.\n \"\"\"\n is_prime = [True] * (n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00004958", "row_id": 4958, "seed_ids": "[12571]" }
0.70257
Code_Contests_4958
I
[ "sieve_of_eratosthenes", "find_twin_primes", "twin_primes_up_to_n", "process_test_cases" ]
4
[ [ "find_twin_primes", "sieve_of_eratosthenes" ], [ "process_test_cases", "twin_primes_up_to_n" ], [ "twin_primes_up_to_n", "find_twin_primes" ] ]
3
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
e1e13ad39bdce819360e53a3a05226e3df504f4b
8f5e652c441c646842007c256a472b50e120bc23
v1.0
instruct
Code_Contests
Code_Contests_4986_I
Anna is fascinated by prime numbers and recently learned about twin primes. Twin primes are pairs of prime numbers (p1, p2) such that p2 = p1 + 2. For example, (3, 5) and (11, 13) are twin primes. Anna has a collection of n integers and she wants to know how many of those integers are part of a twin prime pair. Writ...
def is_prime(n): """ Determines if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import count_twin_prime_pairs def test_example_1(): assert count_twin_prime_pairs(5, [3, 5, 6, 11, 13]) == 4 def test_example_2(): assert count_twin_prime_pairs(4, [1, 2, 4, 10]) == 0 def test_single_element_no_twin(): assert count_twin_prime_pairs(1, [17]) == 0 def test_single_element_twi...
[ { "docstring": "Determines if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the count of numbers in the collection that are part of at least one twin prime pair.", "function_declar...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00004986", "row_id": 4986, "seed_ids": "[12843]" }
0.694058
Code_Contests_4986
I
[ "is_prime", "count_twin_prime_pairs" ]
2
[ [ "count_twin_prime_pairs", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5938543d97771d8d432b894f0928c9a05c83f3c6
06c4e9870cb121675e769b2744f79c31b3cb508b
v1.0
instruct
Code_Contests
Code_Contests_5003_I
In a small town, there's a series of roads connecting various intersections. Each intersection has a unique identifier ranging from 1 to n. However, some intersections have directed roads that only allow traffic in one direction. The town has k detective agencies, each positioned at different intersections. Each agency...
import sys from collections import defaultdict, deque def find_scc(n, graph): index = [None] * n lowlink = [None] * n on_stack = [False] * n stack = [] sccs = [] index_counter = [0] def strongconnect(v): index[v] = index_counter[0] lowlink[v] = index_counter[0] ...
from solution import solve def test_case_1(): n = 6 m = 6 k = 2 roads = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1)] agencies = [1, 4] assert solve(n, m, k, roads, agencies) == "YES" def test_case_2(): n = 6 m = 4 k = 2 roads = [(1, 2), (2, 3), (4, 5), (5, 6)] agencies ...
[ { "docstring": null, "function_declaration": "def find_scc(n, graph):", "function_name": "find_scc", "parameter_list": "(n, graph)" }, { "docstring": null, "function_declaration": "def minimum_additional_roads_to_connect_sccs(n, sccs, graph):", "function_name": "minimum_additional_ro...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef is_reachable_from_all_agencies(n, m, roads, k, agencies):\n def build_graph():\n graph = defaul...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005003", "row_id": 5003, "seed_ids": "[1485]" }
0.752662
Code_Contests_5003
I
[ "find_scc", "minimum_additional_roads_to_connect_sccs", "solve" ]
3
[ [ "solve", "find_scc" ], [ "solve", "minimum_additional_roads_to_connect_sccs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8555732dbc331cd51454352d787e70872c42300c
7bf3cab30c692c7657c7cba46bb6fec7ee169e2a
v1.0
instruct
Code_Contests
Code_Contests_5047_I
You are given a square matrix of size N x N consisting of lowercase Latin letters. You need to rotate the matrix 90 degrees clockwise. The rotation can be achieved by first transposing the matrix and then reversing each row. Input The first line contains an integer N (2 ≤ N ≤ 10) which represents the size of the mat...
def rotate_matrix_clockwise(matrix): """ Rotates the given N x N matrix 90 degrees clockwise. Parameters: matrix (list of list of str): The matrix to be rotated. Returns: list of list of str: The rotated matrix. """ # Transpose the matrix transposed_matrix = [[matrix[j][i] ...
from solution import rotate_matrix_clockwise, format_matrix def test_rotate_3x3_matrix(): matrix = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'] ] rotated_matrix = rotate_matrix_clockwise(matrix) expected = [ ['g', 'd', 'a'], ['h', 'e', 'b'], ['i', ...
[ { "docstring": "Rotates the given N x N matrix 90 degrees clockwise.\n\nParameters:\nmatrix (list of list of str): The matrix to be rotated.\n\nReturns:\nlist of list of str: The rotated matrix.", "function_declaration": "def rotate_matrix_clockwise(matrix):", "function_name": "rotate_matrix_clockwise",...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates the given N x N matrix 90 degrees clockwise.\n \n Parameters:\n matrix (list of l...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005047", "row_id": 5047, "seed_ids": "[1404]" }
0.551467
Code_Contests_5047
I
[ "rotate_matrix_clockwise", "format_matrix", "read_and_rotate_matrix" ]
3
[ [ "read_and_rotate_matrix", "format_matrix" ], [ "read_and_rotate_matrix", "rotate_matrix_clockwise" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bf95e70cedce914ece7ca1c56b8fb7b10374e2f3
d850b74c29747a00d97863bf4cae295733183c0d
v1.0
instruct
Code_Contests
Code_Contests_5065_I
Angie is planning her weekend and wants to complete as many activities as possible. Each activity is associated with a certain level of satisfaction, Si. Angie wants to maximize her overall satisfaction after completing a series of activities. On a particular weekend, she has N activities to choose from, indexed from ...
def max_satisfaction_in_sublist(S, l, r): sublist = S[l-1:r] n = len(sublist) if n == 0: return 0 dp = [0] * n dp[0] = sublist[0] max_sum = dp[0] for i in range(1, n): dp[i] = sublist[i] for j in range(i): if sublist[j] < sublist[i]: ...
def test_max_satisfaction_in_sublist(): assert max_satisfaction_in_sublist([1, 2, 3, 4, 5], 1, 5) == 15 assert max_satisfaction_in_sublist([1, 2, 1, 4, 5], 1, 5) == 12 assert max_satisfaction_in_sublist([1, 2, 1, 4, 2], 1, 5) == 7 def test_process_queries(): N = 5 S = [1, 2, 3, 4, 5] queries = ...
[ { "docstring": null, "function_declaration": "def max_satisfaction_in_sublist(S, l, r):", "function_name": "max_satisfaction_in_sublist", "parameter_list": "(S, l, r)" }, { "docstring": null, "function_declaration": "def process_queries(N, S, queries):", "function_name": "process_que...
[ 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_total_satisfaction(N, satisfaction_values, queries):\n from bisect import bisect_right\n import sys\n\n def process_query_type_2(l, r):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005065", "row_id": 5065, "seed_ids": "[5628]" }
0.713515
Code_Contests_5065
I
[ "max_satisfaction_in_sublist", "process_queries", "angie_activities" ]
3
[ [ "angie_activities", "process_queries" ], [ "process_queries", "max_satisfaction_in_sublist" ] ]
2
[ "process_queries" ]
false
[]
false
pytest
false
[]
true
7a883c018a3a8a1d16490e8612d997e9756a796c
db9fe0e5b87bfd395ae7bfbda64d588333586fff
v1.0
instruct
Code_Contests
Code_Contests_5219_I
Write a function that finds and prints all the prime numbers between 1 and a given number `N`. Input Format The first line contains an integer T, i.e., the number of test cases. The next T lines will each contain an integer N. Output Format For each test case, print all prime numbers less than or equal to N, separa...
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 find_primes_up_to_n(N): primes = [num for num in range(2, N + 1) if is_prime(num)] return " ".join(map(str, primes)) if primes else "None" ...
def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert is_prime(29) assert not is_prime(30) def test_find_primes_up_to_n(): assert find_primes_up_to_n(10) == "2 3 5 7" assert find_primes_up_to_n(1) == "None"...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_primes_up_to_n(N):", "function_name": "find_primes_up_to_n", "parameter_list": "(N)" }, { "d...
[ 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 if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005219", "row_id": 5219, "seed_ids": "[11218]" }
0.697107
Code_Contests_5219
I
[ "is_prime", "find_primes_up_to_n", "prime_numbers" ]
3
[ [ "find_primes_up_to_n", "is_prime" ], [ "prime_numbers", "find_primes_up_to_n" ] ]
2
[]
false
[]
false
pytest
false
[]
true
11fae7d6f8199f1ff8f412629944873de150003b
0dea86fa222a34f5499201cb330dcdcd7a9bf349
v1.0
instruct
Code_Contests
Code_Contests_5362_I
Square Matrix Rotation Write a program to rotate a given NxN square matrix 90 degrees clockwise. Constraints * $1 \leq N \leq 100$ * Each element in the matrix is an integer between -1000 and 1000 Input The first line contains a single integer N, the size of the NxN matrix. The next N lines contain N integers eac...
def rotate_matrix_90_degrees_clockwise(matrix): """ Rotates a given NxN square matrix 90 degrees clockwise. """ N = len(matrix) # The result matrix initialized with zeros result = [[0] * N for _ in range(N)] for i in range(N): for j in range(N): result[j][N-1-i] = ma...
from solution import rotate_matrix_90_degrees_clockwise, read_matrix_and_rotate, matrix_to_string def test_rotate_3x3_matrix(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] rotated = rotate_matrix_90_degrees_clockwise(matrix) expected = [ [7, 4, 1], [8, 5, 2], ...
[ { "docstring": "Rotates a given NxN square matrix 90 degrees clockwise.", "function_declaration": "def rotate_matrix_90_degrees_clockwise(matrix):", "function_name": "rotate_matrix_90_degrees_clockwise", "parameter_list": "(matrix)" }, { "docstring": "Helper function to read the matrix from ...
[ 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_matrix_90_degrees(matrix):\n \"\"\"\n Rotate the NxN matrix 90 degrees clockwise.\n \n :param matrix: List of lists, where each inne...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005362", "row_id": 5362, "seed_ids": "[7289]" }
0.631758
Code_Contests_5362
I
[ "rotate_matrix_90_degrees_clockwise", "read_matrix_and_rotate", "matrix_to_string" ]
3
[ [ "read_matrix_and_rotate", "rotate_matrix_90_degrees_clockwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a534970795f4433aca25ff6913a5bb26d9be4ba
855f699e3c49ef7826d608c88675ad0030b127d2
v1.0
instruct
Code_Contests
Code_Contests_5395_I
Given a list of words, you are to find and print the most frequent word. If two or more words have the same highest frequency, print the lexicographically smallest one among them. Input The input consists of up to 100 datasets. Each dataset is represented in the following format: The first line contains a single int...
def most_frequent_word(datasets): from collections import Counter results = [] for dataset in datasets: word_count = Counter(dataset) # Find the maximum frequency max_freq = max(word_count.values()) # Collect all words with the maximum frequency max...
from solution import most_frequent_word, parse_input, get_most_frequent_in_datasets def test_most_frequent_word(): datasets = [ ['apple', 'banana', 'apple', 'orange', 'banana'], ['apple', 'apple', 'banana', 'banana'], ['apple', 'banana', 'apple', 'banana', 'cherry', 'cherry'] ] asse...
[ { "docstring": null, "function_declaration": "def most_frequent_word(datasets):", "function_name": "most_frequent_word", "parameter_list": "(datasets)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parameter_list":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def most_frequent_word(datasets):\n \"\"\"\n Given a list of datasets, this function returns the most frequent word in each dataset. If multiples wor...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005395", "row_id": 5395, "seed_ids": "[12700]" }
0.724418
Code_Contests_5395
I
[ "most_frequent_word", "parse_input", "get_most_frequent_in_datasets" ]
3
[ [ "get_most_frequent_in_datasets", "most_frequent_word" ], [ "get_most_frequent_in_datasets", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
49ab6d68517310d384a508114014b581a7d4a564
48eafd59af0622205be315bba98a9f5be8f34a17
v1.0
instruct
Code_Contests
Code_Contests_5418_I
The company XYTech has several departments, each operating in their own building and connected via direct communication links. Each building is represented as a node, and each communication link is represented as an edge with an associated latency value. For the proper functioning of certain applications, it is crucial...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] = ro...
from solution import min_max_latency def test_sample_input_1(): n = 4 m = 5 edges = [ (1, 2, 4), (2, 3, 5), (3, 4, 6), (4, 2, 2), (1, 3, 8) ] assert min_max_latency(n, m, edges) == 5 def test_sample_input_2(): n = 3 m = 3 edges = [ (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)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(pare...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005418", "row_id": 5418, "seed_ids": "[4414]" }
0.604751
Code_Contests_5418
I
[ "find", "union", "min_max_latency" ]
3
[ [ "min_max_latency", "find" ], [ "min_max_latency", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ac03494a7bdde2ed20dafef549deccece446a0e5
fc70fca7bae6215b7f2990d12b3ac83d0c6ae9c5
v1.0
instruct
Code_Contests
Code_Contests_5423_I
Alice is organizing a marathon event. She has received M queries each asking for the number of steps a runner needs to complete to reach a certain milestone in the race. The route map of the marathon is given as a directed graph where each node represents a checkpoint and an edge between two nodes represents the direct...
import heapq def dijkstra(graph, N, start): """ Performs Dijkstra's algorithm to find the shortest path from start to all other nodes. Args: graph: Dictionary containing adjacency list, where keys are node ids and values are list of tuples (neighbor, cost) representing the edges. N:...
def test_dijkstra(): graph = { 1: [(2, 2), (3, 4)], 2: [(4, 7), (5, 3)], 3: [(4, 1)], 4: [(5, 1)], 5: [] } N = 5 start = 1 assert dijkstra(graph, N, start) == [float('inf'), 0, 2, 4, 5, 5] def test_marathon_event(): N = 5 E = 6 edges = [ (...
[ { "docstring": "Performs Dijkstra's algorithm to find the shortest path from start to all other nodes.\n\nArgs:\ngraph: Dictionary containing adjacency list, where keys are node ids\n and values are list of tuples (neighbor, cost) representing the edges.\nN: Number of nodes in the graph.\nstart: Starting ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(graph, N, start):\n \"\"\"\n Performs Dijkstra's algorithm to find the shortest path from start to all other nodes.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005423", "row_id": 5423, "seed_ids": "[5174]" }
0.713626
Code_Contests_5423
I
[ "dijkstra", "marathon_event" ]
2
[ [ "marathon_event", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8b59172e82a0b969f6afad335ef791315fe414c7
5ec89d1ec52d556dc582909e77fe41078d2d61e7
v1.0
instruct
Code_Contests
Code_Contests_5473_I
A software company is updating their old attendance record system. They want to perform various operations on the attendance records but need assistance in validating and manipulating the data to make it compatible with the new system. Each attendance record consists of a series of timestamps representing when an emplo...
from datetime import datetime def is_valid_time_format(time_str): try: datetime.strptime(time_str, '%H:%M') return True except ValueError: return False def is_overlap(intervals): intervals = sorted(intervals, key=lambda x: x[0]) for i in range(len(intervals) - 1): if in...
from solution import validate_and_clean_records def test_valid_records(): assert validate_and_clean_records(1, ["08:00-12:00 13:00-17:00"]) == ["08:00-12:00 13:00-17:00"] def test_overlapping_intervals(): assert validate_and_clean_records(1, ["09:00-12:00 09:30-11:30"]) == ["Invalid record"] def test_invalid...
[ { "docstring": null, "function_declaration": "def is_valid_time_format(time_str):", "function_name": "is_valid_time_format", "parameter_list": "(time_str)" }, { "docstring": null, "function_declaration": "def is_overlap(intervals):", "function_name": "is_overlap", "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": "import re\nfrom datetime import datetime\n\ndef validate_and_clean_attendance(n, records):\n def is_valid_time_format(time_str):\n try:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005473", "row_id": 5473, "seed_ids": "[12021]" }
0.554515
Code_Contests_5473
I
[ "is_valid_time_format", "is_overlap", "validate_and_clean_records", "main" ]
4
[ [ "validate_and_clean_records", "is_overlap" ], [ "validate_and_clean_records", "is_valid_time_format" ] ]
2
[]
false
[]
false
pytest
true
[]
true
cc219b32a185de56b035053db12584f25af23741
130973ccd4d84951d104cd42249ce9479e3d2005
v1.0
instruct
Code_Contests
Code_Contests_5494_I
You are given an initially empty array A consisting of integers. There are two types of operations you can perform on this array: 1. Add a given integer x (1 ≤ x ≤ 10^9) to the end of the array. 2. Determine the maximum sum of any contiguous subarray within A. Input The first line contains a single integer Q (1 ≤ Q ...
def process_operations(Q, operations): """ Processes a list of operations on an initially empty array and returns the results of operation type 2 which determine the maximum sum of any contiguous subarray. Parameters: Q (int): Number of operations. operations (list of str): List of operatio...
from solution import process_operations, max_contiguous_subarray_sum def test_max_contiguous_subarray_sum(): assert max_contiguous_subarray_sum([1, 2, -4]) == 3 assert max_contiguous_subarray_sum([1, 2, -4, 3, -1]) == 3 assert max_contiguous_subarray_sum([-1, -2, -3, -4]) == -1 assert max_contiguous_su...
[ { "docstring": "Processes a list of operations on an initially empty array and returns the results\nof operation type 2 which determine the maximum sum of any contiguous subarray.\n\nParameters:\nQ (int): Number of operations.\noperations (list of str): List of operations in string format.\n\nReturns:\nlist of ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_subarray_sum(queries):\n \"\"\"\n Returns a list of results for the maximum sum of any contiguous subarray after each type 2 query.\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005494", "row_id": 5494, "seed_ids": "[12664]" }
0.786108
Code_Contests_5494
I
[ "process_operations", "max_contiguous_subarray_sum" ]
2
[ [ "process_operations", "max_contiguous_subarray_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7c5bd2dc36d52a7fdb325f5760775b586c2f54a6
8563d12623614411e33f002f857b3e63974bc441
v1.0
instruct
Code_Contests
Code_Contests_5498_I
You are given a matrix of size N x M filled with integers. Your task is to transform the matrix such that every row and every column is sorted in ascending order while maintaining the relative positions of all matrix elements. Print the transformed matrix in the format specified in the Output section: Constraints: ...
def sort_matrix(matrix): """ This function takes a matrix and returns a new matrix where each row and each column is sorted in ascending order while maintaining the relative positions of all matrix elements. """ N = len(matrix) M = len(matrix[0]) # Flatten the matrix and sort the ...
def test_sort_matrix_case_1(): matrix = [ [3, 1, 2], [4, 6, 5], [7, 9, 8] ] expected = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert sort_matrix(matrix) == expected def test_sort_matrix_case_2(): matrix = [ [1, 3, 5, 7], [2, 4, 6, 8] ...
[ { "docstring": "This function takes a matrix and returns a new matrix where each row and each \ncolumn is sorted in ascending order while maintaining the relative positions \nof all matrix elements.", "function_declaration": "def sort_matrix(matrix):", "function_name": "sort_matrix", "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 sort_matrix(matrix):\n \"\"\"\n Transforms the input matrix such that each row and column are sorted in ascending order\n while maintaining th...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00005498", "row_id": 5498, "seed_ids": "[6229]" }
0.562041
Code_Contests_5498
I
[ "sort_matrix", "transform_and_print_matrix", "main" ]
3
[ [ "transform_and_print_matrix", "sort_matrix" ] ]
1
[]
false
[]
false
pytest
false
[]
true
56c9fb5d5a4655bea23e28bdf9e9b58480f7535c
16f91730b662e64a270f7b9e360657d6829f65f7
v1.0
instruct
Code_Contests
Code_Contests_5532_I
A city needs to lay down a network of pipes to connect several reservoirs together to ensure a steady water supply throughout the area. The city authorities want to minimize the cost of laying the pipes while ensuring that there is a direct or indirect path between every pair of reservoirs. There are M possible pipes ...
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): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] ...
from solution import min_cost_to_connect_reservoirs def test_example_case(): N = 4 M = 5 pipes = [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (2, 4, 5)] assert min_cost_to_connect_reservoirs(N, M, pipes) == 6 def test_no_reservoirs(): N = 0 M = 0 pipes = [] assert min_cost_to_connect_r...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Importing required libraries for Kruskal's algorithm\nimport sys\ninput = sys.stdin.read\nfrom heapq import heappop, heappush\n\n# Disjoint set (Union-Fi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005532", "row_id": 5532, "seed_ids": "[8212]" }
0.715068
Code_Contests_5532
I
[ "find", "union", "min_cost_to_connect_reservoirs", "process_input_data", "main" ]
5
[ [ "min_cost_to_connect_reservoirs", "find" ], [ "min_cost_to_connect_reservoirs", "union" ], [ "union", "find" ] ]
3
[ "process_input_data" ]
false
[]
false
pytest
true
[]
true
a52cd63f1f8059cb25017d2a7f3c3a5067cbe600
497e34b28c7ab0fb165d28a7ad40852669861108
v1.0
instruct
Code_Contests
Code_Contests_5550_I
You are given a list of integers. For each integer, determine whether it can be represented as the sum of two unique prime numbers. Write a program to solve this problem. Input The first line contains a single integer t (1 ≤ t ≤ 10^6), the number of test cases. Each of the next t lines contains a single integer n (4 ≤...
def sieve(n): is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 is_prime[0], is_prime[1] = False, False primes = [p for p in range(n + 1) if is_prime[p]] return primes, is_pr...
from solution import check_numbers def test_example_case(): t = 3 numbers = [10, 17, 34] expected = ["YES", "NO", "YES"] assert check_numbers(t, numbers) == expected def test_single_no_case(): t = 1 numbers = [17] expected = ["NO"] assert check_numbers(t, numbers) == expected def test...
[ { "docstring": null, "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def can_be_sum_of_two_unique_primes(n, primes, is_prime):", "function_name": "can_be_sum_of_two_unique_primes", "parame...
[ 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 sieve_of_eratosthenes(limit):\n sieve = [True] * (limit + 1)\n sieve[0] = sieve[1] = False\n p = 2\n while p * p <= limit:\n if siev...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00005550", "row_id": 5550, "seed_ids": "[491]" }
0.689618
Code_Contests_5550
I
[ "sieve", "can_be_sum_of_two_unique_primes", "check_numbers" ]
3
[ [ "check_numbers", "can_be_sum_of_two_unique_primes" ], [ "check_numbers", "sieve" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9714a5cffd058b1e9c527377a5fca18aaa2d646f
b1969036f3cc38af93cf643e47bf7d76c5498d90
v1.0
instruct
Code_Contests
Code_Contests_5632_I
A popular card game is played with a standard deck of 52 cards, where each card has a suit (hearts, diamonds, clubs, spades) and a value (A, 2, 3, ..., 10, J, Q, K). In this game, players are dealt a specific number of cards, and they need to form the highest possible hand according to predefined rules. The strength of...
from collections import Counter hand_types = [ "High Card", "Pair", "Two Pair", "Three of a Kind", "Straight", "Flush", "Full House" ] def parse_hand(hand): """ Parse the hand to count the occurrences of each value and each suit. """ values = '23456789TJQKA' suits = 'HDCS' ...
def test_parse_hand(): hand = "7H 8H 9H TH JH".split() value_counter, suit_counter, value_counts = parse_hand(hand) assert value_counter == {'7': 1, '8': 1, '9': 1, 'T': 1, 'J': 1} assert suit_counter == {'H': 5} assert value_counts == [1, 1, 1, 1, 1] def test_is_straight(): assert is_straight(...
[ { "docstring": "Parse the hand to count the occurrences of each value and each suit. ", "function_declaration": "def parse_hand(hand):", "function_name": "parse_hand", "parameter_list": "(hand)" }, { "docstring": null, "function_declaration": "def is_straight(hand):", "function_name"...
[ 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\n\ndef get_best_hand_type(cards):\n # Helper functions\n def is_flush(suits):\n return len(set(suits)) == 1\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005632", "row_id": 5632, "seed_ids": "[7720]" }
0.632897
Code_Contests_5632
I
[ "parse_hand", "is_straight", "determine_hand_type", "find_best_hand" ]
4
[ [ "determine_hand_type", "is_straight" ], [ "determine_hand_type", "parse_hand" ], [ "find_best_hand", "determine_hand_type" ] ]
3
[]
false
[]
false
pytest
false
[]
true
6a928df099fcdfad11ccf9c559c315e36bfd002c
2f28246a99db601b3cb4c1174b07c6ae93be2c32
v1.0
instruct
Code_Contests
Code_Contests_5659_I
You are given a list of distinct integers and you need to determine if the list can be sorted in strictly increasing order by performing a series of operations. In each operation, you can select exactly two integers and swap their values. The list is considered "sortable" if you can reach a state where each subsequen...
def can_be_sorted(arr): """ Determines if the list can be sorted in strictly increasing order by performing a series of swaps. Args: arr: list of distinct integers Returns: str: "YES" if the list can be sorted, otherwise "NO". """ # A list of distinct integers can always be sor...
from solution import solve def test_example_1(): assert solve(5, [4, 1, 3, 2, 5]) == "YES" def test_example_2(): assert solve(4, [4, 3, 2, 1]) == "YES" def test_sorted_list(): assert solve(3, [1, 2, 3]) == "YES" def test_reverse_sorted_list(): assert solve(3, [3, 2, 1]) == "YES" def test_single_ele...
[ { "docstring": "Determines if the list can be sorted in strictly increasing order by performing a series of swaps.\n\nArgs:\narr: list of distinct integers\n\nReturns:\nstr: \"YES\" if the list can be sorted, otherwise \"NO\".", "function_declaration": "def can_be_sorted(arr):", "function_name": "can_be...
[ 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_sortable(lst):\n \"\"\"\n Determines if the list can be sorted in strictly increasing order by performing a series of swaps.\n\n :param lst...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005659", "row_id": 5659, "seed_ids": "[1106]" }
0.676706
Code_Contests_5659
I
[ "can_be_sorted", "solve" ]
2
[ [ "solve", "can_be_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8e11dd8148a165363ecabdd5fe30d82aa6c82676
564284a8185cc2fd1a30bdd07a76a46791c4faff
v1.0
instruct
Code_Contests
Code_Contests_5702_I
Dr. Lyons: Mark, do you know about prime numbers? Mark: Yes, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Dr. Lyons: Exactly. Do you think you could write a program that finds all prime numbers between two given integers? Mark: Certainly. Please provide me ...
def sieve_of_eratosthenes(max_num): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. prime = [True for _ in range(max_num + 1)] p = 2 while p * p <= max_num: # If prime[p] is not ch...
from solution import find_primes_between def test_prime_range_with_primes(): assert find_primes_between(10, 30) == [11, 13, 17, 19, 23, 29] def test_prime_range_without_primes(): assert find_primes_between(14, 16) == ["None"] def test_prime_range_single_prime(): assert find_primes_between(29, 29) == [29]...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def find_primes_between(a, b):", "function_name": "find_primes_between", "p...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_numbers_in_range(a, b):\n \"\"\"\n Finds all prime numbers between a and b inclusive, using the Sieve of Eratosthenes algorithm.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005702", "row_id": 5702, "seed_ids": "[13003]" }
0.627647
Code_Contests_5702
I
[ "sieve_of_eratosthenes", "find_primes_between" ]
2
[ [ "find_primes_between", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
de89b8dda845daca297c8fe76bb6b4685e86a463
445e39814d1ab5c638ad1a7404d0cb7a5050c4a4
v1.0
instruct
Code_Contests
Code_Contests_5721_I
A company has a network of computers. Each computer can directly communicate with a set of other computers, and the communication is bi-directional. The company wants to ensure that information can be spread from one specific computer to all other computers through this network. You need to write a program to determine...
def is_network_connected(n, m, connections): from collections import deque, defaultdict if n == 1: return True graph = defaultdict(list) for u, v in connections: graph[u].append(v) graph[v].append(u) visited = set() queue = deque([1]) visited.add(1) wh...
from solution import main def test_example_case(): input_string = "3 2\n1 2\n2 3\n4 2\n1 2\n3 4\n5 0\n0\n" expected_output = ["YES", "NO", "NO"] assert main(input_string) == expected_output def test_single_computer_case(): input_string = "1 0\n0\n" expected_output = ["YES"] assert main(input_s...
[ { "docstring": null, "function_declaration": "def is_network_connected(n, m, connections):", "function_name": "is_network_connected", "parameter_list": "(n, m, connections)" }, { "docstring": null, "function_declaration": "def check_network_connectivity(datasets):", "function_name": ...
[ 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 can_inform_all_computers(n, m, connections):\n \"\"\"\n Determines if information can be spread from one specific computer\n to all other comp...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005721", "row_id": 5721, "seed_ids": "[8939]" }
0.596098
Code_Contests_5721
I
[ "is_network_connected", "check_network_connectivity", "parse_input", "main" ]
4
[ [ "check_network_connectivity", "is_network_connected" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
5125329def18bbec72bd2a42c7d8c57acec1915f
1b1b3a60e6fdfb7145d0307077cf940ce4cf7964
v1.0
instruct
Code_Contests
Code_Contests_5769_I
Ben is a talented software engineer who loves everything about numbers. One day, he was exploring different properties of numbers and discovered an interesting property about sequences of consecutive integers. He defined a sequence of numbers from 1 to n (inclusive) and wanted to calculate the sum of squared difference...
def sum_of_squared_differences(n): """ Given an integer n, calculates the sum of squared differences between every two elements in the sequence from 1 to n (inclusive). """ total_sum = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): total_sum += (i - j) ** 2 re...
from solution import sum_of_squared_differences, compute_sum_of_squared_differences def test_sum_of_squared_differences(): assert sum_of_squared_differences(3) == 6 assert sum_of_squared_differences(4) == 20 assert sum_of_squared_differences(5) == 50 assert sum_of_squared_differences(1) == 0 assert...
[ { "docstring": "Given an integer n, calculates the sum of squared differences \nbetween every two elements in the sequence from 1 to n (inclusive).", "function_declaration": "def sum_of_squared_differences(n):", "function_name": "sum_of_squared_differences", "parameter_list": "(n)" }, { "doc...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_squared_differences(n):\n \"\"\"\n Given an integer n, calculates the sum of squared differences \n between every two elements in the s...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005769", "row_id": 5769, "seed_ids": "[9439]" }
0.702851
Code_Contests_5769
I
[ "sum_of_squared_differences", "compute_sum_of_squared_differences", "process_input" ]
3
[ [ "compute_sum_of_squared_differences", "sum_of_squared_differences" ], [ "process_input", "compute_sum_of_squared_differences" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
7ddb44a5674d67c9ddf82438608685d80a81dea3
778555662efe76a10338b2a547153bb38b770250
v1.0
instruct
Code_Contests
Code_Contests_5798_I
Write a function that determines the height of a binary tree. The height of a binary tree is the number of edges between the tree's root and its furthest leaf. You will need to implement a helper function to build the tree from a list of tuples representing the nodes and their respective left and right children. The ...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def build_tree(node_list): if not node_list: return None nodes = {} for value, left, right in node_list: if value not in nodes: ...
from solution import height_of_binary_tree def test_single_node_tree(): # Tree: 1 n = 1 nodes = [(1, -1, -1)] assert height_of_binary_tree(n, nodes) == 0 def test_empty_tree(): # Tree: (empty) n = 0 nodes = [] assert height_of_binary_tree(n, nodes) == -1 def test_three_level_tree(): ...
[]
[ 0, 0, 0, 1, 0 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00005798", "row_id": 5798, "seed_ids": "[5496]" }
0.637024
Code_Contests_5798
I
[ "build_tree", "height_of_binary_tree" ]
2
[ [ "height_of_binary_tree", "build_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
c3262da93a622e2c4a8dbd2aa0507c382e909524
a0d3caa4783c9ea7781580d3601ce8b7c2f88cbc
v1.0
instruct
Code_Contests
Code_Contests_5851_I
Given an array of integers, you are tasked with handling two types of queries: 1. MAX l r — find the maximum value in the subarray from index l to r (inclusive). 2. UPDATE x y — update the element at index x to y. After performing the specified queries, produce the results for each MAX query. Input The first li...
def preprocess_log(n): log = [0] * (n + 1) for i in range(2, n + 1): log[i] = log[i // 2] + 1 return log def preprocess_table(arr, n): log = preprocess_log(n) k = log[n] + 1 st = [[0] * k for _ in range(n)] for i in range(n): st[i][0] = arr[i] j = 1 while (1 <<...
from solution import main def test_example_case(): assert main('5 4\n3 1 4 1 5\n1 1 3\n2 2 6\n1 1 3\n2 5 2\n') == '4\n6' def test_single_element_array(): assert main('1 1\n5\n1 1 1\n') == '5' def test_update_only(): assert main('3 2\n1 2 3\n2 1 10\n2 2 20\n') == '' def test_maximum_only(): assert ma...
[ { "docstring": null, "function_declaration": "def preprocess_log(n):", "function_name": "preprocess_log", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def preprocess_table(arr, n):", "function_name": "preprocess_table", "parameter_list": "(arr, n)" }...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "class SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.tree = [0] * (2 * self.n)\n self.build(data)\n\n def ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005851", "row_id": 5851, "seed_ids": "[6521]" }
0.762818
Code_Contests_5851
I
[ "preprocess_log", "preprocess_table", "range_max_query", "process_queries", "main" ]
5
[ [ "preprocess_table", "preprocess_log" ], [ "process_queries", "preprocess_table" ], [ "process_queries", "range_max_query" ] ]
3
[ "process_queries" ]
false
[]
false
pytest
true
[]
true
823140d7f13b91627839ce8369d691aec1afc9b8
e344c4323309a2e45693055a921c6f090bd513f3
v1.0
instruct
Code_Contests
Code_Contests_5868_I
On a grid of size n x m, you start from the top-left corner and want to reach the bottom-right corner. You can only move either right or down. Your task is to calculate the number of distinct paths you can take to reach the destination. INPUT: The first line contains the number of test cases T, followed by T lines, e...
from math import comb def num_distinct_paths(n, m): """ Returns the number of distinct paths from top-left to bottom-right on an n x m grid moving only right or down. """ return comb(n + m - 2, n - 1) def calculate_paths(test_cases): results = [] for n, m in test_cases: results.ap...
from solution import num_distinct_paths, calculate_paths, parse_input def test_num_distinct_paths(): assert num_distinct_paths(2, 2) == 2 assert num_distinct_paths(3, 3) == 6 assert num_distinct_paths(1, 1) == 1 assert num_distinct_paths(4, 5) == 35 def test_calculate_paths(): assert calculate_pat...
[ { "docstring": "Returns the number of distinct paths from top-left to bottom-right \non an n x m grid moving only right or down.", "function_declaration": "def num_distinct_paths(n, m):", "function_name": "num_distinct_paths", "parameter_list": "(n, m)" }, { "docstring": null, "function_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def distinct_paths(n, m):\n \"\"\"\n Calculates the number of distinct paths in a n x m grid from the top-left to the bottom-right corner\n moving...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005868", "row_id": 5868, "seed_ids": "[10794]" }
0.788466
Code_Contests_5868
I
[ "num_distinct_paths", "calculate_paths", "parse_input" ]
3
[ [ "calculate_paths", "num_distinct_paths" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c819a612cb89f51f83c0a1118691dfa008c91908
b35ccae8f558d81a1bc40aeaa6d49bc3264a7387
v1.0
instruct
Code_Contests
Code_Contests_5885_I
Given an integer N, determine if it's possible to represent it as a sum of two prime numbers. If it is possible, print "YES", otherwise print "NO". Input First line of the input contains an integer T denoting number of test cases. For each test case, there is a single line containing an integer N. Output For each ...
def sieve(n): """ Generate a list of prime numbers up to `n`. """ is_prime = [True] * (n + 1) p = 2 while (p * p <= n): if (is_prime[p] == True): for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 prime_numbers = [] for p in range(2, n...
from solution import process_input def test_single_case_yes(): T = 1 cases = [34] assert process_input(T, cases) == ["YES"] def test_single_case_no(): T = 1 cases = [17] assert process_input(T, cases) == ["NO"] def test_multiple_cases(): T = 2 cases = [34, 17] assert process_input...
[ { "docstring": "Generate a list of prime numbers up to `n`.", "function_declaration": "def sieve(n):", "function_name": "sieve", "parameter_list": "(n)" }, { "docstring": "Check if the given number N can be represented as a sum of two prime numbers.", "function_declaration": "def can_be_...
[ 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 if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return Fal...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00005885", "row_id": 5885, "seed_ids": "[9896]" }
0.693253
Code_Contests_5885
I
[ "sieve", "can_be_sum_of_two_primes", "process_input", "read_input", "main" ]
5
[ [ "process_input", "can_be_sum_of_two_primes" ], [ "process_input", "sieve" ] ]
2
[ "process_input", "read_input" ]
false
[]
false
pytest
true
[]
true
675599e868f5c97bf819bc1d7c5abc9f7f982959
2ac439ffb4d96f7e934f14e6cdf706825eae0f79
v1.0
instruct
Code_Contests
Code_Contests_5956_I
You are provided with an n x n matrix filled with unique integers from 1 to n^2 arranged in some order. The task is to rotate the matrix 90 degrees clockwise k times. Here, k is an integer (0 ≤ k ≤ 10^9). Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. For each test case: -...
def rotate_matrix_90_clockwise(matrix): """ Rotate the given n x n matrix 90 degrees clockwise. """ n = len(matrix) new_matrix = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): new_matrix[j][n - i - 1] = matrix[i][j] return new_matrix def rotate_matrix_...
from solution import rotate_matrix_90_clockwise, rotate_matrix_k_times, process_test_case def test_rotate_90_clockwise(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] rotated = rotate_matrix_90_clockwise(matrix) expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3...
[ { "docstring": "Rotate the given n x n matrix 90 degrees clockwise.", "function_declaration": "def rotate_matrix_90_clockwise(matrix):", "function_name": "rotate_matrix_90_clockwise", "parameter_list": "(matrix)" }, { "docstring": "Rotate the given n x n matrix k times 90 degrees clockwise."...
[ 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 rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a given matrix 90 degrees clockwise.\n\n Parameters:\n matrix (List[List[int]]): The...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00005956", "row_id": 5956, "seed_ids": "[13042]" }
0.649427
Code_Contests_5956
I
[ "rotate_matrix_90_clockwise", "rotate_matrix_k_times", "process_test_case" ]
3
[ [ "process_test_case", "rotate_matrix_k_times" ], [ "rotate_matrix_k_times", "rotate_matrix_90_clockwise" ] ]
2
[ "process_test_case" ]
false
[]
false
pytest
true
[]
true
f4074e46c7b2e2573172db36be05037e976a82a3
47da81afa2e2197e7a234163422cfda5fbec3f0a
v1.0
instruct
Code_Contests
Code_Contests_5961_I
Maurice loves prime numbers. He came up with a function f(x) which is defined as the sum of all positive integers less than or equal to x. However, Maurice only wants the sum to include prime numbers. Your task is to help Maurice find the sum f(x) for a given integer x. ### Input - The first line contains a single i...
def is_prime(n): """ Returns True if the number is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, prime_sum, solve_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(29) == True assert is_prime(30) == False def test_prime_sum(): assert prime_sum(10) == 17...
[ { "docstring": "Returns True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Computes the sum of all prime numbers less than or equal to x.", "function_declaration": "def prime_...
[ 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": "00005961", "row_id": 5961, "seed_ids": "[1835]" }
0.630921
Code_Contests_5961
I
[ "is_prime", "prime_sum", "solve_primes" ]
3
[ [ "prime_sum", "is_prime" ], [ "solve_primes", "prime_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
80d5975d9b800c32d242a87cf26618c462f6fed8
03c7fa60e748029e21ee8768147a59484006c1b1
v1.0
instruct
Code_Contests
Code_Contests_5971_I
In a faraway kingdom, there is a game played with magical stones. Each magical stone has a unique power value associated with it. When two stones are combined, they can create a new stone with a power value that is the sum of the two original stones' power values. However, there's a twist: only stones with power values...
import math def is_prime(n): """ Returns True if n is a prime number, False otherwise """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import is_prime, min_combination_power_value, main def test_is_prime(): 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 is_prime(11) assert not is_prime(15) def tes...
[ { "docstring": "Returns True if n is a prime number, False otherwise ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the minimum possible power value of a combined stone,\nor \"IMPOSSIBLE\" if no valid combination...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\" Returns True if n is a prime number, False otherwise \"\"\"\n if n <= 1:\n return False\n if n <= ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005971", "row_id": 5971, "seed_ids": "[5929]" }
0.572712
Code_Contests_5971
I
[ "is_prime", "min_combination_power_value", "solve", "main" ]
4
[ [ "min_combination_power_value", "is_prime" ], [ "solve", "min_combination_power_value" ] ]
2
[]
false
[]
false
pytest
true
[]
true
52fc8dd388357672bef3eba2f8f18cc84ba1025e
80b3c7ab38a0d916352d533473613ec085d1c048
v1.0
instruct
Code_Contests
Code_Contests_5977_I
Peter is fond of magic squares. A magic square is a grid where the sum of elements in each row, each column, and the two diagonals are equal. Peter has a special 3x3 magic square where the numbers 1 to 9 are used exactly once. However, some digits have been erased from the magic square. Can you help Peter reconstruct ...
import itertools def is_magic(square): magic_sum = 15 # Every row, column, and diagonal must sum to 15 in a 3x3 magic square where numbers 1-9 are used. rows = square cols = [[square[row][col] for row in range(3)] for col in range(3)] diags = [[square[i][i] for i in range(3)], [square[i][2-i] for i in...
from solution import reconstruct_magic_square def test_reconstruct_magic_square(): input_square = [ [8, 0, 0], [0, 5, 0], [0, 0, 2] ] expected_output = [ [8, 1, 6], [3, 5, 7], [4, 9, 2] ] assert reconstruct_magic_square(input_square) == expected_outpu...
[ { "docstring": null, "function_declaration": "def is_magic(square):", "function_name": "is_magic", "parameter_list": "(square)" }, { "docstring": null, "function_declaration": "def reconstruct_magic_square(square):", "function_name": "reconstruct_magic_square", "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": "import itertools\n\ndef is_magic(square):\n magic_sum = 15 # Every row, column, and diagonal must sum to 15 in a 3x3 magic square where numbers 1-9 are...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00005977", "row_id": 5977, "seed_ids": "[5957]" }
0.623989
Code_Contests_5977
I
[ "is_magic", "reconstruct_magic_square" ]
2
[ [ "reconstruct_magic_square", "is_magic" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69d97bce83c6b61009a50bc66e2692319d54f6b0
46446bbbdc8208496c24efd1572b392006ab5965
v1.0
instruct
Code_Contests
Code_Contests_5984_I
You are tasked with developing a seating arrangement algorithm for a circular dining table at a party. Each guest has a preference for who they would like to sit next to and who they do not want to sit next to. Given these preferences, your algorithm should determine if it's possible to arrange the guests in such a way...
from itertools import permutations def is_valid_arrangement(arrangement, preferences, A): n = len(arrangement) satisfaction_count = 0 for g1, g2, sign in preferences: g1_index = arrangement.index(g1) g2_index = arrangement.index(g2) g1_next = arrangement[(g1_index + 1) % n] ...
import pytest from solution import process_input, can_seat_guests, is_valid_arrangement def test_is_valid_arrangement(): arrangement = [1, 2, 3, 4] preferences = [(1, 2, '+'), (2, 3, '+'), (3, 4, '+'), (4, 1, '-')] A = 3 assert is_valid_arrangement(arrangement, preferences, A) == True arrangement ...
[ { "docstring": null, "function_declaration": "def is_valid_arrangement(arrangement, preferences, A):", "function_name": "is_valid_arrangement", "parameter_list": "(arrangement, preferences, A)" }, { "docstring": null, "function_declaration": "def can_seat_guests(num_guests, preferences, ...
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef satisfies_preferences(arrangement, preferences, A):\n count = 0\n n = len(arrangement)\n for pref in preferences:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00005984", "row_id": 5984, "seed_ids": "[2077]" }
0.629697
Code_Contests_5984
I
[ "is_valid_arrangement", "can_seat_guests", "process_input" ]
3
[ [ "can_seat_guests", "is_valid_arrangement" ], [ "process_input", "can_seat_guests" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
e1a0d30913280950943790091005c479065db5ed
d4ed231120f4fbe0686321f51824316b17d0088f
v1.0
instruct
Code_Contests
Code_Contests_6027_I
Carmen is organizing her collection of digital photographs, and she wants them to be properly arranged in a visually appealing way. Each photograph is represented by a rectangle in a 2D grid. Carmen would like to form the largest possible square subgrid where all cells are covered by these rectangles without any gaps o...
def largest_square(matrix): if not matrix: return 0 m, n = len(matrix), len(matrix[0]) dp = [[0] * (n + 1) for _ in range(m + 1)] max_side = 0 for i in range(1, m + 1): for j in range(1, n + 1): if matrix[i-1][j-1] == '1': dp[i][j] = min(dp[i-1][j], dp[i...
from solution import largest_square, get_largest_squares, process_input_output def test_largest_square_1(): matrix = [ '11000', '11000', '11100', '00000' ] assert largest_square(matrix) == 2 def test_largest_square_2(): matrix = [ '111', '111', '...
[ { "docstring": null, "function_declaration": "def largest_square(matrix):", "function_name": "largest_square", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def get_largest_squares(test_cases):", "function_name": "get_largest_squares", "parameter_l...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_square_side_length(t, test_cases):\n results = []\n \n for case in test_cases:\n m, n, grid = case\n dp = [[0] * (n + 1)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006027", "row_id": 6027, "seed_ids": "[2109]" }
0.742142
Code_Contests_6027
I
[ "largest_square", "get_largest_squares", "process_input_output" ]
3
[ [ "get_largest_squares", "largest_square" ], [ "process_input_output", "get_largest_squares" ] ]
2
[ "process_input_output" ]
false
[]
false
pytest
true
[]
true
d6a01efe0d14f88eb949dded967ba3582bf1bdac
d91afb97d61b29c4f8c8a3967112c131032e872f
v1.0
instruct
Code_Contests
Code_Contests_6041_I
Problem description You are given a task to handle data encryption and decryption for secure communications. The encryption method uses a basic Caesar Cipher, where each letter in the plaintext is shifted a certain number of places down or up the alphabet. For instance, with a shift of 1, 'A' would be encrypted to 'B'...
def caesar_cipher_encrypt(text, shift): """ Encrypts the given text using Caesar Cipher with the given shift. """ result = [] for char in text: if char.isalpha(): shift_amount = shift % 26 if char.islower(): start = ord('a') result.appe...
def test_caesar_cipher_encrypt(): assert caesar_cipher_encrypt('HELLO', 3) == 'KHOOR' assert caesar_cipher_encrypt('WORLD', 2) == 'YQTNF' assert caesar_cipher_encrypt('ABC', 1) == 'BCD' assert caesar_cipher_encrypt('XYZ', 2) == 'ZAB' assert caesar_cipher_encrypt('abc', 3) == 'def' assert caesar_...
[ { "docstring": "Encrypts the given text using Caesar Cipher with the given shift.", "function_declaration": "def caesar_cipher_encrypt(text, shift):", "function_name": "caesar_cipher_encrypt", "parameter_list": "(text, shift)" }, { "docstring": "Decrypts the given text using Caesar Cipher wi...
[ 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 caesar_cipher_encrypt(text, shift):\n \"\"\"\n Encrypts the given text using Caesar Cipher with the given shift.\n \"\"\"\n encrypted_text ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006041", "row_id": 6041, "seed_ids": "[12080]" }
0.600637
Code_Contests_6041
I
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt", "encrypt_and_decrypt_cases" ]
3
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ], [ "encrypt_and_decrypt_cases", "caesar_cipher_decrypt" ], [ "encrypt_and_decrypt_cases", "caesar_cipher_encrypt" ] ]
3
[]
false
[]
false
pytest
false
[]
true
9d0314efe46bfd1056113e85af03992d1ebb6fa3
5f668cd1691855f99c35109bb9b77ddb105def63