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_29182_I | Given two strings, determine if one string is a subsequence of the other. A subsequence is a sequence derived from another sequence by deleting some or no elements, without changing the order of the remaining elements.
Input
The input consists of two lines. Each line contains a string of characters 'A'-'Z' between 1 ... | def is_subsequence(s1, s2):
"""
Determine if s1 is a subsequence of s2.
"""
it = iter(s2)
return all(char in it for char in s1)
def check_subsequence(str1, str2):
"""
Returns "Yes" if str1 is a subsequence of str2, otherwise "No".
"""
if is_subsequence(str1, str2):
return "Y... | from solution import check_subsequence
def test_positive_case():
assert check_subsequence("ACE", "ABCDE") == "Yes"
def test_negative_case():
assert check_subsequence("HELLO", "WORLD") == "No"
def test_full_match():
assert check_subsequence("ABC", "ABC") == "Yes"
def test_subsequence_at_beginning():
... | [
{
"docstring": "Determine if s1 is a subsequence of s2.",
"function_declaration": "def is_subsequence(s1, s2):",
"function_name": "is_subsequence",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Returns \"Yes\" if str1 is a subsequence of str2, otherwise \"No\".",
"function_declaration"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_subsequence(s1, s2):\n \"\"\"\n Determine if s1 is a subsequence of s2.\n \n Parameters:\n s1 (str): First string.\n s2 (str): Sec... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029182",
"row_id": 29182,
"seed_ids": "[6918]"
} | 0.74296 | Code_Contests_29182 | I | [
"is_subsequence",
"check_subsequence"
] | 2 | [
[
"check_subsequence",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 61341649d69535c886be083ce5807d65e8cfa0c2 | c182b5d5065a7b4fed75e39f81d1afb2a2c22984 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29189_I | In a small kingdom, there is a magical forest inhabited by n fairies. Each fairy has a unique identifier ranging from 1 to n and can travel between different locations in the forest. However, the forest is represented as a weighted undirected graph with V vertices and E edges. The vertices represent distinct locations ... | import heapq
import sys
def dijkstra(start, v, graph):
"""
Implementation of Dijkstra's algorithm to find the shortest path in a graph.
"""
dist = [float('inf')] * (v + 1)
dist[start] = 0
priority_queue = [(0, start)]
heapq.heapify(priority_queue)
while priority_queue:
curr... | from solution import find_travel_times
def example_test_case_1():
num_fairies = 2
num_vertices = 4
num_edges = 4
destination = 3
edges = [
(1, 2, 5),
(1, 3, 10),
(2, 3, 2),
(3, 4, 1)
]
fairy_locations = [1, 4]
expected_output = ["7", "2"]
assert ... | [
{
"docstring": "Implementation of Dijkstra's algorithm to find the shortest path in a graph.",
"function_declaration": "def dijkstra(start, v, graph):",
"function_name": "dijkstra",
"parameter_list": "(start, v, graph)"
},
{
"docstring": "Find the shortest travel times for each fairy from th... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\n\ndef dijkstra(V, edges, start):\n graph = [[] for _ in range(V + 1)]\n for u, v, w in edges:\n graph[u].append((v, ... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00029189",
"row_id": 29189,
"seed_ids": "[8210]"
} | 0.673413 | Code_Contests_29189 | I | [
"dijkstra",
"find_travel_times",
"process_input"
] | 3 | [
[
"find_travel_times",
"dijkstra"
],
[
"process_input",
"find_travel_times"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | ac7eee896cf36383fb8400d8269130d6f490d11f | d0f3daf4d1a87f08b79e2912567c920f2dafb84f | |||
v1.0 | instruct | Code_Contests | Code_Contests_29224_I | Wanda is fascinated by prime numbers and enjoys finding them in various ranges. She has invented a new challenge for herself: finding sums of prime numbers in dynamic ranges.
Given a large array `arr` of length `N` filled with integers, you will need to handle multiple queries. Each query is defined by two integers, `... | def is_prime(num):
"""
Helper function to determine if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
retu... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(13) == True
assert is_prime(17) == True
assert is_prime(18) == False
def test_preprocess_primes():
arr = [2,... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Preprocess primes in the array and their prefix sums.",
"function_declaration": "def preprocess_pri... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n retu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029224",
"row_id": 29224,
"seed_ids": "[8333]"
} | 0.623917 | Code_Contests_29224 | I | [
"is_prime",
"preprocess_primes",
"query_prime_sum",
"prime_sum_in_ranges"
] | 4 | [
[
"preprocess_primes",
"is_prime"
],
[
"prime_sum_in_ranges",
"preprocess_primes"
],
[
"prime_sum_in_ranges",
"query_prime_sum"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | f8a6d9f47697f5c93738de10e483c3bf244363b6 | cef377de73006a5c0f9155272170d1a0818c96cb | |||
v1.0 | instruct | Code_Contests | Code_Contests_29297_I | A line in a 2D plane is represented by the equation ax + by + c = 0, where a, b, and c are integers. Given N lines, the aim is to determine the number of points (x, y) where at least two lines intersect. The output should be the count of these distinct intersection points.
Input
The input is given in the following fo... | def gcd(x, y):
while y:
x, y = y, x % y
return x
def intersection_count(N, lines):
intersection_points = set()
for i in range(N):
for j in range(i + 1, N):
a1, b1, c1 = lines[i]
a2, b2, c2 = lines[j]
det = a1 * b2 - a2 * b1
i... | from solution import intersection_count
def test_intersection_count_case1():
N = 3
lines = [
(1, -1, -1),
(2, -2, -2),
(1, 0, -1)
]
assert intersection_count(N, lines) == 1
def test_intersection_count_case2():
N = 4
lines = [
(1, 2, -3),
(2, -1, 4),
... | [
{
"docstring": null,
"function_declaration": "def gcd(x, y):",
"function_name": "gcd",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def intersection_count(N, lines):",
"function_name": "intersection_count",
"parameter_list": "(N, lines)"
}
] | [
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 itertools import combinations\n\ndef intersection_point(line1, line2):\n \"\"\"\n Returns intersection point of two lines if they are not parall... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029297",
"row_id": 29297,
"seed_ids": "[4778]"
} | 0.692044 | Code_Contests_29297 | I | [
"gcd",
"intersection_count"
] | 2 | [
[
"intersection_count",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1dcf579a71eed29af431c57057f0069e827049e6 | a7ba8391ac006d8e65bd8cd8fbd849539e33525e | |||
v1.0 | instruct | Code_Contests | Code_Contests_29322_I | A software company wants to analyze the performance and reliability of their network of servers. They have n servers, labeled from 1 to n, and they log the connections between these servers. Each connection is bi-directional and is represented by a tuple (u, v) indicating a connection between server u and server v. The... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if xroot != yroot:
if rank[xroot] > rank[yroot]:
parent[yroot] ... | from solution import min_connections_to_fully_connect
def test_min_connections_already_connected():
assert min_connections_to_fully_connect(5, [(1, 2), (2, 3), (3, 4), (4, 5)]) == 0
def test_min_connections_two_components():
assert min_connections_to_fully_connect(4, [(1, 2), (3, 4)]) == 1
def test_min_conne... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_connections_to_fully_connect(n, m, connections):\n def find(parent, i):\n if parent[i] == i:\n return i\n parent[i]... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00029322",
"row_id": 29322,
"seed_ids": "[244]"
} | 0.686539 | Code_Contests_29322 | I | [
"find",
"union",
"min_connections_to_fully_connect"
] | 3 | [
[
"min_connections_to_fully_connect",
"find"
],
[
"min_connections_to_fully_connect",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | ed79479f03b01abc52cfeb86377cbf1906fceba1 | f4698ccf09122da5e10111290ae1afaeb6cd0823 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29448_I | You are given a list of n distinct integers representing points on a 1-dimensional number line, and a set of k intervals. Each interval [a, b] represents a segment that can be used to cover any integer within the range [a, b] (inclusive) on the number line.
Your goal is to determine the minimum number of intervals nee... | def min_intervals_to_cover_points(n, k, points, intervals):
"""
Determines the minimum number of intervals needed to cover all given points.
If it's impossible, returns -1.
"""
points.sort()
intervals.sort()
covered = 0
idx = 0
result = 0
while covered < n:
best... | from solution import min_intervals_to_cover_points
def test_example1():
points = [1, 2, 3, 4, 5]
intervals = [(1, 3), (2, 4), (3, 5)]
assert min_intervals_to_cover_points(5, 3, points, intervals) == 2
def test_example2():
points = [1, 3, 5, 7]
intervals = [(1, 2), (6, 8)]
assert min_intervals_... | [
{
"docstring": "Determines the minimum number of intervals needed to cover all given points.\nIf it's impossible, returns -1.",
"function_declaration": "def min_intervals_to_cover_points(n, k, points, intervals):",
"function_name": "min_intervals_to_cover_points",
"parameter_list": "(n, k, points, i... | [
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 min_intervals_to_cover_points(n, k, points, intervals):\n \"\"\"\n Determines the minimum number of intervals needed to cover all given points.\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029448",
"row_id": 29448,
"seed_ids": "[10262]"
} | 0.716403 | Code_Contests_29448 | I | [
"min_intervals_to_cover_points",
"min_intervals_to_cover_points_from_input"
] | 2 | [
[
"min_intervals_to_cover_points_from_input",
"min_intervals_to_cover_points"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ea5299b96b4cee309ebc74931c9b3c97a4ec34f | 2e9905dfa496d5e9e13a2d4192b45be513750070 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29465_I | **Problem Description:**
You and your friend Alex are organizing a marathon event. On the marathon route, there are several water stations where volunteers provide water to the runners at specific intervals. You want to determine the least time at which all the water stations will be simultaneously replenished with wa... | import math
from functools import reduce
MOD = 1000000007
def lcm(a, b):
return (a * b) // math.gcd(a, b)
def lcm_multiple(numbers):
return reduce(lambda x, y: lcm(x, y) % MOD, numbers, 1)
def marathon_event_replenish_times(T, test_cases):
results = []
for test_case in test_cases:
n = test_c... | from solution import marathon_event_replenish_times
def test_single_interval():
assert marathon_event_replenish_times(1, [[1, 5]]) == [5]
def test_multiple_intervals_same():
assert marathon_event_replenish_times(1, [[3, 5, 5, 5]]) == [5]
def test_multiple_intervals_different():
assert marathon_event_repl... | [
{
"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,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\nMOD = 1000000007\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029465",
"row_id": 29465,
"seed_ids": "[5072]"
} | 0.603588 | Code_Contests_29465 | I | [
"lcm",
"lcm_multiple",
"marathon_event_replenish_times"
] | 3 | [
[
"lcm_multiple",
"lcm"
],
[
"marathon_event_replenish_times",
"lcm_multiple"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d9ca485bc43cfeafe5f10f940e594bbd8d7223a7 | 10ca34aff6f6c068fdc859eeb43ba1d06ff103d4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29476_I | Given an integer n, find the smallest prime number greater than n. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Write a function `next_prime(n)` that takes an integer n as an input and returns the smallest prime number greater than n.
### Input
- An integer ... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def next_prime(n):
candida... | from solution import next_prime
def test_next_prime():
assert next_prime(10) == 11
assert next_prime(17) == 19
assert next_prime(20) == 23
assert next_prime(1) == 2
assert next_prime(2) == 3
assert next_prime(3) == 5
assert next_prime(5) == 7
assert next_prime(1000000) == 1000003 # Lar... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def next_prime(n):",
"function_name": "next_prime",
"parameter_list": "(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": "def is_prime(num):\n \"\"\"Helper function to check if a number is a prime.\"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ret... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029476",
"row_id": 29476,
"seed_ids": "[10096]"
} | 0.636186 | Code_Contests_29476 | I | [
"is_prime",
"next_prime"
] | 2 | [
[
"next_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f8409ed4e34ee08797a1578fc88882006b9315f2 | 87483a99e2b258ec8ccaf6bf7eea3fbf312618f9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29542_I | You are given an array of integers representing the heights of several buildings arranged in a row. The goal is to determine the maximum area of a rectangle formed between the buildings, where the rectangle is confined by the height of the shortest building in the chosen range and spans one or more consecutive building... | def max_area_histogram(heights):
"""
Returns the maximum area of rectangle formed using consecutive buildings.
"""
stack, max_area = [], 0
index = 0
while index < len(heights):
if not stack or heights[index] >= heights[stack[-1]]:
stack.append(index)
index +=... | from solution import max_rectangle_area
def test_max_rectangle_area_example1():
assert max_rectangle_area(6, [2, 1, 5, 6, 2, 3]) == 10
def test_max_rectangle_area_example2():
assert max_rectangle_area(4, [1, 2, 3, 4]) == 6
def test_max_rectangle_area_example3():
assert max_rectangle_area(5, [5, 4, 3, 2, ... | [
{
"docstring": "Returns the maximum area of rectangle formed using consecutive buildings.",
"function_declaration": "def max_area_histogram(heights):",
"function_name": "max_area_histogram",
"parameter_list": "(heights)"
},
{
"docstring": "Wrapper function to read input and return the maximu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_rectangle_area(heights):\n \"\"\"\n Returns the maximum area of a rectangle formed by consecutive buildings using the given heights.\n \"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029542",
"row_id": 29542,
"seed_ids": "[604]"
} | 0.769345 | Code_Contests_29542 | I | [
"max_area_histogram",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_area_histogram"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3db0e8bf9ccc1c13b0559505a9f11a1d02092829 | 762aac331c3ece8819ed28f2d39b8f3a9b663d51 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29543_I | The IT department is auditing access records to identify suspicious activity. They need to analyze a list of n login attempts and filter out invalid ones. A valid login attempt follows these rules:
1. Email addresses must be valid. An email address is considered valid if it contains exactly one "@" symbol and the doma... | import re
def is_valid_email(email):
"""
Checks if an email address is valid based on given criteria.
"""
if email.count("@") != 1:
return False
local_part, domain = email.split("@")
if "." not in domain:
return False
return True
def is_valid_time(time):
"""
... | from solution import filter_valid_logins
def test_single_valid_login():
assert filter_valid_logins(1, ["user@example.com 12:34"]) == ["user@example.com 12:34"]
def test_mixed_valid_and_invalid_logins():
assert filter_valid_logins(3, ["user@example.com 12:34", "invalid-email@domain 12:34", "user2@domain.c 99:9... | [
{
"docstring": "Checks if an email address is valid based on given criteria.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Checks if a time is in the valid HH:MM format where HH is between 00 and 23 a... | [
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": "import re\n\ndef valid_email(email):\n \"\"\"Check if the provided email is valid.\"\"\"\n if email.count('@') != 1:\n return False\n local... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00029543",
"row_id": 29543,
"seed_ids": "[11494]"
} | 0.457514 | Code_Contests_29543 | I | [
"is_valid_email",
"is_valid_time",
"filter_valid_logins"
] | 3 | [
[
"filter_valid_logins",
"is_valid_email"
],
[
"filter_valid_logins",
"is_valid_time"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1272ac7b8a5df68172d8cae8074500459a32d6b5 | ca584cf8365271bafd9baa06aebc775d311ee28f | |||
v1.0 | instruct | Code_Contests | Code_Contests_29585_I | In a faraway land, there is a peculiar kingdom named Arithmopolis where mathematical puzzles are a part of daily life. The kingdom consists of various cities connected in a hierarchical tree structure. Each city is labeled uniquely with integers from 1 to N, and the city 1 is the capital city, i.e., the root of the tre... | def dfs(node, parent, depth, adj, depth_map, parent_map):
depth_map[node] = depth
parent_map[node] = parent
for neighbor in adj[node]:
if neighbor != parent:
dfs(neighbor, node, depth + 1, adj, depth_map, parent_map)
def calculate_lca(u, v, depth_map, parent_map):
if depth_map[u] < ... | def test_total_communication_cost():
trees = [
(7, 3, [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)], [4, 5, 6])
]
assert total_communication_cost(trees, [[4, 5, 6]]) == [10]
trees = [
(5, 2, [(1, 2), (1, 3), (2, 4), (3, 5)], [4, 5])
]
assert total_communication_cost(trees... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, depth, adj, depth_map, parent_map):",
"function_name": "dfs",
"parameter_list": "(node, parent, depth, adj, depth_map, parent_map)"
},
{
"docstring": null,
"function_declaration": "def calculate_lca(u, v, depth_map, pare... | [
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.125 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\nimport itertools\n\ndef bfs_distance(tree, start):\n \"\"\"\n Performs a BFS fro... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00029585",
"row_id": 29585,
"seed_ids": "[10000]"
} | 0.663987 | Code_Contests_29585 | I | [
"dfs",
"calculate_lca",
"shortest_path",
"total_communication_cost",
"solve"
] | 5 | [
[
"shortest_path",
"calculate_lca"
],
[
"solve",
"total_communication_cost"
],
[
"total_communication_cost",
"dfs"
],
[
"total_communication_cost",
"shortest_path"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 5d3d0ec2dba52e4f8b6486d6b92cbbd2889bfcf6 | 1ec2a8544e902292483b1435d0fef179fd6cba3c | |||
v1.0 | instruct | Code_Contests | Code_Contests_29599_I | In a country, there are n roads and m junctions. Each road connects exactly two junctions, and no two roads connect the same pair of junctions. Unfortunately, the roads are one-way, so it is possible that you can travel from junction A to junction B, but not from junction B to junction A.
The government has decided to... | from collections import defaultdict
def find_scc(graph, n):
index = 0
stack = []
low_link = [-1] * (n + 1)
index_map = [-1] * (n + 1)
on_stack = [False] * (n + 1)
sccs = []
def strong_connect(node):
nonlocal index
index_map[node] = index
low_link[node] = index
... | from solution import min_signs
def test_example1():
n, edges = 5, [(1, 2), (2, 3), (3, 4), (4, 5), (1, 5)]
assert min_signs(n, edges) == 1
def test_example2():
n, edges = 6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1), (1, 4)]
assert min_signs(n, edges) == 1
def test_single_junction():
n, edg... | [
{
"docstring": null,
"function_declaration": "def find_scc(graph, n):",
"function_name": "find_scc",
"parameter_list": "(graph, n)"
},
{
"docstring": null,
"function_declaration": "def min_signs(n, edges):",
"function_name": "min_signs",
"parameter_list": "(n, edges)"
},
{
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef minimum_signs_to_install(n, m, roads):\n def bfs(start):\n visited = set()\n queue = deq... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00029599",
"row_id": 29599,
"seed_ids": "[2045]"
} | 0.690895 | Code_Contests_29599 | I | [
"find_scc",
"min_signs"
] | 2 | [
[
"min_signs",
"find_scc"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 34c982976c0c50062af54e16977db9153236a34a | a1fe933cd2cb0644e18ee2da3cf75be54962e8e2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29658_I | A courier is delivering packages in a city with a grid of size n x m. The city can be represented by a grid with n rows and m columns. There are certain cells that represent buildings (blocked cells) where the courier cannot enter. You need to determine the shortest path the courier can take to deliver a package from t... | from collections import deque
def shortest_path(grid):
n = len(grid)
m = len(grid[0])
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'
queue = deque([(0, 0, 0)]) # (row, column, distance)
grid[0][0] = '#' ... | from solution import find_shortest_path
def test_example_1():
n, m = 4, 4
grid_str = [
"....",
"..#.",
"...#",
"#..."
]
assert find_shortest_path(n, m, grid_str) == 6
def test_example_2():
n, m = 3, 3
grid_str = [
".#.",
"###",
".#."
... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid):",
"function_name": "shortest_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path(n, m, grid_str):",
"function_name": "find_shortest_path",
"parameter_list"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path(n, m, grid):\n def is_valid(x, y):\n return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'\n\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029658",
"row_id": 29658,
"seed_ids": "[971]"
} | 0.696739 | Code_Contests_29658 | I | [
"shortest_path",
"find_shortest_path"
] | 2 | [
[
"find_shortest_path",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ca440d42c441e7ae54eabd04622cd9a72dd9cf9 | 9869e2cb2d8586a5af2fbb31c8b76175d406f52b | |||
v1.0 | instruct | Code_Contests | Code_Contests_29719_I | John loves Fibonacci numbers and wants to create a special list based on them. He has a list p of m unique positive integers, and he asked you to find another list q of the same length such that:
- q contains only Fibonacci numbers.
- q contains each Fibonacci number exactly once.
- The sum of the elements in q is as ... | def generate_fibonacci_until(max_value):
fibs = [1, 1]
while True:
next_fib = fibs[-1] + fibs[-2]
if next_fib > max_value:
break
fibs.append(next_fib)
return fibs
def find_closest_fib_subset(p, fibs):
target_sum = sum(p)
m = len(p)
closest_subset = []
cur... | from solution import generate_fibonacci_until, find_closest_fib_subset, find_fib_list
def test_generate_fibonacci_until():
assert generate_fibonacci_until(50) == [1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_find_closest_fib_subset():
p_example = [10, 22, 35, 50]
fibs_example = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55... | [
{
"docstring": null,
"function_declaration": "def generate_fibonacci_until(max_value):",
"function_name": "generate_fibonacci_until",
"parameter_list": "(max_value)"
},
{
"docstring": null,
"function_declaration": "def find_closest_fib_subset(p, fibs):",
"function_name": "find_closes... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_fibonacci_list(m, p):\n def generate_fibonacci_up_to(max_value):\n fibs = [1, 1]\n while True:\n next_fib = fibs[-1] +... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00029719",
"row_id": 29719,
"seed_ids": "[12249]"
} | 0.576209 | Code_Contests_29719 | I | [
"generate_fibonacci_until",
"find_closest_fib_subset",
"find_fib_list",
"main"
] | 4 | [
[
"find_fib_list",
"find_closest_fib_subset"
],
[
"find_fib_list",
"generate_fibonacci_until"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b4715371e5a3c5582cb26af4dcbd045be67cc5c4 | 6ca9885cefdd492233890836066a0603fc8bb142 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29818_I | Consider a new game played on an n x n chessboard with multiple chess pieces. Initially, each piece occupies a distinct cell, and each cell can hold at most one piece. During the game, the pieces are moved according to the following rules:
1. A piece can move to any adjacent cell (up, down, left, or right), but cannot... | def can_first_player_win(t, n, test_cases):
results = []
for case in test_cases:
p = case[0]
positions = case[1:]
if p % 2 == 0:
results.append("NO")
else:
results.append("YES")
return results
# Function to parse input and c... | def test_can_first_player_win():
assert solve(2, 4, ["2 1 1 4 4", "3 1 1 2 2 3 3"]) == ["NO", "YES"]
assert solve(1, 5, ["4 1 1 2 2 3 3 4 4"]) == ["NO"]
assert solve(3, 3, ["1 2 2", "2 1 1 3 3", "4 1 1 2 2 3 3 2 3"]) == ["YES", "NO", "NO"]
assert solve(1, 1, ["1 1 1"]) == ["YES"]
assert solve(2, 6, ... | [
{
"docstring": null,
"function_declaration": "def can_first_player_win(t, n, test_cases):",
"function_name": "can_first_player_win",
"parameter_list": "(t, n, test_cases)"
},
{
"docstring": null,
"function_declaration": "def solve(t, n, cases):",
"function_name": "solve",
"parame... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def has_winning_strategy(t, n, test_cases):\n results = []\n for case in test_cases:\n p = case[0]\n pieces = case[1:]\n board =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029818",
"row_id": 29818,
"seed_ids": "[10350]"
} | 0.72812 | Code_Contests_29818 | I | [
"can_first_player_win",
"solve"
] | 2 | [
[
"solve",
"can_first_player_win"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0189aa135d3a2f42999db86a4af106adaa3f47ff | a79532d391c7758737cedd720a9260b3cd668ca2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29848_I | Alice has recently learned about various sorting algorithms in her computer science class. She is particularly interested in the efficiency of sorting numbers and wonders how many swaps are needed to sort a list of numbers using selection sort.
In selection sort, the smallest element is selected from the unsorted par... | def selection_sort_swaps(arr):
"""
Returns the number of swaps needed to sort the list using selection sort.
"""
n = len(arr)
num_swaps = 0
for i in range(n):
# Find the minimum element in remaining unsorted array
min_index = i
for j in range(i+1, n):
if arr[j... | from solution import count_selection_sort_swaps
def test_example_case():
assert count_selection_sort_swaps(5, [64, 25, 12, 22, 11]) == 3
def test_already_sorted():
assert count_selection_sort_swaps(5, [1, 2, 3, 4, 5]) == 0
def test_reverse_sorted():
assert count_selection_sort_swaps(5, [5, 4, 3, 2, 1]) =... | [
{
"docstring": "Returns the number of swaps needed to sort the list using selection sort.",
"function_declaration": "def selection_sort_swaps(arr):",
"function_name": "selection_sort_swaps",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def count_selection_so... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def selection_sort_swap_count(arr):\n \"\"\"\n Returns the number of swaps required to sort the list using selection sort.\n \"\"\"\n n = len(a... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00029848",
"row_id": 29848,
"seed_ids": "[1983]"
} | 0.650721 | Code_Contests_29848 | I | [
"selection_sort_swaps",
"count_selection_sort_swaps"
] | 2 | [
[
"count_selection_sort_swaps",
"selection_sort_swaps"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 35cb49ff7d3c3a9a3e073f4b456db94ce83f41f7 | e3a88a761c8d3671bb94c1235f2628d5e514dc8e | |||
v1.0 | instruct | Code_Contests | Code_Contests_29865_I | You are given a tree T, which is an undirected graph with N vertices and N-1 edges. Each vertex is numbered from 1 through N, and each edge connects two vertices.
Your task is to determine the maximum distance between any two vertices in T. The distance between two vertices is defined as the number of edges in the sho... | from collections import defaultdict, deque
def find_farthest(node, graph):
visited = set()
queue = deque([(node, 0)])
farthest_node = node
max_distance = 0
while queue:
current_node, distance = queue.popleft()
visited.add(current_node)
for neighbor in graph[cur... | from solution import max_distance_in_tree
def test_example_1():
N = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
assert max_distance_in_tree(N, edges) == 3
def test_example_2():
N = 3
edges = [(1, 2), (2, 3)]
assert max_distance_in_tree(N, edges) == 2
def test_example_3():
N = 6
edges =... | [
{
"docstring": null,
"function_declaration": "def find_farthest(node, graph):",
"function_name": "find_farthest",
"parameter_list": "(node, graph)"
},
{
"docstring": null,
"function_declaration": "def max_distance_in_tree(N, edges):",
"function_name": "max_distance_in_tree",
"par... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nsys.setrecursionlimit(200000)\n\ndef maximum_distance(N, edges):\n from collections import defaultdict, deque\n\n def bfs(start):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00029865",
"row_id": 29865,
"seed_ids": "[4148]"
} | 0.698149 | Code_Contests_29865 | I | [
"find_farthest",
"max_distance_in_tree"
] | 2 | [
[
"max_distance_in_tree",
"find_farthest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 502bff462c27a5a0fb78d73495fc91784e466b97 | b277c1874c051ff438fc8441857cef15932efee1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_29869_I | A binary tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child. Given an integer array `preorder` where `preorder` is the preorder traversal of a binary tree, and an integer array `inorder` where `inorder` is the inorder traversal of the same tree, ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(preorder, inorder):
"""
Builds a binary tree from preorder and inorder traversal lists.
"""
if not preorder or not inorder:
return None... | import pytest
from solution import TreeNode, build_tree, level_order_traversal, construct_and_print_level_order
def test_construct_and_print_level_order_case1():
preorder = [3, 9, 20, 15, 7, 8]
inorder = [9, 3, 15, 20, 7, 8]
expected_output = [3, 9, 20, 15, 7, 8]
assert construct_and_print_level_order(... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00029869",
"row_id": 29869,
"seed_ids": "[12754]"
} | 0.639554 | Code_Contests_29869 | I | [
"build_tree",
"level_order_traversal",
"construct_and_print_level_order"
] | 3 | [
[
"construct_and_print_level_order",
"build_tree"
],
[
"construct_and_print_level_order",
"level_order_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1b7b9fd152ff6ce2d67d6f11cedd5a393c11cfd9 | 2b52ee88822d482750e47d6a826b309992117e0d | |||
v1.0 | instruct | Code_Contests | Code_Contests_29912_I | Problem E: The Lost Treasure Hunt
Mr. Damian is a renowned treasure hunter known for his extraordinary cartographical skills. He has recently discovered a map detailing the locations of several ancient temples scattered across a vast desert. Each temple may or may not contain a piece of a lost treasure. The challenge ... | from collections import deque
def shortest_path_bfs(grid, start, end):
N = len(grid)
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(start[0], start[1], 0)])
visited = set()
visited.add(start)
while queue:
x, y, dist = queue.popleft()
if (x, y) == end:
... | from solution import minimum_time_to_collect_treasure
def test_example_1():
N = 5
temples = [(0, 0, 1), (0, 1, 0), (1, 1, 1), (2, 2, 0), (4, 4, 1)]
sequence = [1, 3, 5]
assert minimum_time_to_collect_treasure(N, temples, sequence) == 8
def test_minimum_travel():
N = 3
temples = [(0, 0, 1), (1,... | [
{
"docstring": null,
"function_declaration": "def shortest_path_bfs(grid, start, end):",
"function_name": "shortest_path_bfs",
"parameter_list": "(grid, start, end)"
},
{
"docstring": null,
"function_declaration": "def minimum_time_to_collect_treasure(N, temples, sequence):",
"functi... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef shortest_path_bfs(grid, start, end):\n N = len(grid)\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n queu... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00029912",
"row_id": 29912,
"seed_ids": "[1558]"
} | 0.663013 | Code_Contests_29912 | I | [
"shortest_path_bfs",
"minimum_time_to_collect_treasure",
"parse_input",
"main"
] | 4 | [
[
"minimum_time_to_collect_treasure",
"shortest_path_bfs"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | ec4ac976e5d646db1b094059f29fa2873ad0d03d | b56cb59126c8941d9597a63b3ad4a6a332283c45 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30019_I | Eva Ecowarrior just embarked on a mission to protect a precious collection of rain forests. Each rain forest is represented as a non-overlapping convex polygon, and Eva is tasked with planting an anti-deforestation beacon in each rain forest to keep them secure.
Eva's drones have a limitation: they can plant a beacon ... | def calculate_centroid_of_polygon(vertices):
"""
Calculate the centroid of a polygon given its vertices.
vertices: list of tuples, where each tuple is an (x, y) coordinate of a vertex.
Returns the centroid of the polygon as a tuple (Cx, Cy).
"""
n = len(vertices)
area = 0
Cx = ... | def test_calculate_centroid_of_polygon_triangle():
vertices = [(0, 0), (4, 0), (2, 3)]
assert calculate_centroid_of_polygon(vertices) == (2.0000, 1.0000)
def test_calculate_centroid_of_polygon_square():
vertices = [(1, 1), (4, 1), (4, 5), (1, 5)]
assert calculate_centroid_of_polygon(vertices) == (2.500... | [
{
"docstring": "Calculate the centroid of a polygon given its vertices.\n\nvertices: list of tuples, where each tuple is an (x, y) coordinate of a vertex.\n\nReturns the centroid of the polygon as a tuple (Cx, Cy).",
"function_declaration": "def calculate_centroid_of_polygon(vertices):",
"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 polygon_centroid(vertices):\n \"\"\"\n Computes the centroid of a polygon given a list of its vertices.\n Each vertex is represented as a tupl... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00030019",
"row_id": 30019,
"seed_ids": "[8346]"
} | 0.490883 | Code_Contests_30019 | I | [
"calculate_centroid_of_polygon",
"find_centroids_of_forests"
] | 2 | [
[
"find_centroids_of_forests",
"calculate_centroid_of_polygon"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 1c6bebaef0fe5bfa5a9b6b9baecadb483cc0a391 | 72d8f636c10ff772fe588909717c20336717166b | |||
v1.0 | instruct | Code_Contests | Code_Contests_30045_I | Problem description
John is a computer scientist who is fascinated with numbers. He recently came across a peculiar problem and needs your expertise to solve it. He has two integers, a and b, and he wants to calculate the sum of all the prime numbers in the range [a, b] inclusive.
A prime number is a natural number g... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def sum_primes_in_range(a, b):
prime_sum =... | from solution import is_prime, sum_primes_in_range, solve_primes_sum
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_sum_primes_in_range():
a... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def sum_primes_in_range(a, b):",
"function_name": "sum_primes_in_range",
"parameter_list": "(a, b)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030045",
"row_id": 30045,
"seed_ids": "[4070]"
} | 0.606007 | Code_Contests_30045 | I | [
"is_prime",
"sum_primes_in_range",
"solve_primes_sum"
] | 3 | [
[
"solve_primes_sum",
"sum_primes_in_range"
],
[
"sum_primes_in_range",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ed714f5813bc2a0d4e89da6b463cf6a45dc6cf18 | 81c76c5b262aee107d45dde583b7b2afefd2f218 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30052_I | Bob is an enthusiast for trains and loves to calculate the total time spent on each of his journeys. He is interested in knowing the actual time spent in transit and the total waiting time during his train travels. Bob's journey consists of multiple train rides with waiting times in between. He wants to calculate the t... | from datetime import datetime, timedelta
def compute_time_difference(start, end):
start_time = datetime.strptime(start, "%H:%M")
end_time = datetime.strptime(end, "%H:%M")
if end_time < start_time:
end_time += timedelta(days=1)
return end_time - start_time
def format_time_difference(diff):
... | from solution import train_schedule
def test_single_test_case():
T = 1
test_cases = [
(3, [("09:00", "11:00"), ("12:00", "14:00"), ("15:00", "17:00")]),
]
result = train_schedule(T, test_cases)
assert result == ["06:00", "02:00"]
def test_multiple_test_cases():
T = 2
test_cases = [... | [
{
"docstring": null,
"function_declaration": "def compute_time_difference(start, end):",
"function_name": "compute_time_difference",
"parameter_list": "(start, end)"
},
{
"docstring": null,
"function_declaration": "def format_time_difference(diff):",
"function_name": "format_time_dif... | [
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 datetime import datetime, timedelta\n\ndef calculate_travel_and_waiting_times(rides):\n def time_diff_in_minutes(start, end):\n start_dt = d... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030052",
"row_id": 30052,
"seed_ids": "[6666]"
} | 0.706461 | Code_Contests_30052 | I | [
"compute_time_difference",
"format_time_difference",
"calc_travel_and_waiting_times",
"train_schedule"
] | 4 | [
[
"calc_travel_and_waiting_times",
"compute_time_difference"
],
[
"calc_travel_and_waiting_times",
"format_time_difference"
],
[
"train_schedule",
"calc_travel_and_waiting_times"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 0e8337c2cd6aa23a391ded944375dcc5438bf947 | 83142c70ff83a7a0ec11276098204aa305e2492b | |||
v1.0 | instruct | Code_Contests | Code_Contests_30079_I | Given an array of integers, write a program to find the longest subsequence such that every two consecutive elements in the subsequence have a common factor greater than 1.
### Input
- The first line of input contains an integer n (2 ≤ n ≤ 1000), the number of elements in the array.
- The second line contains n intege... | from math import gcd
from functools import lru_cache
@lru_cache(None)
def gcd_memo(x, y):
return gcd(x, y)
def find_longest_subsequence(arr):
n = len(arr)
if n == 0:
return 0
dp = [1] * n
for i in range(1, n):
for j in range(i):
if gcd_memo(arr[i], arr[j]) > 1... | from solution import find_longest_subsequence
def test_longest_subsequence_example_1():
assert find_longest_subsequence([4, 8, 15, 16, 23]) == 3
def test_longest_subsequence_example_2():
assert find_longest_subsequence([7, 11, 13, 17]) == 1
def test_longest_subsequence_single_element():
assert find_longe... | [
{
"docstring": null,
"function_declaration": "def gcd_memo(x, y):",
"function_name": "gcd_memo",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def find_longest_subsequence(arr):",
"function_name": "find_longest_subsequence",
"parameter_list": "(arr)"... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef longest_subsequence_with_common_factor(arr):\n n = len(arr)\n dp = [1] * n\n \n for i in range(1, n):\n for j in rang... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00030079",
"row_id": 30079,
"seed_ids": "[11692]"
} | 0.793962 | Code_Contests_30079 | I | [
"gcd_memo",
"find_longest_subsequence",
"main"
] | 3 | [
[
"find_longest_subsequence",
"gcd_memo"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a40d61958fce6ebf6ae891c213dc95d18ccf54c5 | 5993a6d4545c76172ec0ca9e68f9f09e6c943c84 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30140_I | Given is an undirected graph G with N vertices and M edges. A path is defined as a sequence of edges that connects two vertices without revisiting any vertex.
You are given Q queries, where query i asks if there exists a path between Vertex U_i and Vertex V_i (1 \leq U_i, V_i \leq N and U_i ≠ V_i). For each query, pri... | def find_parent(parent, i):
if parent[i] == i:
return i
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
xroot = find_parent(parent, x)
yroot = find_parent(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
... | def test_example_case_1():
input_data = "5 4\n1 2\n2 3\n3 4\n4 5\n3\n1 5\n2 4\n5 1\n"
assert solve(input_data) == "YES\nYES\nYES"
def test_example_case_2():
input_data = "4 2\n1 2\n3 4\n2\n1 3\n4 2\n"
assert solve(input_data) == "NO\nNO"
def test_example_case_3():
input_data = "6 5\n1 2\n2 3\n1 4\... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
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_1 | {
"original_instruction": "",
"prompt_id": "00030140",
"row_id": 30140,
"seed_ids": "[10285]"
} | 0.802573 | Code_Contests_30140 | I | [
"find_parent",
"union",
"is_connected",
"solve"
] | 4 | [
[
"is_connected",
"find_parent"
],
[
"is_connected",
"union"
],
[
"solve",
"is_connected"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | dbeb37980909bf07431f219c6235e7a83c44af3b | eabc57e7876334c10d9825aad5d38cc36ba9ec8c | |||
v1.0 | instruct | Code_Contests | Code_Contests_30152_I | Your task is to write a program that finds the most frequent sum of paths in a binary tree. Given a binary tree, you need to calculate the sum of values on each root-to-leaf path and determine which sum appears the most frequently.
Input:
The first line contains an integer n, representing the number of nodes in the t... | from collections import defaultdict, deque
class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_list):
if not node_list:
return None
nodes = {}
for v, l, r in node_list:
if v not in nodes:
... | def test_basic_case():
n = 5
nodes = [
(1, 2, 3),
(2, 4, -1),
(3, -1, 5),
(4, -1, -1),
(5, -1, -1)
]
assert find_frequent_path_sum(n, nodes) == 7
def test_single_node():
n = 1
nodes = [
(10, -1, -1)
]
assert find_frequent_path_sum(n, n... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, Counter\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n sel... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030152",
"row_id": 30152,
"seed_ids": "[4861]"
} | 0.624482 | Code_Contests_30152 | I | [
"build_tree",
"find_frequent_path_sum"
] | 2 | [
[
"find_frequent_path_sum",
"build_tree"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 39a3a848e99bed0da5c75e2c5cb46b6b0a763d42 | f64555c422221c238e4d7f2da74d4fd84b51b983 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30163_I | problem
You are a software engineer working on optimizing a railway system database. The railway system consists of multiple stations connected by train lines. Each station has multiple tracks, each with a specific travel time. Given a set of stations and tracks, your goal is to determine the minimum time required to ... | import heapq
def dijkstra(n, edges, start, end):
"""
Determines the minimum travel time from station start to station end using Dijkstra's algorithm.
:param n: The number of stations.
:param edges: A list of tuples (u, v, t) representing the tracks between stations u and v with time t.
:param ... | from solution import find_minimum_travel_time
def test_case_1():
assert find_minimum_travel_time(5, 7, [(1, 2, 4), (1, 3, 2), (2, 4, 7), (3, 4, 1), (3, 5, 3), (4, 5, 2), (2, 3, 5)], 1, 5) == 5
def test_case_2():
assert find_minimum_travel_time(3, 3, [(1, 2, 1), (2, 3, 1), (1, 3, 4)], 1, 3) == 2
def test_case... | [
{
"docstring": "Determines the minimum travel time from station start to station end using Dijkstra's algorithm.\n\n:param n: The number of stations.\n:param edges: A list of tuples (u, v, t) representing the tracks between stations u and v with time t.\n:param start: The starting station.\n:param end: The dest... | [
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": "import heapq\n\ndef dijkstra(n, edges, start, end):\n \"\"\"\n Determines the minimum travel time from station start to station end using Dijkstra's ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030163",
"row_id": 30163,
"seed_ids": "[8004]"
} | 0.778418 | Code_Contests_30163 | I | [
"dijkstra",
"find_minimum_travel_time"
] | 2 | [
[
"find_minimum_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b765b3efdad1ddd07672d9eb9157c06c1f41be1 | e01ef8efdef8353ab9444e9acbe5479713e3dfcd | |||
v1.0 | instruct | Code_Contests | Code_Contests_30169_I | A painter has a canvas with a grid of cells, each cell initially colored with either red (R) or blue (B). The painter wants to create a pattern where no two adjacent cells (horizontally or vertically) have the same color. To achieve this, the painter can change the color of a cell from red to blue or from blue to red. ... | def min_color_changes(T, test_cases):
results = []
def calculate_changes(grid, pattern1, pattern2):
changes1 = changes2 = 0
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] != pattern1[i % 2][j % 2]:
changes1 += 1
... | from solution import solve
def test_case_1():
input_data = [
"2",
"3 3",
"RRB", "BRB", "RRB",
"2 2",
"RR", "BB"
]
expected_output = [4, 2]
assert solve(input_data) == expected_output
def test_case_2():
input_data = [
"1",
"2 3",
... | [
{
"docstring": null,
"function_declaration": "def min_color_changes(T, test_cases):",
"function_name": "min_color_changes",
"parameter_list": "(T, test_cases)"
},
{
"docstring": null,
"function_declaration": "def solve(grid_data):",
"function_name": "solve",
"parameter_list": "(g... | [
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 min_color_changes_to_create_pattern(T, test_cases):\n def count_changes(grid, pattern, n, m):\n changes = 0\n for i in range(n):\n ... | trial_gpt4o_6 | {
"original_instruction": "",
"prompt_id": "00030169",
"row_id": 30169,
"seed_ids": "[13120]"
} | 0.753273 | Code_Contests_30169 | I | [
"min_color_changes",
"solve"
] | 2 | [
[
"solve",
"min_color_changes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3902e4da30ea14138fc9f8a7ea2195161af86884 | d459f8398ea221878268fa85a55f5af87419916b | |||
v1.0 | instruct | Code_Contests | Code_Contests_30248_I | Alex is highly interested in number theory, particularly in prime numbers and their interesting properties. One day, he decided to play with the prime factorization of numbers. He wants to determine the sum of the number of prime factors (including multiplicity) for each integer from 1 to a given number M. Alex always ... | def prime_factors_count_up_to_m(M):
"""
Returns a list where the value at index i is the number of prime factors of i.
The returned list covers the range from 1 to M (inclusive).
"""
# Initialize a list for counting prime factors.
factor_counts = [0] * (M + 1)
# Perform a sieve-like app... | import pytest
from solution import main, parse_input, sum_prime_factor_counts, prime_factors_count_up_to_m
def test_prime_factors_count_up_to_m():
assert prime_factors_count_up_to_m(5) == [0, 0, 1, 1, 2, 1]
assert prime_factors_count_up_to_m(10) == [0, 0, 1, 1, 2, 1, 2, 1, 3, 2, 2]
def test_sum_prime_factor_c... | [
{
"docstring": "Returns a list where the value at index i is the number of prime factors of i.\nThe returned list covers the range from 1 to M (inclusive).",
"function_declaration": "def prime_factors_count_up_to_m(M):",
"function_name": "prime_factors_count_up_to_m",
"parameter_list": "(M)"
},
... | [
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 compute_prime_factors_sum_for_range(M):\n \"\"\"\n Computes the sum of the number of prime factors (including multiplicity) for each integer from... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030248",
"row_id": 30248,
"seed_ids": "[6146]"
} | 0.638904 | Code_Contests_30248 | I | [
"prime_factors_count_up_to_m",
"sum_prime_factor_counts",
"parse_input",
"main"
] | 4 | [
[
"sum_prime_factor_counts",
"prime_factors_count_up_to_m"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | b640ce83e4a66b3c916cff5978796ab31ca2b92d | b537088c1bb970224dd160b9a933d3d450099bc2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30255_I | You are given an undirected graph with n nodes and m edges. The nodes are labeled with integers from 1 to n. You need to determine the minimum number of edges you need to add to make the graph fully connected. A graph is fully connected if there is a path between any pair of nodes.
Input
The first line contains one i... | def find_connected_components(n, edges):
from collections import defaultdict
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
visited = [False] * (n + 1)
def dfs(node):
stack = [node]
while stack:
current = stack.pop... | from solution import solve
def test_min_edges_to_connect():
test_cases = [
(4, 2, [(1, 2), (3, 4)]), # Should need 1 edge (connect (2, 3))
(5, 0, []), # Should need 4 edges (to connect 5 isolated nodes)
(7, 9, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 1), (1, 3), ... | [
{
"docstring": null,
"function_declaration": "def find_connected_components(n, edges):",
"function_name": "find_connected_components",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def min_edges_to_connect(n, edges):",
"function_name": "min_edges_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 find_connected_components(n, edges):\n from collections import defaultdict\n graph = defaultdict(list)\n for u, v in edges:\n graph[u].... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030255",
"row_id": 30255,
"seed_ids": "[12520]"
} | 0.781986 | Code_Contests_30255 | I | [
"find_connected_components",
"min_edges_to_connect",
"solve"
] | 3 | [
[
"min_edges_to_connect",
"find_connected_components"
],
[
"solve",
"min_edges_to_connect"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2d8b7c0717b62a1d5c2794eaf7f45d663973413e | 189a25c64c11f5523b466b2189a1d8117cddf9df | |||
v1.0 | instruct | Code_Contests | Code_Contests_30262_I | You are given a grid of size n × m filled with integers. Each integer in the grid represents the elevation of that cell. An elevation change between two adjacent cells (horizontally or vertically) is called a step. A path from the upper-left corner (0, 0) to the bottom-right corner (n-1, m-1) is considered "smooth" if ... | def is_smooth_path(grid, n, m, k):
from collections import deque
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
visited = [[False for _ in range(m)] for _ in range(n)]
queue = deque([(0, 0)])
visited[0][0] = True
while queue:
r, c = queue.popleft()
if r == n-1... | from solution import smooth_path
def test_smooth_path_case1():
n, m, k = 3, 3, 2
elevation_lines = [
"1 2 3",
"4 8 2",
"1 4 7"
]
assert smooth_path(n, m, k, elevation_lines) == "NO"
def test_smooth_path_case2():
n, m, k = 2, 2, 1
elevation_lines = [
"0 1",
... | [
{
"docstring": null,
"function_declaration": "def is_smooth_path(grid, n, m, k):",
"function_name": "is_smooth_path",
"parameter_list": "(grid, n, m, k)"
},
{
"docstring": null,
"function_declaration": "def smooth_path(n, m, k, elevation_lines):",
"function_name": "smooth_path",
... | [
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_smooth_path(n, m, k, grid):\n \"\"\"\n Determines if there exists a smooth path from the upper-left corner to the \n bottom-right corner of... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030262",
"row_id": 30262,
"seed_ids": "[7754]"
} | 0.611612 | Code_Contests_30262 | I | [
"is_smooth_path",
"smooth_path"
] | 2 | [
[
"smooth_path",
"is_smooth_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d79673b849f5a88c3c0501ae28eafa714a1b943 | 6f220fbb91db0dde8cb8fdd6730186036b1b22a0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30270_I | Mark is preparing for a coding competition and he has n points on a 2D plane represented by their coordinates (x, y). He wants to form multiple queries to determine if there is a right triangle with the right angle at each queried point such that the other two points of the triangle are also part of the n points provid... | def is_right_triangle(a, b, c):
# Function to check if points a, b, c can form a right triangle with a right angle at point `a`
ax, ay = a
bx, by = b
cx, cy = c
vec1 = (bx - ax, by - ay)
vec2 = (cx - ax, cy - ay)
# Check if dot product of vec1 and vec2 is 0
return vec1[0] * vec2[0] + v... | def test_main():
input_lines = [
"1",
"5 3",
"0 0",
"1 0",
"0 1",
"1 1",
"2 2",
"1",
"2",
"5"
]
expected_output = ["YES", "YES", "NO"]
assert main(input_lines) == expected_output
def test_no_right_triangle():
input... | [
{
"docstring": null,
"function_declaration": "def is_right_triangle(a, b, c):",
"function_name": "is_right_triangle",
"parameter_list": "(a, b, c)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solve",
"parameter_list": "(test_cases)"... | [
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 check_right_triangle(n, points, queries):\n results = []\n for query in queries:\n x_q, y_q = points[query - 1]\n found = False\n ... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00030270",
"row_id": 30270,
"seed_ids": "[3674]"
} | 0.723614 | Code_Contests_30270 | I | [
"is_right_triangle",
"solve",
"parse_input",
"main"
] | 4 | [
[
"solve",
"is_right_triangle"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | d51e9804a33660ffeba4c542aa047324434b1270 | b433f2e45949b17dc55a74345dba7c247f9ea745 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30276_I | You are given a matrix of size MxN filled with non-negative integers. A traversal from the top-left corner (0, 0) to the bottom-right corner (M-1, N-1) is performed, where at each step one can only move either right or down. Calculate the sum of all numbers along the path that costs the least.
Input:
- The first line ... | def min_sum_path(matrix):
"""
Returns the sum of the numbers along the path that costs the least to traverse
from the top-left corner (0, 0) to the bottom-right corner (M-1, N-1).
Args:
matrix: List[List[int]] - A 2D list containing non-negative integers.
Returns:
int - The minimum sum alo... | def test_min_sum_path():
matrix1 = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert min_sum_path(matrix1) == 7
matrix2 = [
[1, 2, 3],
[4, 5, 6]
]
assert min_sum_path(matrix2) == 12
matrix3 = [
[0, 0, 0],
[0, 0, 0]
]
assert min_sum_p... | [
{
"docstring": "Returns the sum of the numbers along the path that costs the least to traverse\nfrom the top-left corner (0, 0) to the bottom-right corner (M-1, N-1).\n\nArgs:\nmatrix: List[List[int]] - A 2D list containing non-negative integers.\n\nReturns:\nint - The minimum sum along the path.",
"functio... | [
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 minPathSum(matrix):\n \"\"\"\n Returns the sum of all numbers along the path that costs the least\n from the top-left corner to the bottom-rig... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030276",
"row_id": 30276,
"seed_ids": "[10622]"
} | 0.693657 | Code_Contests_30276 | I | [
"min_sum_path",
"solve"
] | 2 | [
[
"solve",
"min_sum_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | b91694268e3c1fa24db34c65317526189593d0c5 | 4bc9edcc6570999507516fe3f6af4646347a002f | |||
v1.0 | instruct | Code_Contests | Code_Contests_30299_I | Monica is designing a ring road network for a new city. The city has n intersections connected by m bidirectional roads. Each road has a specific length in kilometers. Monica wants to identify the longest road in the city that, when removed, does not change the city from being fully connected, such that all intersectio... | from collections import defaultdict
import heapq
def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
rootX = find(parent, x)
rootY = find(parent, y)
if rootX != rootY:
if rank[rootX] > rank[rootY]:
... | from solution import longest_road_to_remove
def test_example():
n, m = 5, 6
roads = [
(1, 2, 3),
(1, 3, 4),
(2, 3, 2),
(3, 4, 6),
(4, 5, 5),
(2, 5, 8)
]
assert longest_road_to_remove(n, m, roads) == 8
def test_no_removable_road():
n, m = 3, 3
roa... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_longest_safely_removable_road(n, m, roads):\n # Helper function to perform Union-Find operations\n parent = list(range(n))\n rank = [0] *... | trial_gpt4o_5 | {
"original_instruction": "",
"prompt_id": "00030299",
"row_id": 30299,
"seed_ids": "[4926]"
} | 0.692932 | Code_Contests_30299 | I | [
"find",
"union",
"kruskal",
"longest_road_to_remove"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"longest_road_to_remove",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 2ab0c936d621ca4a9d827c6cdfd35b1e2d38bdb9 | 38899183fff02be264a1506e181d56a61a0e3fd2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30313_I | You are given a single integer `N` (1 ≤ N ≤ 100) and a list of N integers `a_1, a_2, ..., a_N` where each `a_i` is between 1 and 1000. You need to partition the list into two non-empty subsets such that the absolute difference between the sum of the elements in the two subsets is minimized.
Constraints
* 1 ≤ N ≤ 100
... | def min_subset_difference(arr):
"""
Function to calculate the minimum subset difference
Args:
arr: List of integers
Returns:
int: The minimum difference between the sums of two subsets
"""
total_sum = sum(arr)
n = len(arr)
dp = [[False] * (total_sum // 2 + 1) for _ in r... | from solution import find_min_subset_difference
def test_example_1():
assert find_min_subset_difference(4, [1, 6, 5, 11]) == 1
def test_example_2():
assert find_min_subset_difference(5, [3, 1, 4, 2, 2]) == 0
def test_single_element():
assert find_min_subset_difference(1, [1000]) == 1000
def test_same_el... | [
{
"docstring": "Function to calculate the minimum subset difference\n\nArgs:\narr: List of integers\n\nReturns:\nint: The minimum difference between the sums of two subsets",
"function_declaration": "def min_subset_difference(arr):",
"function_name": "min_subset_difference",
"parameter_list": "(arr)... | [
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 min_partition_difference(N, a):\n \"\"\"\n Returns the minimum possible absolute difference between the sums of two subsets of the list a.\n \... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00030313",
"row_id": 30313,
"seed_ids": "[290]"
} | 0.673276 | Code_Contests_30313 | I | [
"min_subset_difference",
"find_min_subset_difference"
] | 2 | [
[
"find_min_subset_difference",
"min_subset_difference"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aed7ab0730897915a13cfc343417077012b4e732 | b5060e24ac3174fcce5ddcc448d4bacc1e222d48 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30316_I | There are n nodes in a network, numbered from 1 to n, connected by m bidirectional edges. Each node i has an associated value vi.
Now, there are q queries you need to handle. There are two types of queries:
* "U x y": Update the value at node x to y.
* "S x y": Find the maximum shortest path value between nodes x... | import heapq
def update_value(values, x, y):
values[x-1] = y
def max_shortest_path_value(graph, values, x, y):
n = len(values)
INF = float('inf')
dist = [INF] * n
visited = [False] * n
max_values = [0] * n
pq = []
dist[x-1] = 0
max_values[x-1] = values[x-1]
heapq.heappush(... | def test_update_value():
values = [5, 3, 8, 6, 2]
update_value(values, 2, 10)
assert values == [5, 10, 8, 6, 2]
def test_max_shortest_path_value():
n, m = 5, 5
values = [5, 3, 8, 6, 2]
edges = [(1, 2), (2, 3), (1, 4), (4, 5), (3, 5)]
graph = [[] for _ in range(n)]
for u, v in edges:
... | [
{
"docstring": null,
"function_declaration": "def update_value(values, x, y):",
"function_name": "update_value",
"parameter_list": "(values, x, y)"
},
{
"docstring": null,
"function_declaration": "def max_shortest_path_value(graph, values, x, y):",
"function_name": "max_shortest_path... | [
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 heapq import heappop, heappush\nfrom collections import defaultdict, deque\n\nINF = float('inf')\n\ndef dijkstra_max_value(n, adj_list, start, values)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030316",
"row_id": 30316,
"seed_ids": "[6191]"
} | 0.751821 | Code_Contests_30316 | I | [
"update_value",
"max_shortest_path_value",
"process_queries",
"main"
] | 4 | [
[
"process_queries",
"max_shortest_path_value"
],
[
"process_queries",
"update_value"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | c1ca48d4e0914fd3d3d6afe849b2d44cd476be86 | e4c4c1b5decf869df4fdc9c53d057585b2a41e8b | |||
v1.0 | instruct | Code_Contests | Code_Contests_30331_I | You have been tasked to manage the schedules of several university lecturers. Each lecturer has a set of classes they need to teach at different times of the week. Your goal is to ensure that no lecturer is scheduled to teach more than one class at the same time while maximizing the number of classes taught in a week. ... | from collections import defaultdict
def parse_time(time_str):
hours, minutes = map(int, time_str.split(':'))
return hours * 60 + minutes
def parse_classes(n, class_details):
lectures = defaultdict(list)
for detail in class_details:
lecturer, day, time_range = detail[0], int(detail[1]), detail[... | from solution import maximize_lecturer_classes
def test_example_1():
n = 5
class_details = [
("alice", "0", "09:00 - 10:00"),
("bob", "1", "10:00 - 12:00"),
("alice", "0", "10:00 - 11:00"),
("bob", "2", "15:00 - 17:00"),
("bob", "1", "11:00 - 13:00")
]
result = m... | [
{
"docstring": null,
"function_declaration": "def parse_time(time_str):",
"function_name": "parse_time",
"parameter_list": "(time_str)"
},
{
"docstring": null,
"function_declaration": "def parse_classes(n, class_details):",
"function_name": "parse_classes",
"parameter_list": "(n,... | [
0,
0,
0,
0,
0,
1,
1,
1,
1
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def parse_time(time_str):\n \"\"\"\n Parse the time string in HH:MM format and return the total number of minutes from 00:00.\n \"\"\"\n hours,... | trial_gpt4o_9 | {
"original_instruction": "",
"prompt_id": "00030331",
"row_id": 30331,
"seed_ids": "[8803]"
} | 0.716223 | Code_Contests_30331 | I | [
"parse_time",
"parse_classes",
"calculate_max_classes",
"maximize_lecturer_classes"
] | 4 | [
[
"maximize_lecturer_classes",
"calculate_max_classes"
],
[
"maximize_lecturer_classes",
"parse_classes"
],
[
"parse_classes",
"parse_time"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | a34c314384a5e0e2414dbaf6a844d650aa73ea92 | c7055fb34fcbd7d777815bac49b91d5aff5b76b6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30406_I | In a special school for programming, the students have a peculiar tradition. Each year, they select an integer k (1 ≤ k ≤ 100) and build a binary tree with k nodes. Each node in the tree has a unique value from 1 to k. To enhance their programming skills, students are given a task to transform this binary tree into its... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(node_descriptions, k):
nodes = {i: TreeNode(i) for i in range(1, k + 1)}
for parent, left, right in node_descriptions:
if left != 0:
nodes[parent].lef... | def test_build_tree_single_node():
k = 1
node_descriptions = [(1, 0, 0)]
root = build_tree(node_descriptions, k)
assert root.value == 1
assert root.left == None
assert root.right == None
def test_build_tree():
k = 3
node_descriptions = [(1, 2, 3), (2, 0, 0), (3, 0, 0)]
root = build_... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left \n self.right = right\n\nde... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030406",
"row_id": 30406,
"seed_ids": "[7871]"
} | 0.615369 | Code_Contests_30406 | I | [
"build_tree",
"in_order_traversal",
"canonical_form"
] | 3 | [
[
"canonical_form",
"build_tree"
],
[
"canonical_form",
"in_order_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 0bbfc99efb9a001365ad8e8e2f83a9b1817d5155 | 600a6c62626257b92a94ee851197493a00410232 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30425_I | You are given a list of words from a dictionary. Write a program which identifies and prints all the words that can be constructed from the given characters. The characters can each be used only once. Each test case will provide a list of words and the available set of characters.
Input
The first line contains an int... | from collections import Counter
def can_form_word(word, chars):
"""
Check if a word can be formed using the given set of characters.
"""
word_count = Counter(word)
chars_count = Counter(chars)
for char in word_count:
if word_count[char] > chars_count.get(char, 0):
retur... | from solution import words_from_chars
def test_single_word():
words = ["apple"]
chars = "aelpp"
assert words_from_chars(words, chars) == ["apple"]
def test_multiple_words():
words = ["apple", "orange", "grape", "melon"]
chars = "aelpp"
assert words_from_chars(words, chars) == ["apple"]
def te... | [
{
"docstring": "Check if a word can be formed using the given set of characters.",
"function_declaration": "def can_form_word(word, chars):",
"function_name": "can_form_word",
"parameter_list": "(word, chars)"
},
{
"docstring": "Returns a list of words that can be formed using the given set ... | [
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 can_construct_word(word, char_count):\n \"\"\"\n Helper function to determine if a word can be constructed with given character counts.\n \"\"... | trial_gpt4o_3 | {
"original_instruction": "",
"prompt_id": "00030425",
"row_id": 30425,
"seed_ids": "[8570]"
} | 0.669274 | Code_Contests_30425 | I | [
"can_form_word",
"words_from_chars"
] | 2 | [
[
"words_from_chars",
"can_form_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9048a9c3e21a82bac2cc6f85140053a27c740ef | 25360c242a0c4f57b25fb6fdd0bff8e0898f230e | |||
v1.0 | instruct | Code_Contests | Code_Contests_30454_I | Given an undirected graph G = (V, E), where V is a set of vertices and E is a set of edges, an independent set is a subset of vertices such that no two vertices in the subset are adjacent.
Given a graph, find the size of the maximum independent set.
Constraints
* 1 ≤ V ≤ 100
* 0 ≤ E ≤ 4,950
Input
V E
v1 v2
v3 v4
:... | from itertools import combinations
def is_independent_set(graph, subset):
"""
Check if the given subset of vertices form an independent set in the graph.
"""
for v1, v2 in combinations(subset, 2):
if v2 in graph[v1]:
return False
return True
def max_independent_set_size(V, edge... | def test_simple_case():
assert max_independent_set_size(5, [(0, 1), (0, 2), (1, 2), (1, 3), (2, 4), (3, 4)]) == 2
def test_no_edges():
assert max_independent_set_size(5, []) == 5
def test_single_vertex():
assert max_independent_set_size(1, []) == 1
def test_no_independent_set():
assert max_independen... | [
{
"docstring": "Check if the given subset of vertices form an independent set in the graph.",
"function_declaration": "def is_independent_set(graph, subset):",
"function_name": "is_independent_set",
"parameter_list": "(graph, subset)"
},
{
"docstring": "Return the size of the maximum indepen... | [
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_independent_set(graph, subset):\n \"\"\"\n Checks if the given subset of vertices is an independent set in the graph.\n \"\"\"\n for i i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030454",
"row_id": 30454,
"seed_ids": "[8746]"
} | 0.56195 | Code_Contests_30454 | I | [
"is_independent_set",
"max_independent_set_size"
] | 2 | [
[
"max_independent_set_size",
"is_independent_set"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e78f0e117132fd440ddbc6123ec2e766ccabe92d | 57741e982fce703ebc5d807ecf664a858666e8be | |||
v1.0 | instruct | Code_Contests | Code_Contests_30541_I | You have a grid with N rows and M columns. Each cell of the grid contains an integer value. You have to perform K operations on the grid. In each operation, you can pick any cell in the grid and replace the value in that cell with the maximum value of any of its 8 neighboring cells (including diagonals).
After perform... | def get_max_neighbor_value(grid, N, M, r, c):
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
max_value = grid[r][c]
for dr, dc in directions:
nr, nc = r + dr, c + dc
if 0 <= nr < N and 0 <= nc < M:
max_value = max(max_value, grid[nr][nc])
... | def test_get_max_value_after_operations():
assert get_max_value_after_operations(2, 3, 1, [[1, 2, 3], [4, 5, 6]]) == 6
assert get_max_value_after_operations(3, 3, 2, [[1, 3, 1], [3, 5, 3], [1, 3, 1]]) == 5
assert get_max_value_after_operations(1, 1, 0, [[7]]) == 7
assert get_max_value_after_operations(2... | [
{
"docstring": null,
"function_declaration": "def get_max_neighbor_value(grid, N, M, r, c):",
"function_name": "get_max_neighbor_value",
"parameter_list": "(grid, N, M, r, c)"
},
{
"docstring": null,
"function_declaration": "def perform_operations(grid, N, M, K):",
"function_name": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_value_after_operations(N, M, K, grid):\n directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]\n \n def get_... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030541",
"row_id": 30541,
"seed_ids": "[12053]"
} | 0.659299 | Code_Contests_30541 | I | [
"get_max_neighbor_value",
"perform_operations",
"get_max_value_after_operations"
] | 3 | [
[
"get_max_value_after_operations",
"perform_operations"
],
[
"perform_operations",
"get_max_neighbor_value"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1ff4ca50e40fbf77bc7fa488b08b335149634cb0 | 24c8624fb931365c65c8884794564fe7c80ab870 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30546_I | You are given a list of integers. Your task is to find the smallest possible value of their greatest common divisor (GCD) after removing exactly one integer from the list.
Input
The first line contains an integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t test cases follow. Each test case consists of two li... | import math
from functools import reduce
from typing import List
def gcd(a, b):
"""
Compute the greatest common divisor (GCD) of two numbers.
"""
return math.gcd(a, b)
def gcd_of_list(lst: List[int]) -> int:
"""
Compute the GCD of a list of numbers.
"""
return reduce(gcd, lst)
def min... | from solution import min_gcd_after_removal
def test_example_cases():
assert min_gcd_after_removal(3, [
[3, 2, 4, 6],
[4, 12, 15, 21, 25],
[5, 5, 10, 15, 20, 25]
]) == [2, 1, 5]
def test_single_case():
assert min_gcd_after_removal(1, [
[3, 3, 9, 6]
]) == [3]
def test_al... | [
{
"docstring": "Compute the greatest common divisor (GCD) of two numbers.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Compute the GCD of a list of numbers.",
"function_declaration": "def gcd_of_list(lst):",
"functi... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\nfrom typing import List\n\ndef gcd(a, b):\n \"\"\"\n Compute the greatest common divisor (GCD) of two numb... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030546",
"row_id": 30546,
"seed_ids": "[7312]"
} | 0.65796 | Code_Contests_30546 | I | [
"gcd",
"gcd_of_list",
"min_gcd_after_removal"
] | 3 | [
[
"gcd_of_list",
"gcd"
],
[
"min_gcd_after_removal",
"gcd_of_list"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cafaee37e1b6a259f9221da3af5b77769cf7a8be | 2d057c3a0295792d6b5c64ab1a6042ecbd2fa88f | |||
v1.0 | instruct | Code_Contests | Code_Contests_30548_I | Alice and Bob are playing an interesting game with a string. The string consists of only lowercase English letters. Alice makes the first move, and then they alternately take turns. In each move, a player must remove a substring that is a palindrome and also of length greater than 1. The player who cannot make a move l... | def can_remove_palindrome(s):
"""
Check if there is any palindrome substring of length greater than 1.
"""
n = len(s)
for length in range(2, n + 1):
for i in range(n - length + 1):
substring = s[i:i + length]
if substring == substring[::-1]:
return Tru... | from solution import who_wins
def test_who_wins_case1():
assert who_wins("ababa") == "Alice"
def test_who_wins_case2():
assert who_wins("abcde") == "Bob"
def test_who_wins_all_same_characters():
assert who_wins("aaaaa") == "Alice"
def test_who_wins_no_possible_move():
assert who_wins("abcdefgh") == ... | [
{
"docstring": "Check if there is any palindrome substring of length greater than 1.",
"function_declaration": "def can_remove_palindrome(s):",
"function_name": "can_remove_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Determine the winner of the game based on the initial string.",... | [
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_remove_palindrome_substring(s):\n \"\"\"\n Returns whether there is any palindrome substring of length greater than 1 in the string.\n \"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030548",
"row_id": 30548,
"seed_ids": "[2146]"
} | 0.822967 | Code_Contests_30548 | I | [
"can_remove_palindrome",
"who_wins"
] | 2 | [
[
"who_wins",
"can_remove_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a676ffa13ed632d4a5674de1e0d66d94ab5bb67e | 994f3b253b393f6f0501b83bcf125cec5316b0d6 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30562_I | Petya is an avid fan of prime numbers. One day, Petya was given an array of integers and asked to perform a special operation on it. An operation consists of choosing two non-overlapping subarrays (segments) such that the sum of the elements in both subarrays is equal to the same prime number.
Petya wants to know if i... | def is_prime(n):
"""Return True if n is prime, else False"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import prime_sum_subarrays
def test_case_1():
assert prime_sum_subarrays(7, [1, 2, 3, 6, 10, 3, 7]) == "YES"
def test_case_2():
assert prime_sum_subarrays(4, [4, 6, 8, 12]) == "NO"
def test_case_3():
assert prime_sum_subarrays(5, [1, 2, 1, 2, 3]) == "YES"
def test_case_4():
assert prim... | [
{
"docstring": "Return True if n is prime, else False",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def prime_sum_subarrays(n, a):",
"function_name": "prime_sum_subarrays",
"para... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Returns True if n is a prime number, False otherwise.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030562",
"row_id": 30562,
"seed_ids": "[2984]"
} | 0.653927 | Code_Contests_30562 | I | [
"is_prime",
"prime_sum_subarrays"
] | 2 | [
[
"prime_sum_subarrays",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6205a601fd56c76f168f8afa4ce2b935d600e258 | a0f1a4318a9a36fb613a25c31839f8e617e09a64 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30590_I | A company is planning a new project and needs to distribute their employees across various tasks. Each employee has a specific set of skills, and each task requires a minimum set of skills to be effectively completed. You need to determine the maximum number of tasks that can be completed if employees are optimally ass... | from typing import List, Set
def can_handle(task: Set[int], employee_skills: Set[int]) -> bool:
return task.issubset(employee_skills)
def max_tasks_completed(t: int, test_cases: List[List[List[int]]]) -> List[int]:
results = []
for case in test_cases:
n, m = case[0]
employee_skills = [set(... | from solution import max_tasks_completed
def test_single_case_simple():
t = 1
test_cases = [
[
[3, 3],
[2, 1, 2],
[3, 2, 3, 4],
[1, 5],
[1, 1],
[2, 1, 4],
[2, 2, 5]
]
]
assert max_tasks_completed(t, test... | [
{
"docstring": null,
"function_declaration": "def can_handle(task, employee_skills):",
"function_name": "can_handle",
"parameter_list": "(task, employee_skills)"
},
{
"docstring": null,
"function_declaration": "def max_tasks_completed(t, test_cases):",
"function_name": "max_tasks_com... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_complete_task(employee_skills, task_requirements):\n \"\"\"\n Check if the given employee can complete the given task.\n \"\"\"\n retur... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00030590",
"row_id": 30590,
"seed_ids": "[4712]"
} | 0.726495 | Code_Contests_30590 | I | [
"can_handle",
"max_tasks_completed"
] | 2 | [
[
"max_tasks_completed",
"can_handle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8f2e7ed262e23f2a0b4c864fa0c1dd0eb7418579 | 1c3028ce2e02e5742fea0f1a47cdb8873cd26dc2 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30591_I | A wizard has a list of spells, each represented as a string of lowercase letters. He wants to sort this list such that the spells are arranged in either ascending or descending order of their magical power. The magical power of a spell is calculated as the sum of all the alphabetical positions of its letters ('a' is 1,... | def spell_power(spell):
"""
Calculate the magical power of a spell.
The magical power is the sum of all the alphabetical positions of its letters ('a' is 1, 'b' is 2, ..., 'z' is 26).
"""
return sum(ord(char) - ord('a') + 1 for char in spell)
def sort_spells(spells, order):
"""
Sort the lis... | from solution import sort_spells
def test_sort_spells_asc():
spells = ["abcd", "dz", "wxyz", "aa"]
order = "asc"
assert sort_spells(spells, order) == ['aa', 'abcd', 'dz', 'wxyz']
def test_sort_spells_desc():
spells = ["abcd", "dz", "wxyz", "aa"]
order = "desc"
assert sort_spells(spells, order)... | [
{
"docstring": "Calculate the magical power of a spell.\nThe magical power is the sum of all the alphabetical positions of its letters ('a' is 1, 'b' is 2, ..., 'z' is 26).",
"function_declaration": "def spell_power(spell):",
"function_name": "spell_power",
"parameter_list": "(spell)"
},
{
"... | [
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 spell_magical_power(spell):\n \"\"\"\n Calculate the magical power of a spell, which is the sum of the alphabetical positions of its letters.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030591",
"row_id": 30591,
"seed_ids": "[11708]"
} | 0.600537 | Code_Contests_30591 | I | [
"spell_power",
"sort_spells"
] | 2 | [
[
"sort_spells",
"spell_power"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cb5193c3e51bce9e5d7299e685cbb697e684c452 | 065b9c0771134a19a6923ffb35be542b03708fb1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30645_I | Binary Trees are a fundamental data structure in computer science. A binary tree is a hierarchical structure in which each node has at most two children, referred to as the left child and the right child.
Given a binary tree, your task is to determine if the tree is height-balanced. A height-balanced binary tree is de... | class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def is_balanced(root):
def check_height(node):
if not node:
return 0, True
left_height, left_balanced = check_height(node.left)
ri... | import pytest
from solution import is_binary_tree_balanced
def test_balanced_tree():
node_count = 5
node_list = [
(1, 2, 3),
(2, 4, 5),
(3, -1, -1),
(4, -1, -1),
(5, -1, -1)
]
assert is_binary_tree_balanced(node_count, node_list) == "YES"
def test_unbalanced_tre... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, value, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030645",
"row_id": 30645,
"seed_ids": "[11095]"
} | 0.780908 | Code_Contests_30645 | I | [
"is_balanced",
"build_tree",
"is_binary_tree_balanced"
] | 3 | [
[
"is_binary_tree_balanced",
"build_tree"
],
[
"is_binary_tree_balanced",
"is_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2ff3989a393bd3bae7bd227cc9ba94a261690a01 | 54a5b4dd5f1781eaf96e51cd716a44191e1403c0 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30670_I | A popular sorting algorithm is the merge sort algorithm. The beauty of merge sort is that it splits an array in half, recursively sorts the two halves, and then merges the sorted halves to produce a sorted whole. The process is efficient, yet intuitive.
In this problem, you are tasked with implementing a special versi... | def merge_sort_and_count(arr):
"""
Function to perform merge sort and count inversions.
"""
if len(arr) <= 1:
return arr, 0
mid = len(arr) // 2
left, left_inv = merge_sort_and_count(arr[:mid])
right, right_inv = merge_sort_and_count(arr[mid:])
merged, split_inv = merge_and_coun... | from solution import count_inversions
def test_example_case_1():
arr = [2, 4, 1, 3, 5]
assert count_inversions(arr) == 3
def test_example_case_2():
arr = [5, 4, 3, 2, 1]
assert count_inversions(arr) == 10
def test_no_inversions():
arr = [1, 2, 3, 4, 5]
assert count_inversions(arr) == 0
def t... | [
{
"docstring": "Function to perform merge sort and count inversions.",
"function_declaration": "def merge_sort_and_count(arr):",
"function_name": "merge_sort_and_count",
"parameter_list": "(arr)"
},
{
"docstring": "Helper function to merge two sorted arrays and count inversions.",
"funct... | [
0,
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subar... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00030670",
"row_id": 30670,
"seed_ids": "[7124]"
} | 0.717173 | Code_Contests_30670 | I | [
"merge_sort_and_count",
"merge_and_count",
"count_inversions"
] | 3 | [
[
"count_inversions",
"merge_sort_and_count"
],
[
"merge_sort_and_count",
"merge_and_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5abf6cb249211de194dae212ce3d4fb5a33d5a2a | 642a377f8dabe5c2eb17314ba4d3ce7f542a1a28 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30682_I | Rational numbers can be expressed as the ratio of two integers. Two rational numbers are considered to be equivalent if they reduce to the same fraction in their simplest forms. Write a program to determine if given pairs of rational numbers are equivalent.
Each test case consists of a set of two rational numbers. The... | from math import gcd
def simplify_fraction(numerator, denominator):
"""
Simplifies the fraction by dividing the numerator and denominator by their greatest common divisor (GCD).
"""
common_divisor = gcd(numerator, denominator)
return numerator // common_divisor, denominator // common_divisor
def a... | from solution import are_equivalent, check_equivalence
def test_simplify_fraction():
from solution import simplify_fraction
assert simplify_fraction(4, 6) == (2, 3)
assert simplify_fraction(2, 4) == (1, 2)
assert simplify_fraction(10, 25) == (2, 5)
assert simplify_fraction(5, 25) == (1, 5)
asse... | [
{
"docstring": "Simplifies the fraction by dividing the numerator and denominator by their greatest common divisor (GCD).",
"function_declaration": "def simplify_fraction(numerator, denominator):",
"function_name": "simplify_fraction",
"parameter_list": "(numerator, denominator)"
},
{
"docst... | [
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 fractions import Fraction\n\ndef are_equivalent_rationals(pair):\n \"\"\"\n Determines if two rational numbers in the given pair are equivalent.... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030682",
"row_id": 30682,
"seed_ids": "[10624]"
} | 0.562581 | Code_Contests_30682 | I | [
"simplify_fraction",
"are_equivalent",
"check_equivalence"
] | 3 | [
[
"are_equivalent",
"simplify_fraction"
],
[
"check_equivalence",
"are_equivalent"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8c52eb4717bd7c690a3ce585f0c8f4c2c3d775f6 | 25d884fe222772034ae1cb106cfbec9c4c6ae795 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30707_I | A DNA sequence is represented by a string consisting of the characters 'A', 'C', 'G', and 'T'. Given a DNA sequence, your task is to find the longest substring that contains at most two different characters. If there are multiple substrings with the same length, return the leftmost one.
Write a program that takes in a... | def longest_substring_with_two_chars(s):
from collections import defaultdict
# Sliding window approach with two pointers
left = 0
right = 0
max_substring = ""
char_map = defaultdict(int)
while right < len(s):
char_map[s[right]] += 1
while len(char_map) > 2:
cha... | def test_longest_substring_with_two_chars():
assert longest_substring_with_two_chars("GATTACA") == "ATTA"
assert longest_substring_with_two_chars("CGCGATTA") == "CGCG"
assert longest_substring_with_two_chars("A") == "A"
assert longest_substring_with_two_chars("AAAA") == "AAAA"
assert longest_substri... | [
{
"docstring": null,
"function_declaration": "def longest_substring_with_two_chars(s):",
"function_name": "longest_substring_with_two_chars",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def process_sequences(sequences):",
"function_name": "process_sequenc... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_substring_two_chars(dna):\n \"\"\"\n Finds the longest substring containing at most two different characters.\n \"\"\"\n max_length... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030707",
"row_id": 30707,
"seed_ids": "[10918]"
} | 0.721603 | Code_Contests_30707 | I | [
"longest_substring_with_two_chars",
"process_sequences"
] | 2 | [
[
"process_sequences",
"longest_substring_with_two_chars"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bb97ac31407b00a6e9999506d502a79da2869c2c | 200070e68ce9d9fe18796eebad3176f8216cce22 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30769_I | An imaginary city has a unique transportation system consisting of multiple train routes where each route connects exactly two stations. Each station can be connected to multiple other stations, forming a network.
The city's transportation planner wants to ensure that there exists a way to travel from any station to ... | def find_root(parent, i):
if parent[i] == i:
return i
else:
return find_root(parent, parent[i])
def union(parent, rank, x, y):
root_x = find_root(parent, x)
root_y = find_root(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_... | from solution import min_additional_routes
def test_single_station():
assert min_additional_routes(1, 0, []) == 0
def test_double_disconnected():
assert min_additional_routes(4, 2, [(1, 2), (3, 4)]) == 1
def test_larger_disconnected():
assert min_additional_routes(5, 3, [(1, 2), (2, 3), (4, 5)]) == 1
de... | [
{
"docstring": null,
"function_declaration": "def find_root(parent, i):",
"function_name": "find_root",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x,... | [
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_min_additional_routes(n, m, connections):\n parent = list(range(n))\n\n def find(x):\n if parent[x] == x:\n return x\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030769",
"row_id": 30769,
"seed_ids": "[5557]"
} | 0.728346 | Code_Contests_30769 | I | [
"find_root",
"union",
"min_additional_routes"
] | 3 | [
[
"min_additional_routes",
"find_root"
],
[
"min_additional_routes",
"union"
],
[
"union",
"find_root"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 31fd303f96dfe5d88e804caecff79102d0d1a0dc | 99a1633b68086dfffe74cf399f96a84c1d72d912 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30806_I | A network of computers is represented in a grid structure where each cell contains either a '0' (representing an empty space where no computer is present) or a '1' (representing a computer). Two computers are considered connected if they are adjacent horizontally or vertically.
Your task is to determine how many uniqu... | def dfs(grid, i, j, visited):
"""
Depth-first search to mark all connected '1's as visited.
"""
n, m = len(grid), len(grid[0])
stack = [(i, j)]
while stack:
x, y = stack.pop()
if 0 <= x < n and 0 <= y < m and grid[x][y] == '1' and not visited[x][y]:
visited[x][y] = Tr... | from solution import count_networks
def test_example_1():
grid = [
"11000",
"11000",
"00100",
"00011",
]
assert count_networks(grid) == 3
def test_example_2():
grid = [
"111",
"010",
"111",
]
assert count_networks(grid) == 1
def test... | [
{
"docstring": "Depth-first search to mark all connected '1's as visited.",
"function_declaration": "def dfs(grid, i, j, visited):",
"function_name": "dfs",
"parameter_list": "(grid, i, j, visited)"
},
{
"docstring": "Count the number of unique networks of connected computers.",
"functio... | [
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 dfs(grid, i, j, visited):\n \"\"\"\n Depth-first search to mark all connected '1's as visited.\n \"\"\"\n n, m = len(grid), len(grid[0])\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00030806",
"row_id": 30806,
"seed_ids": "[8779]"
} | 0.644069 | Code_Contests_30806 | I | [
"dfs",
"count_networks"
] | 2 | [
[
"count_networks",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1bac8543669ca9a69d890f225ab59ae140cc2b44 | bc4e972461d5c0e402234390d1cc3c69c4d79c79 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30837_I | You are given a grid representing a city plan that is composed of buildings, roads, and parks. The city is represented as a 2D grid where each cell can either be a building (`'B'`), road (`'R'`), or park (`'P'`). The goal is to find the shortest path from the starting point to the destination considering that you can o... | from collections import deque
def shortest_path(city_plan, start, destination):
w, h = len(city_plan[0]), len(city_plan)
sx, sy = start
dx, dy = destination
def is_valid(x, y):
return 0 <= x < h and 0 <= y < w and city_plan[x][y] in ('R', 'P')
# If the start or destination is a bu... | from solution import execute_plans
def test_example_case():
plans = [
"5 5",
"RRRRR",
"RBBBB",
"RPRPR",
"RRRRR",
"RRRRR",
"0 0 4 4",
"4 4",
"RRRR",
"RBRR",
"RRRR",
"RPRR",
"0 0 3 3",
"0 0"
... | [
{
"docstring": null,
"function_declaration": "def shortest_path(city_plan, start, destination):",
"function_name": "shortest_path",
"parameter_list": "(city_plan, start, destination)"
},
{
"docstring": null,
"function_declaration": "def execute_plans(plans):",
"function_name": "execu... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_destination(grid, start, destination):\n w, h = len(grid[0]), len(grid)\n sx, sy = start\n dx, d... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00030837",
"row_id": 30837,
"seed_ids": "[6549]"
} | 0.764685 | Code_Contests_30837 | I | [
"shortest_path",
"execute_plans"
] | 2 | [
[
"execute_plans",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8b92ff4fac169dd6cb2a6838b43df1027053d40e | 7ef8c160a5d4cddca0cdea2f45f7a8773f7d917b | |||
v1.0 | instruct | Code_Contests | Code_Contests_30886_I | Jenna is working on a network of computers connected with direct communication channels. The network consists of n computers and m bi-directional communication channels. Each communication channel has a latency value. Jenna needs to perform q queries on the network to determine the shortest communication path between d... | import heapq
def floyd_warshall(n, edges):
dist = [[float('inf')] * n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
for u, v, l in edges:
dist[u-1][v-1] = min(dist[u-1][v-1], l)
dist[v-1][u-1] = min(dist[v-1][u-1], l)
for k in range(n):
for i in range(n):
... | def test_shortest_path_example_1():
assert shortest_path(
4, 4, 2,
[(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7)],
[(1, 4), (2, 3)]
) == [9, 1]
def test_shortest_path_example_2():
assert shortest_path(
5, 3, 3,
[(1, 2, 3), (1, 3, 10), (4, 5, 1)],
[(1, 4), (1, 5... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, edges):",
"function_name": "floyd_warshall",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def shortest_path(n, m, q, edges, queries):",
"function_name": "shortest_path",
"parame... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef find_shortest_paths(n, m, q, edges, queries):\n \"\"\"\n Uses Dijkstra's algorithm to find the shortest paths in a weighted graph... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030886",
"row_id": 30886,
"seed_ids": "[12454]"
} | 0.656573 | Code_Contests_30886 | I | [
"floyd_warshall",
"shortest_path"
] | 2 | [
[
"shortest_path",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 74c03ce43e93c48e36fa56f24ca40a4a68036bf4 | 5d800ab5ffd9623cd1b7bd35ca5bafe8f65d9eb4 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30955_I | Alex loves creating patterns with numbers. Recently, he came across an interesting problem: given a positive integer n, generate the first n terms of the sequence where each term is the sum of the digits of the square of the index of that term. Specifically, the k-th term of the sequence should be the sum of the digits... | def sum_of_digits(n):
"""
Returns the sum of digits of the given number n.
"""
return sum(int(digit) for digit in str(n))
def generate_sequence(n):
"""
Generates the first n terms of the sequence where each term is the sum of the digits
of the square of the index of that term.
"""
s... | from solution import sum_of_digits, generate_sequence
def test_sum_of_digits():
assert sum_of_digits(1) == 1
assert sum_of_digits(4) == 4
assert sum_of_digits(16) == 1 + 6
assert sum_of_digits(25) == 2 + 5
assert sum_of_digits(100) == 1 + 0 + 0
def test_generate_sequence():
assert generate... | [
{
"docstring": "Returns the sum of digits of the given number n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Generates the first n terms of the sequence where each term is the sum of the digits\nof the square... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_sequence(n):\n \"\"\"\n Generates the first n terms of the sequence where each term is \n the sum of the digits of the square of the ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00030955",
"row_id": 30955,
"seed_ids": "[9909]"
} | 0.628793 | Code_Contests_30955 | I | [
"sum_of_digits",
"generate_sequence"
] | 2 | [
[
"generate_sequence",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2837025a4dd0caae4754d9066622e6f9673bba94 | b739b89665452663ea7d18781c317265e19bb843 | |||
v1.0 | instruct | Code_Contests | Code_Contests_30994_I | Dr. Azuma, an avid mathematician and puzzle enthusiast, has recently devised a new challenge involving palindrome numbers. He seeks your help to determine whether given numbers can be rearranged to form a palindrome with minimal changes.
A palindrome number is a number that reads the same backward as forward. For the ... | def can_form_palindrome_with_one_edit(num_str):
"""
Determines if a number can be rearranged to form a palindrome with at most one digit change.
"""
n = len(num_str)
left, right = 0, n - 1
changes = 0
chars = list(num_str)
while left < right:
if chars[left] != chars[right]:
... | from solution import can_form_palindrome_with_one_edit, process_input_numbers
def test_can_form_palindrome_with_one_edit():
assert can_form_palindrome_with_one_edit('12321') == 'Yes 12321'
assert can_form_palindrome_with_one_edit('12121') == 'Yes 12121'
assert can_form_palindrome_with_one_edit('2002') == '... | [
{
"docstring": "Determines if a number can be rearranged to form a palindrome with at most one digit change.",
"function_declaration": "def can_form_palindrome_with_one_edit(num_str):",
"function_name": "can_form_palindrome_with_one_edit",
"parameter_list": "(num_str)"
},
{
"docstring": null... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def can_form_palindrome_with_one_change(number):\n \"\"\"\n Determine if the digits of the given number can be rearranged to... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00030994",
"row_id": 30994,
"seed_ids": "[2704]"
} | 0.714395 | Code_Contests_30994 | I | [
"can_form_palindrome_with_one_edit",
"process_input_numbers"
] | 2 | [
[
"process_input_numbers",
"can_form_palindrome_with_one_edit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 83e7663cc9e801a9b24cffac57aff538f3877ee0 | fb1e8bc68f8bc0d79d4b55e25867a34bc72e2f87 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31060_I | Recently Sam started learning about prefix sums and found them quite interesting. He discovered that with the help of prefix sums he can find the sum of any subarray in constant time after doing some preprocessing. He wants to test his understanding by solving some problems using prefix sums. Can you help him?
Given a... | def preprocess_prefix_sums(arr):
"""
Preprocesses the array to calculate prefix sums.
"""
n = len(arr)
prefix_sums = [0] * (n + 1)
for i in range(n):
prefix_sums[i + 1] = prefix_sums[i] + arr[i]
return prefix_sums
def subarray_sum(prefix_sums, l, r):
"""
Returns the sum of t... | def test_preprocess_prefix_sums():
arr = [1, 2, 3, 4, 5]
expected_prefix_sums = [0, 1, 3, 6, 10, 15]
assert preprocess_prefix_sums(arr) == expected_prefix_sums
def test_subarray_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert subarray_sum(prefix_sums, 1, 3) == 6
assert subarray_sum(prefix_sums... | [
{
"docstring": "Preprocesses the array to calculate prefix sums.",
"function_declaration": "def preprocess_prefix_sums(arr):",
"function_name": "preprocess_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the sum of the subarray from index l to r (1-based index).",
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum_array(a):\n prefix_sums = [0] * (len(a) + 1)\n for i in range(len(a)):\n prefix_sums[i + 1] = prefix_sums[i] + a[i]\n return... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031060",
"row_id": 31060,
"seed_ids": "[9444]"
} | 0.605216 | Code_Contests_31060 | I | [
"preprocess_prefix_sums",
"subarray_sum",
"solve"
] | 3 | [
[
"solve",
"preprocess_prefix_sums"
],
[
"solve",
"subarray_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 96a4ebba8cbc2961121e8108912d230e89f051ef | 22b8628e3e4122b838deb246bb70db012517e633 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31069_I | In Bellworld, there are n interconnected cities C1, C2, ..., Cn with one-way roads. Each road has a certain travel time. Your task is to help Bellworld's delivery company to find the shortest delivery routes between pairs of cities.
You will be given a list of roads between cities and asked to answer m queries, where... | import sys
def floyd_warshall(n, dist):
for k in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
def find_shortest_paths(n, roads, queries):
# Initialize the distances matrix w... | def test_single_dataset():
input_n = 3
input_r = 3
roads = [(1, 2, 5), (2, 3, 10), (1, 3, 15)]
queries = [(1, 3), (2, 1)]
expected_output = [15, -1]
assert find_shortest_paths(input_n, roads, queries) == expected_output
def test_no_path():
input_n = 4
input_r = 5
roads = [(1, 2... | [
{
"docstring": null,
"function_declaration": "def floyd_warshall(n, dist):",
"function_name": "floyd_warshall",
"parameter_list": "(n, dist)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_paths(n, roads, queries):",
"function_name": "find_shortest_paths",
"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 floyd_warshall(n, roads):\n inf = float('inf')\n distances = [[inf] * n for _ in range(n)]\n\n for i in range(n):\n distances[i][i] = 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031069",
"row_id": 31069,
"seed_ids": "[1968]"
} | 0.81047 | Code_Contests_31069 | I | [
"floyd_warshall",
"find_shortest_paths"
] | 2 | [
[
"find_shortest_paths",
"floyd_warshall"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 530563fec06902210c0830b19b2b5a240fd06940 | d778db61332b8fa8a5588f94d3f2cec030c9b1ae | |||
v1.0 | instruct | Code_Contests | Code_Contests_31176_I | A company is planning to upgrade its servers and wants to ensure high availability. They have noticed that during maintenance or server failures, it is crucial to balance the load on the other available servers to minimize downtime and performance degradation. As an initial step, they want to simulate this by distribut... | def canDistribute(tasks, k, maxLoad):
currentLoadSum = 0
numServers = 1
for task in tasks:
if currentLoadSum + task > maxLoad:
numServers += 1
currentLoadSum = task
if numServers > k:
return False
else:
currentLoadSum += ta... | from solution import process_test_cases
def test_example_cases():
T = 2
test_cases = [
[(5, 2), [1, 2, 3, 4, 5]],
[(6, 3), [10, 10, 10, 10, 10, 10]]
]
expected = [9, 20]
assert process_test_cases(T, test_cases) == expected
def test_single_task():
T = 1
test_cases = [
... | [
{
"docstring": null,
"function_declaration": "def canDistribute(tasks, k, maxLoad):",
"function_name": "canDistribute",
"parameter_list": "(tasks, k, maxLoad)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_load(tasks, k):",
"function_name": "minimize_max_load",
... | [
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 typing import List\n\ndef minimize_max_load(tasks: List[int], k: int) -> int:\n def canDistribute(mid):\n current_sum, required_servers = 0,... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031176",
"row_id": 31176,
"seed_ids": "[2370]"
} | 0.628418 | Code_Contests_31176 | I | [
"canDistribute",
"minimize_max_load",
"process_test_cases"
] | 3 | [
[
"minimize_max_load",
"canDistribute"
],
[
"process_test_cases",
"minimize_max_load"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 9e083debb5be9787124179ead7228d12c72ce00b | 1288e38a478bfc6dfafb4fb58a70e10d4d340c18 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31202_I | Maria is a big fan of palindrome numbers. One day, she thought about a unique problem to challenge her friends. She gave them a number K and asked them to find all the palindromic numbers between 1 and K (inclusive).
Your task is to help Maria's friends by writing a program to find all the palindromic numbers between ... | def is_palindrome(number):
"""
Checks whether a given number is a palindrome.
"""
return str(number) == str(number)[::-1]
def find_palindromes_up_to_k(k):
"""
Finds all palindromic numbers between 1 and k (inclusive).
"""
palindromes = [num for num in range(1, k + 1) if is_palindrome(nu... | import pytest
from solution import palindromes_between_1_and_k
def test_single_digit_palindromes():
assert palindromes_between_1_and_k([10]) == ["1 2 3 4 5 6 7 8 9"]
def test_palindromes_up_to_50():
assert palindromes_between_1_and_k([50]) == ["1 2 3 4 5 6 7 8 9 11 22 33 44"]
def test_no_palindromes():
a... | [
{
"docstring": "Checks whether a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Finds all palindromic numbers between 1 and k (inclusive).",
"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 find_palindromic_numbers(K):\n \"\"\"\n Returns a list of all palindromic numbers between 1 and K (inclusive).\n \"\"\"\n def is_palindrome... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031202",
"row_id": 31202,
"seed_ids": "[2887]"
} | 0.736112 | Code_Contests_31202 | I | [
"is_palindrome",
"find_palindromes_up_to_k",
"palindromes_between_1_and_k"
] | 3 | [
[
"find_palindromes_up_to_k",
"is_palindrome"
],
[
"palindromes_between_1_and_k",
"find_palindromes_up_to_k"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 058cadeaf6181704c246d63686a4d999c4618c86 | 00a75d7f42a8afca3f0dcc96dc0df6a3ff9eb044 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31273_I | Alice loves rectangular grids and numbers. She decided to create a game involving these two.
The game is played on an m x n grid, where each cell initially contains a number. Alice can perform the following operation any number of times:
- Select a subrectangle from the grid and add the same integer x (positive or ne... | def can_make_grid_equal(grid):
"""
Determines if it's possible to make all numbers in the grid equal.
If possible, returns a list of operations to achieve it.
"""
m = len(grid)
n = len(grid[0])
# Calculate the modulo with respect to the first element in the grid.
base = grid[0][0]
... | def test_can_make_grid_equal():
grid1 = [
[1, 2, 3],
[4, 5, 6]
]
grid2 = [
[1, 2],
[3, 4]
]
grid3 = [
[5, 5],
[5, 5]
]
assert can_make_grid_equal(grid1) == ("NO", [])
assert can_make_grid_equal(grid2) == ("NO", [])
assert can_make_grid_... | [
{
"docstring": "Determines if it's possible to make all numbers in the grid equal.\nIf possible, returns a list of operations to achieve it.",
"function_declaration": "def can_make_grid_equal(grid):",
"function_name": "can_make_grid_equal",
"parameter_list": "(grid)"
},
{
"docstring": null,
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def make_all_numbers_equal(grids):\n results = []\n\n for grid in grids:\n m, n, matrix = grid\n first_elem = matrix[0][0]\n pos... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00031273",
"row_id": 31273,
"seed_ids": "[11857]"
} | 0.694385 | Code_Contests_31273 | I | [
"can_make_grid_equal",
"process_grids"
] | 2 | [
[
"process_grids",
"can_make_grid_equal"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 58c3f9364f254ff7a5df7383d2b4f47efc5ab341 | b62b1d4f74a4d7e5d657f44dd3688897757ea795 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31279_I | Recipe Ingredient Calculator
Everyone loves food, and so does Chef Anna. Trying out new recipes is her hobby. However, adjusting the ingredient quantities as per the number of servings required is a tedious task. Hence, she has approached you for help.
Your responsibility is to write a program that calculates the qua... | def parse_recipes_and_requests(data):
lines = data.splitlines()
n = int(lines[0])
recipes = []
index = 1
for _ in range(n):
line_parts = lines[index].split()
index += 1
num_servings = int(line_parts[-1])
ingredients = []
for i in range(0, len(line_parts) ... | def test_recipe_calculator():
input_data = "2\nflour 200 g sugar 100 g butter 50 g 4\npasta 250 g tomato 2 unit cheese 100 g 2\n1 8\n2 3\n0"
expected_output = "flour 400.00 g\nsugar 200.00 g\nbutter 100.00 g\npasta 375.00 g\ntomato 3.00 unit\ncheese 150.00 g"
assert recipe_calculator(input_data) == expected... | [
{
"docstring": null,
"function_declaration": "def parse_recipes_and_requests(data):",
"function_name": "parse_recipes_and_requests",
"parameter_list": "(data)"
},
{
"docstring": null,
"function_declaration": "def calculate_ingredients(recipes, requests):",
"function_name": "calculate... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_ingredient_quantities(recipes, requests):\n \"\"\"\n Calculate the ingredient quantities based on the number of servings requested.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031279",
"row_id": 31279,
"seed_ids": "[7904]"
} | 0.717605 | Code_Contests_31279 | I | [
"parse_recipes_and_requests",
"calculate_ingredients",
"format_output",
"recipe_calculator"
] | 4 | [
[
"recipe_calculator",
"calculate_ingredients"
],
[
"recipe_calculator",
"format_output"
],
[
"recipe_calculator",
"parse_recipes_and_requests"
]
] | 3 | [
"format_output"
] | false | [] | false | pytest | false | [] | true | 904c9913730df61884b2d0834127f956381df103 | 1b959ff78041928b435ae08452e06b078fb4b946 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31299_I | Eva loves numbers and is particularly fascinated by palindromic numbers - numbers that read the same forward and backward. One day, she decided to create a challenge for herself: finding the smallest palindromic number that is larger than a given integer N.
A palindrome is a sequence that reads the same backward as fo... | def is_palindrome(num):
"""
Check if a given number is a palindrome.
"""
return str(num) == str(num)[::-1]
def next_palindrome(N):
"""
Find the smallest palindromic number greater than N.
"""
N += 1
while not is_palindrome(N):
N += 1
return N
def find_next_palindromes(t... | from solution import find_next_palindromes, next_palindrome
def test_next_palindrome():
assert next_palindrome(123) == 131
assert next_palindrome(99) == 101
assert next_palindrome(1) == 2
assert next_palindrome(8) == 9
assert next_palindrome(808) == 818
assert next_palindrome(999) == 1001
def ... | [
{
"docstring": "Check if a given number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Find the smallest palindromic number greater than N.",
"function_declaration": "def next_palindrome... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def next_palindrome(N):\n \"\"\"\n Returns the smallest palindromic number greater than N.\n \"\"\"\n def is_palindrome(number):\n retur... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031299",
"row_id": 31299,
"seed_ids": "[9268]"
} | 0.80716 | Code_Contests_31299 | I | [
"is_palindrome",
"next_palindrome",
"find_next_palindromes"
] | 3 | [
[
"find_next_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cbe20aaeda72b7cada8673e7aa32261ac002fa5c | e60d2be35f4240ea0a135611b30c9f05131f44dc | |||
v1.0 | instruct | Code_Contests | Code_Contests_31304_I | In a faraway kingdom, the king loves sequences of numbers. One day, he poses a challenge to his subjects: Given a sequence of N integers, find the number of special subsequences of this sequence. A special subsequence is defined as a subsequence where each element is a multiple of the previous element.
Write a progra... | def count_special_subsequences(N, sequence):
MOD = 10**9 + 7
dp = [0] * N
for i in range(N):
# Start with the element itself as a subsequence
dp[i] = 1
for j in range(i):
if sequence[i] % sequence[j] == 0:
dp[i] = (dp[i] + dp[j]) % MOD
... | from solution import count_special_subsequences
def test_example_case_1():
assert count_special_subsequences(4, [1, 2, 4, 8]) == 15
def test_example_case_2():
assert count_special_subsequences(3, [2, 2, 4]) == 7
def test_single_element():
assert count_special_subsequences(1, [10]) == 1
def test_all_elem... | [
{
"docstring": null,
"function_declaration": "def count_special_subsequences(N, sequence):",
"function_name": "count_special_subsequences",
"parameter_list": "(N, sequence)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"parameter_list"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_special_subsequences(N, sequence):\n MOD = 10**9 + 7\n \n dp = [0] * N\n for i in range(N):\n # Start with the element itself ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031304",
"row_id": 31304,
"seed_ids": "[7476]"
} | 0.797019 | Code_Contests_31304 | I | [
"count_special_subsequences",
"solve"
] | 2 | [
[
"solve",
"count_special_subsequences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7d810b90bce8423341f28f9e5c7a33da244e3bb0 | 5af6da4eba5c77acf1e4a6b5d5fc0acbb3013b11 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31320_I | John is studying algorithms and graph theory. He has encountered a problem involving directed acyclic graphs (DAGs). The problem is as follows:
Given a directed acyclic graph with `n` vertices and `m` edges, John needs to determine the number of distinct topological orderings of the graph.
A topological ordering of a... | MOD = 1000000007
def count_topological_orderings(n, m, edges):
from functools import lru_cache
from itertools import permutations
graph = {i: [] for i in range(n)}
indegree = {i: 0 for i in range(n)}
for u, v in edges:
graph[u - 1].append(v - 1)
indegree[v - 1] += 1
@lru_cach... | from solution import solve_topological_orderings
def test_example_1():
graph_input = [
"3 2",
"1 2",
"2 3"
]
assert solve_topological_orderings(graph_input) == 1
def test_example_2():
graph_input = [
"4 3",
"1 2",
"1 3",
"3 4"
]
assert so... | [
{
"docstring": null,
"function_declaration": "def count_topological_orderings(n, m, edges):",
"function_name": "count_topological_orderings",
"parameter_list": "(n, m, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_topological_orderings(graph_input):",
"function_n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef count_topological_orderings(n, m, edges):\n from functools import lru_cache\n from itertools import permutations\n\n graph... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031320",
"row_id": 31320,
"seed_ids": "[4729]"
} | 0.602987 | Code_Contests_31320 | I | [
"count_topological_orderings",
"solve_topological_orderings"
] | 2 | [
[
"solve_topological_orderings",
"count_topological_orderings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4beebd7774a5d2df8382bfdc6722dbc902bfb169 | dce541f06593ea5e78d5ac87dc67dd37c1d1c92b | |||
v1.0 | instruct | Code_Contests | Code_Contests_31324_I | Given a number, determine if it can be expressed as the sum of two prime numbers. If the number can be expressed as the sum of two prime numbers, print "YES" followed by the pair of prime numbers. If there are multiple pairs, print any one of them. If the number cannot be expressed as the sum of two prime numbers, prin... | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import find_prime_sum_pair, is_prime
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(1) == False
def test_prime_sum_pair_34():
result = find_prime_sum_pair(34)
assert result.sta... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determine if `n` can be expressed as the sum of two prime numbers.",
"function_declaration": "def find_prime_sum_pair(n):"... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <=... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031324",
"row_id": 31324,
"seed_ids": "[1330]"
} | 0.701954 | Code_Contests_31324 | I | [
"is_prime",
"find_prime_sum_pair"
] | 2 | [
[
"find_prime_sum_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3956bf6eaa5e5a6f261b4f14cdff35cbdb46459e | 17b9c060bbc8b0803595c0d42a33b56172f3170f | |||
v1.0 | instruct | Code_Contests | Code_Contests_31386_I | Anna and Boris are playing a game involving prime numbers. They have a list of non-negative integers and take turns picking a number from the list. Anna always moves first. The player who picks a prime number wins immediately. If no prime numbers are left to pick, the game is a draw.
Anna and Boris both play optimally... | import math
def is_prime(num):
"""
Returns True if the num is a prime number, else False.
"""
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:... | from solution import is_prime, game_result
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(10) == False
assert is_prime(17) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(97) == True
... | [
{
"docstring": "Returns True if the num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Determines the result of the game.",
"function_declaration": "def game_result(n, numbers):",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Determines if n is a prime number.\n \"\"\"\n if n < 2:\n return False\n if n == 2:\n return True\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031386",
"row_id": 31386,
"seed_ids": "[11186]"
} | 0.758417 | Code_Contests_31386 | I | [
"is_prime",
"game_result"
] | 2 | [
[
"game_result",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c1621904d5398479194dc650cd6661c89e13bbba | 63453fa271f90cd9b50d399e39f54ef420b5dbc7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31395_I | You are given an n x n grid with some cells blocked and some cells open. The task is to find the number of paths from the top-left corner of the grid to the bottom-right corner, such that you can only move right or down and you cannot pass through blocked cells. Write a function to calculate the number of such paths.
... | def count_paths(grid):
n = len(grid)
if grid[0][0] == 1 or grid[n-1][n-1] == 1:
return 0
dp = [[0] * n for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(n):
if grid[i][j] == 1:
dp[i][j] = 0
else:
if i >... | def test_parse_input():
input_str = "3\n3\n0 0 0\n0 1 0\n0 0 0\n4\n0 1 0 0\n0 0 1 0\n1 0 0 0\n0 0 0 0\n2\n0 1\n0 0"
expected_output = [
[
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
],
[
[0, 1, 0, 0],
[0, 0, 1, 0],
[1, 0, 0, 0],... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve_grids(test_cases):",
"function_name": "solve_grids",
"parameter_list": "(test_cases)"
},
... | [
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 count_paths(grid):\n n = len(grid)\n if grid[0][0] == 1 or grid[n-1][n-1] == 1:\n return 0\n \n dp = [[0] * n for _ in range(n)]\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031395",
"row_id": 31395,
"seed_ids": "[1253]"
} | 0.79667 | Code_Contests_31395 | I | [
"count_paths",
"solve_grids",
"parse_input",
"main"
] | 4 | [
[
"solve_grids",
"count_paths"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 1e5ba9f4af6dc44bd38aff0fec34e7a62e7c941a | e547a52f90094f5bf4abd007c6f42edee7a146ba | |||
v1.0 | instruct | Code_Contests | Code_Contests_31434_I | Given a list of N positive integers, you are required to partition this list into two subsets such that the sum of integers in each subset is as equal as possible. If there are multiple solutions, any valid one is acceptable. You need to output the difference between the sums of the two subsets.
Input
The first line c... | def min_subset_difference(arr):
"""
Returns the smallest possible absolute difference between the sums of two subsets.
"""
total_sum = sum(arr)
n = len(arr)
# Initialize a 2D dp array
dp = [[False for _ in range(total_sum // 2 + 1)] for _ in range(n + 1)]
# Base case: it is alw... | def test_min_subset_difference():
assert min_subset_difference([1, 6, 11, 5]) == 1
assert min_subset_difference([3, 1, 4]) == 0
assert min_subset_difference([10, 10, 10]) == 10
assert min_subset_difference([1, 2, 3, 4, 5]) == 1
assert min_subset_difference([5]) == 5
def test_edge_cases():
asser... | [
{
"docstring": "Returns the smallest possible absolute difference between the sums of two subsets.",
"function_declaration": "def min_subset_difference(arr):",
"function_name": "min_subset_difference",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def solve()... | [
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 min_subset_difference(N, arr):\n total_sum = sum(arr)\n half_sum = total_sum // 2\n \n dp = [0] * (half_sum + 1)\n \n for num in arr:... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031434",
"row_id": 31434,
"seed_ids": "[3464]"
} | 0.675815 | Code_Contests_31434 | I | [
"min_subset_difference",
"solve"
] | 2 | [
[
"solve",
"min_subset_difference"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e50f997e2b0924b110543172bcb31b55090b48f4 | 590ee6f3e46ed51bbde4c0426d83f2106a9c51de | |||
v1.0 | instruct | Code_Contests | Code_Contests_31517_I | In a dense forest, a group of friends is playing a game of hide-and-seek. The forest is represented as a 2D grid where each cell is either empty ('.') or contains a tree ('T'). One of the friends, Bob, is hiding, and his initial position is marked with a 'B'. The seeker, Alice, starts at a position marked with an 'A'. ... | from collections import deque
def can_alice_reach_bob(grid, start, end):
"""
Determines if Alice (A) can reach Bob (B) in a forest represented by a 2D grid.
Args:
grid (list of list of str): The 2D grid representing the forest.
start (tuple of int): The starting coordinates of Alice (A).
e... | def test_can_reach_bob_simple_yes():
grid = [
['A', '.', '.', 'T'],
['.', 'T', '.', '.'],
['.', '.', 'T', 'B'],
['T', 'T', 'T', 'T']
]
assert process_grid(4, 4, grid) == "YES"
def test_can_reach_bob_simple_no():
grid = [
['A', '.', 'T', '.'],
['.', 'T', '... | [
{
"docstring": "Determines if Alice (A) can reach Bob (B) in a forest represented by a 2D grid.\n\nArgs:\ngrid (list of list of str): The 2D grid representing the forest.\nstart (tuple of int): The starting coordinates of Alice (A).\nend (tuple of int): The coordinates of Bob (B).\n\nReturns:\nstr: \"YES\" if A... | [
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_alice_reach_bob(N, M, grid):\n from collections import deque\n\n # Find positions of Alice and Bob\n alice_position = None\n bob_positi... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00031517",
"row_id": 31517,
"seed_ids": "[6007]"
} | 0.67005 | Code_Contests_31517 | I | [
"can_alice_reach_bob",
"process_grid"
] | 2 | [
[
"process_grid",
"can_alice_reach_bob"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 57101f2f1d88694d01ae7e2a8464fd3ec2cb731e | 79e29b5eaf89eb70d2dbc50ace1d7bd800acfe44 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31604_I | Alice loves playing with numbers and has recently started exploring matrices. She is curious about the sum of elements in a specific submatrix. Given a matrix and multiple queries, help Alice determine the sum of elements within each specified submatrix.
Input:
The first line contains two integers, n and m (1 ≤ n, m ≤... | def preprocess_matrix(matrix):
"""
Preprocess the matrix to create a prefix sum matrix.
"""
n = len(matrix)
m = len(matrix[0])
# Create a prefix sum matrix initialized with zeros
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
# Fill the prefix sum matrix
for i in range(... | import pytest
from solution import preprocess_matrix, query_sum, matrix_sum_queries
def test_preprocess_matrix():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 6],
[0, 5, 12, 21],
[0, 12, 27, 45]
]
... | [
{
"docstring": "Preprocess the matrix to create a prefix sum matrix.",
"function_declaration": "def preprocess_matrix(matrix):",
"function_name": "preprocess_matrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Calculate the sum of the submatrix from (r1, c1) to (r2, c2) using the prefix... | [
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 precompute_matrix_sums(matrix, n, m):\n \"\"\"\n Precomputes the sum of elements for all submatrices starting from (0,0) to (i,j) and stores them... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031604",
"row_id": 31604,
"seed_ids": "[12840]"
} | 0.564936 | Code_Contests_31604 | I | [
"preprocess_matrix",
"query_sum",
"matrix_sum_queries"
] | 3 | [
[
"matrix_sum_queries",
"preprocess_matrix"
],
[
"matrix_sum_queries",
"query_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c38d6ca46f6d6d5907aff937419163654b105228 | ef18d5c66a05f32777e724342a2aadb8e284c9d3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31616_I | Alex enjoys solving puzzles and recently discovered an interesting problem involving prime numbers. He read about the Goldbach Conjecture, which asserts that every even integer greater than 2 can be expressed as the sum of two prime numbers. He's thrilled and decides to write a program that can find at least one of suc... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def find_go... | from solution import is_prime, find_goldbach_pair
def test_is_prime():
# Test known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(11) == True
# Test known non-prime numbers
assert is_prime(1) == False
assert is_prime(4) =... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns two prime numbers P1 and P2 such that E = P1 + P2.",
"function_declaration": "def find_goldb... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031616",
"row_id": 31616,
"seed_ids": "[9337]"
} | 0.689948 | Code_Contests_31616 | I | [
"is_prime",
"find_goldbach_pair"
] | 2 | [
[
"find_goldbach_pair",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7a02bd4aa5ce551b6f0ad1e2d84e359cab12433f | 7b8e1f3151321559113dd4db1a805a668924b95f | |||
v1.0 | instruct | Code_Contests | Code_Contests_31625_I | You are tasked with developing a system for managing a collection of books in a small library.
The library contains a variety of books, each identified by a unique International Standard Book Number (ISBN-10). The system must include functionalities to query the collection of books based on certain criteria and to de... | def edit_distance(s1, s2):
"""
Calculate the Levenshtein distance between two given strings s1 and s2.
"""
m, n = len(s1), len(s2)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0:
dp[i][j] = j
... | import pytest
from solution import edit_distance, find_similar_books, process_input_data
def test_edit_distance():
assert edit_distance("kitten", "sitting") == 3
assert edit_distance("flaw", "lawn") == 2
assert edit_distance("book", "back") == 2
assert edit_distance("intention", "execution") == 5
a... | [
{
"docstring": "Calculate the Levenshtein distance between two given strings s1 and s2.",
"function_declaration": "def edit_distance(s1, s2):",
"function_name": "edit_distance",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Given a list of books and an edit distance threshold, find all pai... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def edit_distance(str1, str2):\n \"\"\"\n Calculate the Levenshtein distance between two strings str1 and str2.\n \"\"\"\n m, n = len(str1), le... | trial_gpt4o_7 | {
"original_instruction": "",
"prompt_id": "00031625",
"row_id": 31625,
"seed_ids": "[12900]"
} | 0.63831 | Code_Contests_31625 | I | [
"edit_distance",
"find_similar_books",
"process_input_data"
] | 3 | [
[
"find_similar_books",
"edit_distance"
],
[
"process_input_data",
"find_similar_books"
]
] | 2 | [
"process_input_data"
] | false | [] | false | pytest | true | [] | true | 13979d88480ef239f4c86a2e0fe42a075b0242eb | 75ecd502d56ce0cf2a1f52febc0b30f53d5bc68f | |||
v1.0 | instruct | Code_Contests | Code_Contests_31652_I | You are given a grid with R rows and C columns. Each cell in the grid can be either empty (denoted by '.') or contain an obstacle (denoted by '#'). You are currently standing at the top-left corner of the grid (cell (1,1)) and you want to reach the bottom-right corner (cell (R,C)). You can move to an adjacent cell in t... | def find_path(R, C, grid):
from collections import deque
def is_valid(x, y):
return 0 <= x < R and 0 <= y < C and grid[x][y] == '.'
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
start = (0, 0)
goal = (R-1, C-1)
queue = deque([start])
visited = set([start])
parent = {star... | def test_find_path_no_obstacles():
R = 5
C = 5
grid = [
".....",
".###.",
".....",
".###.",
"....."
]
output = find_path(R, C, grid)
assert output.startswith("Yes")
def test_find_path_with_obstacles():
R = 3
C = 3
grid = [
".#.",
... | [
{
"docstring": null,
"function_declaration": "def find_path(R, C, grid):",
"function_name": "find_path",
"parameter_list": "(R, C, grid)"
},
{
"docstring": null,
"function_declaration": "def grid_path():",
"function_name": "grid_path",
"parameter_list": "()"
},
{
"docstri... | [
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_path(R, C, grid):\n from collections import deque\n\n directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n start = (0, 0)\n end = (R-1, C... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00031652",
"row_id": 31652,
"seed_ids": "[9557]"
} | 0.758569 | Code_Contests_31652 | I | [
"find_path",
"grid_path"
] | 2 | [
[
"grid_path",
"find_path"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2b94948f90dff9abbc7d6c7d80e01dd7e5ec51fe | 04c1294a7136d63416d89358e905c340d813852d | |||
v1.0 | instruct | Code_Contests | Code_Contests_31658_I | Write a program that, given a list of string pairs, finds the minimum number of steps required to transform the first string in each pair into the second string. A step consists of either inserting, deleting, or replacing a single character.
You can assume the input strings will only contain lowercase English letters.... | def minDistance(word1, word2):
"""
Given two words word1 and word2, this function returns the minimum number of operations
required to convert word1 to word2. You can insert, delete, or replace a character.
"""
m, n = len(word1), len(word2)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i i... | from solution import minimal_steps
def test_minimal_steps():
string_pairs = [
("horse", "ros"),
("intention", "execution")
]
result = minimal_steps(2, string_pairs)
assert result == [3, 5]
def test_minimal_steps_same_strings():
string_pairs = [
("abc", "abc")
]
res... | [
{
"docstring": "Given two words word1 and word2, this function returns the minimum number of operations\nrequired to convert word1 to word2. You can insert, delete, or replace a character.",
"function_declaration": "def minDistance(word1, word2):",
"function_name": "minDistance",
"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 min_steps_to_transform(str1, str2):\n \"\"\"\n Compute the minimum number of operations required to transform str1 into str2.\n An operation i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031658",
"row_id": 31658,
"seed_ids": "[11199]"
} | 0.74096 | Code_Contests_31658 | I | [
"minDistance",
"minimal_steps"
] | 2 | [
[
"minimal_steps",
"minDistance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bf60e42b9e00e4d32c4217eedfc05b50355e6e41 | 6c4c13ede72810cc023f4aefca365fe8d1f64f9f | |||
v1.0 | instruct | Code_Contests | Code_Contests_31724_I | In a forest, there is a group of N animals. Each animal is either a herbivore or a carnivore. You have a list of pairs indicating which animals are friends with each other. Your task is to decide if it is possible to assign types (herbivore or carnivore) to all animals such that no pair of friends has the same type.
I... | def is_bipartite(graph, start, color_map):
queue = [start]
color_map[start] = 0 # Start coloring with 0
while queue:
node = queue.pop(0)
for neighbor in graph[node]:
if neighbor not in color_map:
color_map[neighbor] = 1 - color_map[node]
... | from solution import can_assign_types
def test_example_cases():
T = 2
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)]),
(4, 2, [(1, 2), (2, 3)])
]
assert can_assign_types(T, test_cases) == ['NO', 'YES']
def test_single_animal():
T = 1
test_cases = [
(1, 0, [])
]
... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(graph, start, color_map):",
"function_name": "is_bipartite",
"parameter_list": "(graph, start, color_map)"
},
{
"docstring": null,
"function_declaration": "def can_assign_types(T, test_cases):",
"function_name": "can_assi... | [
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_bipartite(graph, n):\n color = [-1] * n\n \n def bfs(source):\n queue = [source]\n color[source] = 0\n \n while... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031724",
"row_id": 31724,
"seed_ids": "[11281]"
} | 0.606431 | Code_Contests_31724 | I | [
"is_bipartite",
"can_assign_types"
] | 2 | [
[
"can_assign_types",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8bf0178ec98fb2bf422afbff2a66e20d64ae8273 | d9eab3cea8654efe055d788d35d92390b6cc03db | |||
v1.0 | instruct | Code_Contests | Code_Contests_31768_I | Alex is learning about symmetricalNumbers. A number is said to be a symmetricalNumber if its digits can be rearranged to form a palindrome. A palindrome is a number that reads the same forwards and backwards.
Given a set of numbers, you need to determine if each number is a symmetricalNumber or not.
Input:
The first ... | def is_symmetrical_number(num):
"""
Determines if the number can be rearranged to form a palindrome.
"""
from collections import Counter
# Count the frequency of each digit in the number
count = Counter(num)
# A number can form a palindrome if at most one digit has an odd count
odd... | from solution import symmetrical_numbers, is_symmetrical_number
def test_is_symmetrical_number():
assert is_symmetrical_number("121") == True
assert is_symmetrical_number("12321") == True
assert is_symmetrical_number("1221") == True
assert is_symmetrical_number("123") == False
assert is_symmetrical... | [
{
"docstring": "Determines if the number can be rearranged to form a palindrome.",
"function_declaration": "def is_symmetrical_number(num):",
"function_name": "is_symmetrical_number",
"parameter_list": "(num)"
},
{
"docstring": "Given N numbers, returns a list with \"YES\" if the number is a... | [
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 Counter\n\ndef is_symmetrical_number(number):\n \"\"\"\n Determine if the digits of a given number can be rearranged to form ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031768",
"row_id": 31768,
"seed_ids": "[698]"
} | 0.65505 | Code_Contests_31768 | I | [
"is_symmetrical_number",
"symmetrical_numbers"
] | 2 | [
[
"symmetrical_numbers",
"is_symmetrical_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bdc25ab617856457a9a278c11e1f62fa619e2a55 | 0bfa3a597642be2d099f3b447af84c2d797694b9 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31773_I | You are given a permutation of the first n natural numbers, represented as an array of integers where each number from 1 to n appears exactly once. Your task is to find the cyclic configurations of this permutation. A cycle in the permutation is defined as follows:
Starting from any position i, follow the permutation ... | def find_cycles(n, permutation):
visited = [False] * n
cycles = []
for i in range(n):
if not visited[i]:
cycle = []
current = i
while not visited[current]:
visited[current] = True
cycle.append(current + 1)
... | from solution import cycles_info
def test_single_element():
assert cycles_info(1, [1]) == ["1", "1"]
def test_two_elements():
assert cycles_info(2, [2, 1]) == ["1", "1 2"]
def test_identity_permutation():
assert cycles_info(5, [1, 2, 3, 4, 5]) == ["5", "1", "2", "3", "4", "5"]
def test_example_case():
... | [
{
"docstring": null,
"function_declaration": "def find_cycles(n, permutation):",
"function_name": "find_cycles",
"parameter_list": "(n, permutation)"
},
{
"docstring": null,
"function_declaration": "def cycles_info(n, permutation):",
"function_name": "cycles_info",
"parameter_lis... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_cycles(permutation):\n \"\"\"\n Finds the cyclic configurations of the permutation.\n \n Args:\n permutation: A list of integers re... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031773",
"row_id": 31773,
"seed_ids": "[12610]"
} | 0.664985 | Code_Contests_31773 | I | [
"find_cycles",
"cycles_info"
] | 2 | [
[
"cycles_info",
"find_cycles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2bfbb6a3e781f7a0760046c7b97b432298d279aa | c17a57807a5214161553a55a2623b46ce037e3e7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31852_I | John is a software engineer who loves puzzles. Recently, he came across a unique numeric pattern and wants to replicate it using a program. The pattern consists of consecutive numbers arranged in a diamond shape within a square grid of size (2*n - 1) x (2*n - 1). Here, the integer values run horizontally, vertically, a... | def generate_grid(n):
size = 2 * n - 1
grid = [[0] * size for _ in range(size)]
for i in range(size):
for j in range(size):
grid[i][j] = n - (abs(n - 1 - i) + abs(n - 1 - j))
for i in range(size):
for j in range(size):
if grid[i][j] < 0:
grid[i][... | from solution import generate_grid
def test_generate_grid_base_case():
expected = [
[1]
]
assert generate_grid(1) == expected
def test_generate_grid_2():
expected = [
[0, 1, 0],
[1, 2, 1],
[0, 1, 0]
]
assert generate_grid(2) == expected
def test_generate_grid_3... | [
{
"docstring": null,
"function_declaration": "def generate_grid(n):",
"function_name": "generate_grid",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def print_grid(n):",
"function_name": "print_grid",
"parameter_list": "(n)"
}
] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_grid(n):\n size = 2 * n - 1\n grid = [[0] * size for _ in range(size)]\n\n for i in range(size):\n for j in range(size):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031852",
"row_id": 31852,
"seed_ids": "[4911]"
} | 0.591102 | Code_Contests_31852 | I | [
"generate_grid",
"print_grid"
] | 2 | [
[
"print_grid",
"generate_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0157ad37a5c004b4e4b76303416a4ca40af7431c | b7b51c05aa1fc7d362346fcb403a870b14fb45c7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31861_I | In a country far, far away, there are n cities connected by m two-way roads. Each road connects exactly two different cities and no two roads connect the same pair of cities. The country’s government is planning to introduce a new tax on the roads. They want to ensure that the road network remains connected after the t... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yroot]... | def test_minimum_total_tax_simple_case():
assert minimum_total_tax(4, 5, [
(1, 2, 1),
(1, 3, 2),
(1, 4, 3),
(2, 3, 4),
(3, 4, 5)
]) == 6
def test_minimum_total_tax_another_case():
assert minimum_total_tax(3, 3, [
(1, 2, 2),
(2, 3, 3),
(1, 3, 4... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minimum_total_tax(n, m, roads):\n \"\"\"\n Returns the minimum total tax the government can collect to ensure that all cities remain connected.\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031861",
"row_id": 31861,
"seed_ids": "[2850]"
} | 0.743919 | Code_Contests_31861 | I | [
"find",
"union",
"kruskal",
"minimum_total_tax"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_total_tax",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | f84b7069ef2c4e87f271450c8c8c1dd1390c7867 | 7824dfc56b8eeafd678870138921e041581ab92e | |||
v1.0 | instruct | Code_Contests | Code_Contests_31896_I | A company has decided to automate their employee report generation system. Each report contains the employee's name, age, and job title. Every day, the system generates these reports based on the data provided. However, it's critical that the reports are sorted by age, and if two or more employees have the same age, th... | def sort_employees(employee_records):
"""
Sorts the employee records first by age and then by name if ages are equal.
Args:
employee_records (list of tuples): List of employee records, where each record is a tuple containing
(name, age, job title).
... | import pytest
from solution import employee_report
def test_employee_report_basic():
input_list = [
'4',
'Alice 30 Engineer',
'Bob 25 Developer',
'Charlie 25 Designer',
'David 30 Manager'
]
expected_output = [
'Bob 25 Developer',
'Charlie 25 Designer'... | [
{
"docstring": "Sorts the employee records first by age and then by name if ages are equal.\n\nArgs:\n employee_records (list of tuples): List of employee records, where each record is a tuple containing\n (name, age, job title).\n\nReturns:\n list of tuples: Sorted 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 sort_employees(employee_list):\n \"\"\"\n Sort a list of employee records first by age, then by name if ages are equal.\n\n Parameters:\n e... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00031896",
"row_id": 31896,
"seed_ids": "[11493]"
} | 0.638854 | Code_Contests_31896 | I | [
"sort_employees",
"read_employee_data",
"format_output",
"employee_report"
] | 4 | [
[
"employee_report",
"format_output"
],
[
"employee_report",
"read_employee_data"
],
[
"employee_report",
"sort_employees"
]
] | 3 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 92b7d03e8a70bd067e77bd357405475b8e0416a6 | db0ffdf03b8e9a1cc0a0096578c9812b25ed0d04 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31956_I | Barry is fascinated by palindromic numbers and enjoys finding them in various scenarios. A palindromic number reads the same forwards and backwards. Barry is interested in finding the largest palindromic number that can be obtained by multiplying two n-digit numbers. Your task is to help Barry identify this largest pal... | def is_palindrome(number):
"""
Returns True if the given number is a palindrome, False otherwise.
"""
return str(number) == str(number)[::-1]
def largest_palindromic_product(n):
"""
Returns the largest palindromic number that is a product of two n-digit numbers.
"""
max_digit = 10 ** n ... | from solution import largest_palindromic_product
def test_largest_palindromic_product_1_digit():
assert largest_palindromic_product(1) == 9
def test_largest_palindromic_product_2_digits():
assert largest_palindromic_product(2) == 9009
def test_largest_palindromic_product_3_digits():
assert largest_palind... | [
{
"docstring": "Returns True if the given number is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns the largest palindromic number that is a product of two n-digit... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(number) == str(number)[::-1]\n\ndef largest_pali... | trial_gpt4o_8 | {
"original_instruction": "",
"prompt_id": "00031956",
"row_id": 31956,
"seed_ids": "[7036]"
} | 0.761321 | Code_Contests_31956 | I | [
"is_palindrome",
"largest_palindromic_product"
] | 2 | [
[
"largest_palindromic_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 64763c4536e643370ea4743e3196a207b3efa786 | 81dda876f6a5a5da10869bc585f193b369933425 | |||
v1.0 | instruct | Code_Contests | Code_Contests_31962_I | You are given a weighted, undirected graph with N nodes and M edges. Each edge has a positive weight. Your task is to find the Maximum Spanning Tree (MST) of this graph, which is a spanning tree with the maximum possible total edge weight.
A spanning tree of a graph is a subgraph that includes all vertices of the grap... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | def test_maximum_spanning_tree():
edges = [
(1, 2, 10),
(1, 3, 6),
(1, 4, 5),
(2, 3, 4),
(3, 4, 1)
]
assert maximum_spanning_tree(4, 5, edges) == 21
edges = [
(1, 2, 1),
(2, 3, 1),
(3, 4, 1),
(4, 5, 1),
(5, 1, 1)
]
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xr... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00031962",
"row_id": 31962,
"seed_ids": "[10045]"
} | 0.751837 | Code_Contests_31962 | I | [
"find",
"union",
"maximum_spanning_tree"
] | 3 | [
[
"maximum_spanning_tree",
"find"
],
[
"maximum_spanning_tree",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 62f045a2e7a3e9f36104c6039832f36b2a8e74a4 | 4b38779f2a40cbd8d7860764793972a5f5b7e021 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32010_I | You are given a linked list of integers. Your task is to find and return the middle element of the linked list. If the list has an even number of elements, return the second of the two middle elements.
Constraints
* The size of the linked list is at least 1 and at most 10000.
* Each element in the linked list is an i... | class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def middle_of_linked_list(head: ListNode) -> int:
"""
Returns the middle element of a linked list. If the list has an even number of elements,
returns the second of the two middle elements.
"""
slow = fast = he... | from solution import find_middle_element
def test_find_middle_element_odd():
assert find_middle_element(5, [1, 2, 3, 4, 5]) == 3
def test_find_middle_element_even():
assert find_middle_element(6, [10, 20, 30, 40, 50, 60]) == 40
def test_find_middle_element_single():
assert find_middle_element(1, [7]) == ... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef find_middle_element(n, elements):... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032010",
"row_id": 32010,
"seed_ids": "[5708]"
} | 0.568101 | Code_Contests_32010 | I | [
"middle_of_linked_list",
"create_linked_list_from_list",
"find_middle_element"
] | 3 | [
[
"find_middle_element",
"create_linked_list_from_list"
],
[
"find_middle_element",
"middle_of_linked_list"
]
] | 2 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | a949f1abf555071e4a9b91c87e8a067650fbcd8a | 619f35eb97ae44b78eeffdac288a0f0ecbb0c0f3 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32013_I | You are given a list of words. Your task is to compound these words to generate the longest possible word that contains all the given words as subsequences. A subsequence of a string is a new string generated from the original string by deleting some (can be none) of the characters without disturbing the relative posit... | def find_longest_compound_word(words):
"""
Given a list of words, rearrange and concatenate them to form the longest possible
word that contains all the given words as subsequences.
"""
# To find the longest compound word we can use all letters of all words given
# corner case for empty string
... | from solution import find_longest_compound_word
def test_example_1():
assert find_longest_compound_word(["abc", "bcd", "ace"]) == "abcde"
def test_example_2():
assert find_longest_compound_word(["xyz", "xy", "yz", "z"]) == "xyz"
def test_single_word():
assert find_longest_compound_word(["alone"]) == "alo... | [
{
"docstring": "Given a list of words, rearrange and concatenate them to form the longest possible\nword that contains all the given words as subsequences.",
"function_declaration": "def find_longest_compound_word(words):",
"function_name": "find_longest_compound_word",
"parameter_list": "(words)"
... | [
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_longest_compound_word(words):\n \"\"\"\n Given a list of words, rearrange and concatenate them to form the longest possible\n word that c... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032013",
"row_id": 32013,
"seed_ids": "[1303]"
} | 0.738109 | Code_Contests_32013 | I | [
"find_longest_compound_word",
"merge_two_words"
] | 2 | [
[
"find_longest_compound_word",
"merge_two_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ac3e6843bb117cc8a7f4571138d9a87eaf9ed96d | ab88dfcf720f2a7aa7acec3bd1657e8fd9e2af2f | |||
v1.0 | instruct | Code_Contests | Code_Contests_32086_I | Robin has an undirected, weighted graph with n nodes and m edges. The graph is represented by an edge list where each edge has a source node u, a destination node v, and a weight w. Robin is interested in finding the shortest path from node 1 to node n but with a twist: Robin can remove at most one edge from the graph ... | import heapq
def dijkstra(n, adj, src):
dist = [float('inf')] * (n + 1)
dist[src] = 0
pq = [(0, src)] # priority queue as (distance, node)
while pq:
current_dist, u = heapq.heappop(pq)
if current_dist > dist[u]:
continue
for v, weight in adj[u]:
if dist[... | def test_find_shortest_path_with_removal():
n1 = 6
m1 = 7
edges1 = [
(1, 2, 2),
(2, 3, 2),
(3, 4, 2),
(4, 5, 2),
(5, 6, 2),
(1, 3, 4),
(3, 6, 4)
]
assert find_shortest_path_with_removal(n1, m1, edges1) == 8
n2 = 5
m2 = 6
edges2... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, adj, src):",
"function_name": "dijkstra",
"parameter_list": "(n, adj, src)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_path_with_removal(n, m, edges):",
"function_name": "find_shortest_path_with_rem... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nimport sys\nfrom collections import defaultdict\n\ndef dijkstra(graph, n, start):\n distances = [sys.maxsize] * (n + 1)\n distances[sta... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032086",
"row_id": 32086,
"seed_ids": "[7927]"
} | 0.726966 | Code_Contests_32086 | I | [
"dijkstra",
"find_shortest_path_with_removal"
] | 2 | [
[
"find_shortest_path_with_removal",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | bab1cbb4efa185b47f5f2e6ba56cd62934b889a4 | 908a89857c1a84b4e0d97b026f75a904650250e5 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32103_I | In a faraway kingdom, a wise king decided to build a new road network to connect all his cities together. He wants to ensure that all cities are accessible from any other city, while minimizing the cost of constructing the roads. To achieve this, the king has hired you to help him determine the optimal road network.
T... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[r... | from solution import min_cost_to_connect_cities
def test_example_1():
n = 4
m = 5
roads = [
(1, 2, 3),
(2, 3, 1),
(3, 4, 4),
(2, 4, 2),
(1, 4, 5)
]
assert min_cost_to_connect_cities(n, m, roads) == 6
def test_example_2():
n = 3
m = 1
roads = [
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032103",
"row_id": 32103,
"seed_ids": "[4519]"
} | 0.705531 | Code_Contests_32103 | I | [
"find",
"union",
"kruskal",
"min_cost_to_connect_cities"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_cost_to_connect_cities",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | a1e16e7f9f6e765712565072e16b9e68a8cde13e | 349def4a0c253fcd32dac316ad455c087bc574f1 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32142_I | You are given a list of strings which represent binary numbers. Write a function that, for each binary number in the list, determines the maximum length of consecutive '1's. If there are multiple segments of consecutive '1's with the same maximum length, consider only one of them.
Input:
- The first line contains an ... | def max_consecutive_ones(binary_str):
"""
This function returns the maximum length of consecutive '1's in a binary string.
Parameters:
- binary_str: string, input binary string
Returns:
- int, maximum length of consecutive '1's
"""
return max(len(segment) for segment in binary_... | def test_max_consecutive_ones():
assert max_consecutive_ones("1101") == 2
assert max_consecutive_ones("111011") == 3
assert max_consecutive_ones("100001") == 1
assert max_consecutive_ones("0000000") == 0
assert max_consecutive_ones("1111111") == 7
assert max_consecutive_ones("1010101010") == 1
... | [
{
"docstring": "This function returns the maximum length of consecutive '1's in a binary string.\n\nParameters:\n- binary_str: string, input binary string\n\nReturns:\n- int, maximum length of consecutive '1's",
"function_declaration": "def max_consecutive_ones(binary_str):",
"function_name": "max_conse... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_consecutive_ones(binary_strings):\n \"\"\"\n Given a list of binary strings, return a list containing the maximum length\n of consecutive ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032142",
"row_id": 32142,
"seed_ids": "[3508]"
} | 0.729225 | Code_Contests_32142 | I | [
"max_consecutive_ones",
"process_binary_strings"
] | 2 | [
[
"process_binary_strings",
"max_consecutive_ones"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8296e63a0a5c5a203c8cd5f2ca456e68ebcc063e | f60ae07442e963c6fbbec20e0064a2883c3f1b55 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32155_I | Jasmine loves creating shapes on her n × m checkered grid. Each cell in the grid can either be green ('G') or red ('R'). She wants to make the entire grid match her favorite alternating pattern: 'GRGRGR...' in the first row, 'RGRGRG...' in the second row, 'GRGRGR...' in the third row, and so on.
Given the initial stat... | def min_recolor_operations(t, test_cases):
favorite_patterns = [[0] * t for _ in range(2)]
# Generate the two types of favorite patterns
def generate_pattern(n, m):
pattern1 = [['G' if (i + j) % 2 == 0 else 'R' for j in range(m)] for i in range(n)]
pattern2 = [['R' if (i + j) % 2 == 0 else ... | from solution import min_recolor_operations, parse_input, min_recolor_from_input
def test_example_1():
input_str = "3\n3 3\nGRG\nRGR\nGRG\n4 4\nGRGR\nRGRG\nGRGR\nRGRG\n2 3\nGGR\nRGG\n"
expected_output = "0\n0\n3"
assert min_recolor_from_input(input_str) == expected_output
def test_no_recolor_needed():
... | [
{
"docstring": null,
"function_declaration": "def min_recolor_operations(t, test_cases):",
"function_name": "min_recolor_operations",
"parameter_list": "(t, test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
... | [
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_recolor_operations(t, test_cases):\n results = []\n\n for case in test_cases:\n n, m, grid = case\n pattern1 = [[\"G\" if (i + ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032155",
"row_id": 32155,
"seed_ids": "[1892]"
} | 0.690973 | Code_Contests_32155 | I | [
"min_recolor_operations",
"parse_input",
"min_recolor_from_input"
] | 3 | [
[
"min_recolor_from_input",
"min_recolor_operations"
],
[
"min_recolor_from_input",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | f5c036538cfeb5b8cb4db198c9c201e231cc76d4 | 3feea7766095fab172af8c01323bfccf9b9692fe | |||
v1.0 | instruct | Code_Contests | Code_Contests_32220_I | Write a function to implement the Merge Sort algorithm, which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
MergeSort(A, left, right):
if left < right:
mid = (left + right) // 2
MergeSort(A, left, mid)
MergeSort(A, mid + 1, right)
... | def merge(A, left, mid, right):
# Create temporary arrays L and R holding elements A[left..mid] and A[mid+1..right]
L = A[left:mid + 1]
R = A[mid + 1:right + 1]
i, j, k = 0, 0, left
# Merge the temp arrays back into A[left..right]
while i < len(L) and j < len(R):
if L[i] <= R[j]:
... | def test_merge_sort():
from solution import sort_sequence
sequence = [5, 2, 4, 6, 1, 3]
sorted_sequence = [1, 2, 3, 4, 5, 6]
assert sort_sequence(6, sequence) == sorted_sequence
sequence = [3, 2, 1]
sorted_sequence = [1, 2, 3]
assert sort_sequence(3, sequence) == sorted_sequence
# A... | [
{
"docstring": null,
"function_declaration": "def merge(A, left, mid, right):",
"function_name": "merge",
"parameter_list": "(A, left, mid, right)"
},
{
"docstring": null,
"function_declaration": "def merge_sort(A, left, right):",
"function_name": "merge_sort",
"parameter_list": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge(A, left, mid, right):\n # Create temporary arrays L and R holding elements A[left..mid] and A[mid+1..right]\n L = A[left:mid+1]\n R = A[... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032220",
"row_id": 32220,
"seed_ids": "[10204]"
} | 0.691896 | Code_Contests_32220 | I | [
"merge",
"merge_sort",
"sort_sequence"
] | 3 | [
[
"merge_sort",
"merge"
],
[
"sort_sequence",
"merge_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 092ee7dcef9fc9093f81ad9c85dcb3c0ab0ebeef | 4fb53d18a4f7c56107fde0d30a577e3e3938f538 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32228_I | Alice loves playing with arrays and searching for hidden patterns in them. She recently came across a challenging problem. Given an array of integers, she wants to find the longest contiguous subarray that has an equal number of even and odd integers. Help Alice write a program that finds this subarray.
Input
The fir... | def find_longest_even_odd_subarray(arr):
"""
Finds the longest contiguous subarray with equal number of even and odd integers.
"""
n = len(arr)
if n == 0:
return -1, -1
# Dictionary to store the first occurrence of the difference between even and odd counts
first_occurrence = {0: -1... | from solution import find_longest_even_odd_subarray
def test_example_1():
arr = [1, 2, 3, 4, 5, 6]
assert find_longest_even_odd_subarray(arr) == (1, 6)
def test_example_2():
arr = [2, 4, 6, 8, 10]
assert find_longest_even_odd_subarray(arr) == (-1, -1)
def test_single_element_odd():
arr = [1]
... | [
{
"docstring": "Finds the longest contiguous subarray with equal number of even and odd integers.",
"function_declaration": "def find_longest_even_odd_subarray(arr):",
"function_name": "find_longest_even_odd_subarray",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declarati... | [
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 find_longest_subarray(arr):\n n = len(arr)\n prefix_sums = {0: -1}\n balance = 0\n max_length = 0\n start_index = -1\n \n for i in... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00032228",
"row_id": 32228,
"seed_ids": "[1925]"
} | 0.769111 | Code_Contests_32228 | I | [
"find_longest_even_odd_subarray",
"process_input_and_output"
] | 2 | [
[
"process_input_and_output",
"find_longest_even_odd_subarray"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e0e8b1d0c4f55ac4a35d1484a8f71f01097fdea | 401380348a98e0402941a3934028d58bdff77b32 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32232_I | A large company has networked several computers together for file sharing. One day, the employees noticed that the file sharing is incredibly slow. Upon investigation, you discovered that the slowdowns are due to multiple paths between the computers and some being far more efficient than others. To optimize the network... | import heapq
def find_minimum_spanning_tree(n, edges):
# Create adjacency list
adj = {i: [] for i in range(1, n + 1)}
for a, b, w in edges:
adj[a].append((w, b))
adj[b].append((w, a))
# Prim's algorithm to find the Minimum Spanning Tree
visited = set()
min_heap = [(0, 1)] # (co... | from solution import minimum_total_time
def test_example_case():
assert minimum_total_time(5, 6, [(1, 2, 4), (1, 3, 4), (2, 3, 2), (2, 4, 7), (3, 5, 3), (4, 5, 1)]) == 10
assert minimum_total_time(4, 2, [(1, 2, 3), (3, 4, 6)]) == -1
def test_single_connection():
assert minimum_total_time(2, 1, [(1, 2, 10)... | [
{
"docstring": null,
"function_declaration": "def find_minimum_spanning_tree(n, edges):",
"function_name": "find_minimum_spanning_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def minimum_total_time(n, m, connections):",
"function_name": "mini... | [
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 find_minimum_spanning_tree(n, edges):\n # Create adjacency list\n adj = {i: [] for i in range(1, n + 1)}\n for a, b, w in edge... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032232",
"row_id": 32232,
"seed_ids": "[5355]"
} | 0.660554 | Code_Contests_32232 | I | [
"find_minimum_spanning_tree",
"minimum_total_time"
] | 2 | [
[
"minimum_total_time",
"find_minimum_spanning_tree"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97c8606197e51bdc0ea538b47162ead9c82b7f88 | d019f2fced9f0c09c556bec78e9cf36666cf67af | |||
v1.0 | instruct | Code_Contests | Code_Contests_32236_I | Eva enjoys solving puzzles on a grid. She has an m x n grid where each cell contains either a 0 or a 1. Eva wants to identify the largest rectangle of 1's in this grid and determine its area. Help her out!
Input
The first line of input contains two integers m and n (1 ≤ m, n ≤ 1000) representing the number of rows and... | def max_histogram_area(heights):
"""
Calculate the maximum rectangle area in a histogram represented by heights.
"""
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index +... | from solution import max_rectangle_area
def test_sample_case():
grid = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0]
]
assert max_rectangle_area(grid) == 6
def test_single_row():
grid = [
[1, 1, 1, 1, 1]
]
assert max_rectangle_area... | [
{
"docstring": "Calculate the maximum rectangle area in a histogram represented by heights.",
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": "Calculate the maximum rectangle area of 1's in a b... | [
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_histogram_area(heights):\n \"\"\"\n Calculate the maximum rectangle area in a histogram represented by heights.\n \"\"\"\n stack = []\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032236",
"row_id": 32236,
"seed_ids": "[3818]"
} | 0.728892 | Code_Contests_32236 | I | [
"max_histogram_area",
"max_rectangle_area"
] | 2 | [
[
"max_rectangle_area",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fbb75d160ebf3e5b95238b7e45d8a8c7ca38d165 | ae6982ee676b8fdaa9355503ef29343c1ec075f7 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32244_I | In a distant kingdom, there are N castles (numbered 1 to N inclusive) and M bidirectional roads connecting the castles. Each road i has a repair time of Ti days to make it functional. Initially, all roads are broken due to recent attacks by dragons. The kingdom's monarch has issued a royal decree that all castles must ... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank... | def test_case_1():
input_str = """4 4
1 2 5
2 3 3
3 4 4
4 1 6"""
expected = 12
cases = parse_input(input_str)
results = minimum_time_to_connect_castles(cases)
assert results[0] == expected
def test_case_2():
input_str = """4 3
1 2 5
2 3 2
1 3 4"""
expected = -1
cases = parse_input(input... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef uni... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032244",
"row_id": 32244,
"seed_ids": "[6865]"
} | 0.718923 | Code_Contests_32244 | I | [
"find",
"union",
"kruskal",
"minimum_time_to_connect_castles",
"parse_input",
"solve"
] | 6 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_time_to_connect_castles",
"kruskal"
],
[
"solve",
"minimum_time_to_connect_castles"
],
[
"solve",
"parse_input"
],
[
"union",
"find"
]
] | 6 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 6c9c4098b6c0a2e1c3f7e73151c6241b915d3dc7 | 66ee3a30436f3f6c3c59fb10d03c81bb7f83a300 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32264_I | Tanya loves palindromic numbers. A number is considered palindromic if it reads the same backward as forward. For example, 121, 1331, and 7 are palindromic, while 123, 1221, and 466 are not.
A palindromic number is super palindromic if its decimal representation is made up of the digits 1 and 0 only. For example, 101,... | def is_super_palindromic(num):
"""
Checks if a number is super palindromic.
"""
s = str(num)
return s == s[::-1] and set(s).issubset({'0', '1'})
def next_super_palindromic(n):
"""
Finds the smallest super palindromic number greater than or equal to n.
"""
current = n
while True:... | from solution import is_super_palindromic, next_super_palindromic
def test_is_super_palindromic():
assert is_super_palindromic(101)
assert is_super_palindromic(1001)
assert is_super_palindromic(11)
assert not is_super_palindromic(121)
assert not is_super_palindromic(1331)
assert not is_super_pa... | [
{
"docstring": "Checks if a number is super palindromic.",
"function_declaration": "def is_super_palindromic(num):",
"function_name": "is_super_palindromic",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest super palindromic number greater than or equal to n.",
"function_d... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def next_super_palindromic(n):\n \"\"\"\n Returns the smallest super palindromic number that is greater than or equal to n.\n \"\"\"\n \n de... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032264",
"row_id": 32264,
"seed_ids": "[13289]"
} | 0.810484 | Code_Contests_32264 | I | [
"is_super_palindromic",
"next_super_palindromic"
] | 2 | [
[
"next_super_palindromic",
"is_super_palindromic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8fec69213775c59fda052abc342559b6bfedec4c | a5544d0a1a5d91378e327c573260f94ef739cfdc | |||
v1.0 | instruct | Code_Contests | Code_Contests_32321_I | Problem
You are given a list of $ N $ buildings in a city where each building has a certain height. There is also a list of $ M $ pairs of constraints where each constraint indicates that one building must be at least as tall as another building. The aim is to determine the minimum possible heights for all the buildin... | from collections import defaultdict, deque
def minimal_heights_sum(N, M, constraints):
def topological_sort(N, graph, in_degree):
# Queue of all nodes with no incoming edge (in_degree 0)
zero_in_degree_queue = deque([node for node in range(1, N+1) if in_degree[node] == 0])
topological_order... | def test_case_1():
input_str = "4 3\n2 1\n3 2\n4 3"
expected_output = 10
assert minimal_heights_sum_from_input(input_str) == expected_output
def test_case_2():
input_str = "5 0"
expected_output = 15
assert minimal_heights_sum_from_input(input_str) == expected_output
def test_case_3():
inpu... | [
{
"docstring": null,
"function_declaration": "def minimal_heights_sum(N, M, constraints):",
"function_name": "minimal_heights_sum",
"parameter_list": "(N, M, constraints)"
},
{
"docstring": null,
"function_declaration": "def minimal_heights_sum_from_input(input_str):",
"function_name... | [
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 min_heights_total(N, M, constraints):\n from collections import defaultdict, deque\n \n # Initialize the in-degrees and graph structure\n i... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00032321",
"row_id": 32321,
"seed_ids": "[11348]"
} | 0.70571 | Code_Contests_32321 | I | [
"minimal_heights_sum",
"minimal_heights_sum_from_input"
] | 2 | [
[
"minimal_heights_sum_from_input",
"minimal_heights_sum"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 07fb7444b4ab694fd27a7d347d4be3dd9ce5b252 | 827f3aa32dc10e3fe13d7396456cfb2f3a6fc03d | |||
v1.0 | instruct | Code_Contests | Code_Contests_32353_I | ## problem
The company XYZ provides coaching for a variety of competitive exams. To efficiently manage the coaching league, they divide students in leagues based on their scores. Each league has a fixed score range, and students scoring within this range are assigned to the respective league.
The leagues are as follo... | def recommend_league(students):
"""
Recommends the league based on total score including bonus points for each student.
Args:
students: List of tuples where each tuple contains the score and bonus points of a student.
Returns:
List of strings representing leagues for each student.
"""
... | def test_recommend_league():
assert recommend_league([(450, 50)]) == ["Silver"]
assert recommend_league([(1000, 400)]) == ["Gold"]
assert recommend_league([(2300, 100)]) == ["Diamond"]
assert recommend_league([(700, 0)]) == ["Silver"]
assert recommend_league([(1500, 0)]) == ["Platinum"]
assert r... | [
{
"docstring": "Recommends the league based on total score including bonus points for each student.\n\nArgs:\nstudents: List of tuples where each tuple contains the score and bonus points of a student.\n\nReturns:\nList of strings representing leagues for each student.",
"function_declaration": "def recomme... | [
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 recommend_league(scores_and_bonus):\n \"\"\"\n Given a list of tuples containing scores and bonus points, return the recommended league for each ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032353",
"row_id": 32353,
"seed_ids": "[4675]"
} | 0.709644 | Code_Contests_32353 | I | [
"recommend_league",
"process_student_leagues"
] | 2 | [
[
"process_student_leagues",
"recommend_league"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 64c1af447a6e5b717db5d77854a9e79c2cd951fa | bc1c13de597106403848ab35186572504b75c304 | |||
v1.0 | instruct | Code_Contests | Code_Contests_32356_I | Story
Alice is learning about prime numbers, and she finds them fascinating. To improve her programming skills, she decides to work on a problem related to prime numbers. She wants to write a program that finds all prime numbers between two given numbers A and B, inclusive. Moreover, Alice wants to know the sum of the... | def is_prime(n):
"""
Helper function to check if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import sum_of_primes
def test_prime_sum_example1():
assert sum_of_primes(1, 10) == 17
def test_prime_sum_example2():
assert sum_of_primes(20, 30) == 52
def test_prime_sum_example3():
assert sum_of_primes(14, 16) == 0
def test_prime_sum_single_prime():
assert sum_of_primes(5, 5) == 5
d... | [
{
"docstring": "Helper function to check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers between A and B (inclusive).",
"function_declaration": "def sum_of_p... | [
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 is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i... | trial_gpt4o_4 | {
"original_instruction": "",
"prompt_id": "00032356",
"row_id": 32356,
"seed_ids": "[9679]"
} | 0.662935 | Code_Contests_32356 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 69e2ee1536c7db2ddd758c1453f6e6ef1ca60d17 | da742b0303f38e312196773cc1a34c3a84c305fb | |||
v1.0 | instruct | Code_Contests | Code_Contests_32424_I | A company has a network of N employees connected via friendships. Each employee can communicate with their friends directly or through mutual friends. The company wants to find out how many distinct groups of employees there are, such that each group is connected either directly or indirectly via friendships.
Input
T... | def find_parent(parent, i):
if parent[i] == i:
return i
parent[i] = find_parent(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
root_x = find_parent(parent, x)
root_y = find_parent(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
... | def test_find_distinct_groups():
T = 2
test_cases = [
(4, 2, [(1, 2), (2, 3)]),
(5, 0, [])
]
expected_results = [2, 5]
results = count_distinct_groups(T, test_cases)
assert results == expected_results
def test_no_friendships():
T = 1
test_cases = [(5, 0, [])]
... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
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 find_parent(parent, i):\n if parent[i] == i:\n return i\n parent[i] = find_parent(parent, parent[i])\n return parent[i]\n\ndef union(pa... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032424",
"row_id": 32424,
"seed_ids": "[8019]"
} | 0.720242 | Code_Contests_32424 | I | [
"find_parent",
"union",
"count_distinct_groups"
] | 3 | [
[
"count_distinct_groups",
"find_parent"
],
[
"count_distinct_groups",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | e722691cfc4e3a398c0ef7b29813f1fe661af496 | 8b34c01efe34338c3f52482bedc70d46bdfdc34e | |||
v1.0 | instruct | Code_Contests | Code_Contests_32586_I | On a certain island, there are n cities and m bidirectional roads connecting some pairs of cities. You are given a list of potential construction projects, each characterized by the amount of gold it would take to construct that road. Despite the construction cost, the island's rulers will only allow constructing roads... | class DisjointSetUnion:
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 is_part_of_mst
def test_example_case():
n = 4
m = 4
p = 3
roads = [
(1, 2, 5),
(2, 3, 3),
(3, 4, 2),
(4, 1, 4)
]
projects = [
(1, 3, 6),
(2, 4, 1),
(3, 1, 7)
]
expected_output = ["NO", "YES", "NO"]
assert i... | [] | [
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 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_4 | {
"original_instruction": "",
"prompt_id": "00032586",
"row_id": 32586,
"seed_ids": "[343]"
} | 0.70633 | Code_Contests_32586 | I | [
"kruskal",
"is_part_of_mst"
] | 2 | [
[
"is_part_of_mst",
"kruskal"
]
] | 1 | [] | false | [
"DisjointSetUnion"
] | true | pytest | true | [] | true | 21e47eaff605a705bb414e66931e4e63c8435e7b | 517310b9e2995d77d7a52453bbbd101f94c8688f | |||
v1.0 | instruct | Code_Contests | Code_Contests_32599_I | You are given n strings consisting of lowercase English letters. Your task is to rearrange the characters of each string so that no two adjacent characters in the rearranged string are the same.
If there are multiple ways to achieve this, return any of them. If it is not possible to rearrange the string to meet the co... | from heapq import heappop, heappush
from collections import Counter
def rearrange_string(s):
"""
Rearranges the input string such that no two adjacent characters are the same.
If not possible, returns an empty string.
"""
counter = Counter(s)
max_heap = []
for char, freq in counter.ite... | from solution import rearrange_strings
def test_rearrange_strings_case1():
assert rearrange_strings(["aabb", "aaab"]) == ["abab", ""]
def test_rearrange_strings_case2():
assert rearrange_strings(["xyz", "aaa", "ab"]) == ["xyz", "", "ab"]
def test_rearrange_strings_single_char():
assert rearrange_strings(... | [
{
"docstring": "Rearranges the input string such that no two adjacent characters are the same.\nIf not possible, returns an empty string.",
"function_declaration": "def rearrange_string(s):",
"function_name": "rearrange_string",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_d... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_code_contests-i2i_50000_1739866719_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\nfrom collections import Counter\n\ndef rearrange_string(s):\n frequency = Counter(s)\n max_heap = [(-count, char) for char, count in fr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032599",
"row_id": 32599,
"seed_ids": "[9124]"
} | 0.824771 | Code_Contests_32599 | I | [
"rearrange_string",
"rearrange_strings"
] | 2 | [
[
"rearrange_strings",
"rearrange_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2124e49cb278481936b1566063737b3516bfceb0 | 0bf599ff860ffac467a483b42808361e18ec565c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.