{"id": "flatten_nested_list_903", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, non-nested list.\n \n The input `nested_list` can contain integers or other lists (which in turn\n can contain integers or other lists, and so on).\n\n Example:\n flatten_nested_list([1, [2, 3], [[4], 5]]) == [1, 2, 3, 4, 5]\n flatten_nested_list([]) == []\n flatten_nested_list([1, 2, 3]) == [1, 2, 3]\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], [[4], 5]]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([1, 2, 3]) == [1, 2, 3]", "assert flatten_nested_list([[[1]], [[2], [3, 4]], 5]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([7, [8, [9, [10]]]]) == [7, 8, 9, 10]", "assert flatten_nested_list([[], [[]], [[[]]]]) == []"], "kind": "synthetic"} {"id": "flatten_nested_list_742", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, flat list of integers.\n\n The input `nested_list` can contain integers or other lists. Each inner list\n can also contain integers or further nested lists, and so on.\n\n For example:\n flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]\n flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]\n flatten_nested_list([]) == []\n flatten_nested_list([1, [], [2, [3]]]) == [1, 2, 3]\n\n Args:\n nested_list: A list that may contain integers or other lists (nested arbitrarily deep).\n\n Returns:\n A new list containing all integers from the nested_list in the order they appear,\n but without any nesting.\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([1, [], [2, [3]]]) == [1, 2, 3]", "assert flatten_nested_list([[[1]], 2, [3, [4, 5], 6], 7]) == [1, 2, 3, 4, 5, 6, 7]", "assert flatten_nested_list([[[[[[]]]]]]) == []"], "kind": "synthetic"} {"id": "parse_key_value_string_676", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef parse_key_value_string(data_string: str) -> dict:\n \"\"\"\n Parses a string containing key-value pairs separated by newlines, \n where each key and value are separated by the first colon encountered.\n \n - Keys and values are stripped of leading/trailing whitespace.\n - Empty lines are ignored.\n - Lines without a colon are ignored.\n - If a key appears multiple times, the last value associated with that key should be used.\n \n Args:\n data_string: A multi-line string with key-value pairs.\n \n Returns:\n A dictionary mapping parsed keys to their corresponding values.\n\n Examples:\n >>> parse_key_value_string(\"\"\"\n name: John Doe\n age: 30\n city: New York\n \"\"\")\n {'name': 'John Doe', 'age': '30', 'city': 'New York'}\n\n >>> parse_key_value_string(\"\"\"\n item: Apple\n price: 1.20\n\n category: Fruit\n item: Gala Apple\n \"\"\")\n {'item': 'Gala Apple', 'price': '1.20', 'category': 'Fruit'}\n\n >>> parse_key_value_string(\"\"\"\n key_only\n :value_only\n \"\"\")\n {}\n \n >>> parse_key_value_string(\"\"\"\n key1: value1:part2\n key2 : value2\n key3:value3\n \"\"\")\n {'key1': 'value1:part2', 'key2': 'value2', 'key3': 'value3'}\n \"\"\"", "tests": ["assert parse_key_value_string(\"\"\"\nname: Alice\nage: 25\ncountry: USA\n\"\"\") == {'name': 'Alice', 'age': '25', 'country': 'USA'}", "assert parse_key_value_string(\"\"\"\nproduct: Laptop\nprice: 999.99\n\ncategory: Electronics\nproduct: Gaming PC\n\"\"\") == {'product': 'Gaming PC', 'price': '999.99', 'category': 'Electronics'}", "assert parse_key_value_string(\"\"\"\n key1 : value1 \nkey2:value2\nkey3: value3 : with colon\n\"\"\") == {'key1': 'value1', 'key2': 'value2', 'key3': 'value3 : with colon'}", "assert parse_key_value_string(\"\"\"\nno_colon_here\n:value_without_key\nkey_with_empty_value:\n\"\"\") == {'key_with_empty_value': ''}", "assert parse_key_value_string(\"\") == {}", "assert parse_key_value_string(\"\"\"\n \n \n \n\"\"\") == {}"], "kind": "synthetic"} {"id": "flatten_nested_list_555", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, non-nested list of integers.\n The order of elements should be preserved.\n\n For example:\n flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]\n flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]\n flatten_nested_list([]) == []\n flatten_nested_list([1, 2, 3]) == [1, 2, 3]\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([1, 2, 3]) == [1, 2, 3]", "assert flatten_nested_list([[], [1, [2]], [[3]]]) == [1, 2, 3]", "assert flatten_nested_list([[[[1]]]]) == [1]"], "kind": "synthetic"} {"id": "is_prime_and_sum_digits", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef is_prime_and_sum_digits(n: int) -> tuple[bool, int]:\n \"\"\"Checks if a given integer n is a prime number and also returns the sum of its digits.\n\n A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n The sum of digits is calculated for the absolute value of n.\n\n Args:\n n: An integer.\n\n Returns:\n A tuple where the first element is a boolean indicating if n is prime (True) or not (False).\n The second element is an integer representing the sum of the absolute value of n's digits.\n For n <= 1, the first element (is_prime) should be False.\n If n is negative, its primality is determined by its absolute value.\n\n Examples:\n is_prime_and_sum_digits(7) == (True, 7)\n is_prime_and_sum_digits(10) == (False, 1)\n is_prime_and_sum_digits(13) == (True, 4)\n is_prime_and_sum_digits(-17) == (True, 8)\n is_prime_and_sum_digits(1) == (False, 1)\n is_prime_and_sum_digits(0) == (False, 0)\n is_prime_and_sum_digits(2) == (True, 2)\n \"\"\"", "tests": ["assert is_prime_and_sum_digits(7) == (True, 7)", "assert is_prime_and_sum_digits(10) == (False, 1)", "assert is_prime_and_sum_digits(13) == (True, 4)", "assert is_prime_and_sum_digits(-17) == (True, 8)", "assert is_prime_and_sum_digits(1) == (False, 1)", "assert is_prime_and_sum_digits(0) == (False, 0)", "assert is_prime_and_sum_digits(2) == (True, 2)", "assert is_prime_and_sum_digits(23) == (True, 5)", "assert is_prime_and_sum_digits(25) == (False, 7)", "assert is_prime_and_sum_digits(-1) == (False, 1)", "assert is_prime_and_sum_digits(97) == (True, 16)"], "kind": "synthetic"} {"id": "find_median_sorted_arrays_686", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_median_sorted_arrays(nums1: list[int], nums2: list[int]) -> float:\n \"\"\"\n Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median\n of the two sorted arrays. The overall run time complexity should be O(log(m+n)).\n\n You may assume nums1 and nums2 cannot be both empty.\n\n Examples:\n find_median_sorted_arrays([1,3], [2]) == 2.0\n find_median_sorted_arrays([1,2], [3,4]) == 2.5\n find_median_sorted_arrays([0,0], [0,0]) == 0.0\n find_median_sorted_arrays([], [1]) == 1.0\n find_median_sorted_arrays([2], []) == 2.0\n \"\"\"", "tests": ["assert find_median_sorted_arrays([1,3], [2]) == 2.0", "assert find_median_sorted_arrays([1,2], [3,4]) == 2.5", "assert find_median_sorted_arrays([0,0], [0,0]) == 0.0", "assert find_median_sorted_arrays([], [1]) == 1.0", "assert find_median_sorted_arrays([2], []) == 2.0", "assert find_median_sorted_arrays([1,2,3,4,5], [1,2,3,4,5,6,7,8]) == 4.0", "assert find_median_sorted_arrays([100], [200]) == 150.0"], "kind": "synthetic"} {"id": "max_subarray_sum_circular", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef max_subarray_sum_circular(nums: list[int]) -> int:\n \"\"\"\n Given a circular integer array 'nums' of length 'n', return the maximum possible sum of a non-empty subarray of 'nums'.\n\n A circular array means the end-elements are connected to the beginning-elements.\n Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].\n\n A subarray may only include each element of the original 'nums' at most once.\n For example, if nums = [1,2,3], the subarray [3,1] is valid, but [3,1,2,1] is not.\n\n Example 1:\n Input: nums = [1,-2,3,-2]\n Output: 3\n Explanation: Subarray [3] has maximum sum 3.\n\n Example 2:\n Input: nums = [5,-3,5]\n Output: 10\n Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.\n\n Example 3:\n Input: nums = [-3,-2,-3]\n Output: -2\n Explanation: Subarray [-2] has maximum sum -2.\n\n Constraints:\n n == nums.length\n 1 <= n <= 3 * 10^4\n -3 * 10^4 <= nums[i] <= 3 * 10^4\n \"\"\"", "tests": ["assert max_subarray_sum_circular([1,-2,3,-2]) == 3", "assert max_subarray_sum_circular([5,-3,5]) == 10", "assert max_subarray_sum_circular([-3,-2,-3]) == -2", "assert max_subarray_sum_circular([1]) == 1", "assert max_subarray_sum_circular([-1,-2,-3,-4]) == -1", "assert max_subarray_sum_circular([1,2,3,4]) == 10", "assert max_subarray_sum_circular([1,-1,1]) == 2", "assert max_subarray_sum_circular([3,-1,2,-1]) == 4"], "kind": "synthetic"} {"id": "min_taps_to_water_garden", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef min_taps_to_water_garden(n: int, ranges: list[int]) -> int:\n \"\"\"\n You have a garden of length `n` units. There are `n + 1` taps located at points\n `[0, 1, ..., n]` along the garden. `ranges[i]` denotes that the i-th tap (at point `i`)\n can water the area `[i - ranges[i], i + ranges[i]]`. A tap can only water within\n the garden, so its effective range is clamped to `[0, n]`. If `ranges[i]` is 0,\n that tap cannot water any area.\n\n Your task is to find the minimum number of taps needed to water the whole garden,\n from point `0` to point `n`. If the garden cannot be watered completely,\n return -1.\n\n Args:\n n: The length of the garden (from 0 to n).\n ranges: A list of integers where `ranges[i]` is the reach of the tap at point `i`.\n The length of `ranges` will be `n + 1`.\n\n Returns:\n The minimum number of taps required, or -1 if the garden cannot be watered.\n\n Example:\n min_taps_to_water_garden(5, [3, 4, 1, 1, 0, 0]) == 1\n Explanation: Tap at 1 can water [1-4, 1+4] = [-3, 5]. Clamped to [0, 5].\n min_taps_to_water_garden(3, [0, 0, 0, 0]) == -1\n Explanation: No tap can water anything.\n min_taps_to_water_garden(7, [1,2,1,0,4,1,0,7]) == 2\n Explanation: Tap at 0 (range 1) covers [0,1].\n Tap at 7 (range 7) covers [0,7].\n Or tap at 4 (range 4) covers [0,8] clamped to [0,7]. One tap is enough.\n Ah, example is wrong. Let's trace it.\n Taps available: (start, end)\n 0: [0,1]\n 1: [0,3]\n 2: [1,3]\n 3: [3,3]\n 4: [0,8] -> [0,7]\n 5: [4,6]\n 6: [6,6]\n 7: [0,7]\n Greedy approach:\n Need to cover from 0. Max reach from current point 0.\n Tap 4 covers [0,7]. One tap.\n Expected output for (7, [1,2,1,0,4,1,0,7]) is 1.\n Let's use (7, [1,2,1,0,4,1,0,7]) == 1 as the example.\n \"\"\"\n", "tests": ["assert min_taps_to_water_garden(5, [3, 4, 1, 1, 0, 0]) == 1", "assert min_taps_to_water_garden(3, [0, 0, 0, 0]) == -1", "assert min_taps_to_water_garden(7, [1, 2, 1, 0, 4, 1, 0, 7]) == 1", "assert min_taps_to_water_garden(8, [4, 0, 0, 0, 0, 0, 0, 0, 4]) == 2", "assert min_taps_to_water_garden(9, [0, 5, 0, 3, 0, 0, 0, 0, 2, 0]) == 2", "assert min_taps_to_water_garden(10, [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]) == -1", "assert min_taps_to_water_garden(0, [0]) == 0", "assert min_taps_to_water_garden(1, [1,1]) == 1"], "kind": "synthetic"} {"id": "count_anagram_groups", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef count_anagram_groups(words: list[str]) -> int:\n \"\"\"\n Given a list of words, return the number of unique anagram groups.\n\n An anagram group is a set of words where all words in the set are anagrams\n of each other. Two words are anagrams if they contain the same characters\n with the same frequencies, regardless of order or case.\n\n For example:\n - ['listen', 'silent', 'inlets'] form one anagram group.\n - ['Hello', 'olleh', 'world'] form two groups: ['Hello', 'olleh'] and ['world'].\n - ['a', 'A'] are considered anagrams.\n\n All input words will consist of alphabetic characters only.\n The list of words can be empty.\n \"\"\"", "tests": ["assert count_anagram_groups(['listen', 'silent', 'inlets', 'hello', 'olleh', 'world']) == 3", "assert count_anagram_groups(['a', 'A', 'b', 'B', 'c']) == 3", "assert count_anagram_groups(['cat', 'act', 'tac']) == 1", "assert count_anagram_groups(['apple', 'banana', 'orange']) == 3", "assert count_anagram_groups(['tar', 'rat', 'art', 'star', 'rats']) == 2", "assert count_anagram_groups([]) == 0", "assert count_anagram_groups(['single']) == 1"], "kind": "synthetic"} {"id": "flatten_nested_list", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, flat list of integers.\n The input list can contain integers or other lists, which in turn can contain integers or lists, and so on.\n\n For example:\n flatten_nested_list([1, [2, 3], [[4], 5]]) == [1, 2, 3, 4, 5]\n flatten_nested_list([1, 2, 3]) == [1, 2, 3]\n flatten_nested_list([]) == []\n flatten_nested_list([[], [1]]) == [1]\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], [[4], 5]]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([1, 2, 3]) == [1, 2, 3]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([[], [1]]) == [1]", "assert flatten_nested_list([[[[[1]]]]]) == [1]", "assert flatten_nested_list([1, [2, [3, [4, 5], 6], 7], 8]) == [1, 2, 3, 4, 5, 6, 7, 8]"], "kind": "synthetic"} {"id": "rotate_matrix_clockwise_592", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_clockwise(matrix):\n \"\"\"\n Rotates a 2D square matrix 90 degrees clockwise.\n\n The matrix is represented as a list of lists. The input matrix is guaranteed to be\n non-empty and square (i.e., num_rows == num_cols).\n\n For example:\n rotate_matrix_clockwise([[1, 2],\n [3, 4]])\n should return [[3, 1],\n [4, 2]]\n\n rotate_matrix_clockwise([[1]])\n should return [[1]]\n\n rotate_matrix_clockwise([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]])\n should return [[7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]]\n \"\"\"", "tests": ["assert rotate_matrix_clockwise([[1]]) == [[1]]", "assert rotate_matrix_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]]", "assert rotate_matrix_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "assert rotate_matrix_clockwise([[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]]) == [[130, 90, 50, 10], [140, 100, 60, 20], [150, 110, 70, 30], [160, 120, 80, 40]]", "assert rotate_matrix_clockwise([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == [[0, 0, 1], [0, 1, 0], [1, 0, 0]]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a list or tuple of two integers: [start, end].\n The intervals are inclusive at both ends. For example, [1, 5] includes 1, 2, 3, 4, 5.\n\n The input list of intervals is not guaranteed to be sorted.\n\n Args:\n intervals: A list of intervals, where each interval is [start, end].\n\n Returns:\n A new list of merged, non-overlapping intervals, sorted by their start times.\n\n Examples:\n >>> merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]])\n [[1, 6], [8, 10], [15, 18]]\n >>> merge_overlapping_intervals([[1, 4], [4, 5]])\n [[1, 5]]\n >>> merge_overlapping_intervals([[1, 4], [0, 4]])\n [[0, 4]]\n >>> merge_overlapping_intervals([[1, 4], [0, 0]])\n [[0, 0], [1, 4]]\n >>> merge_overlapping_intervals([])\n []\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 0]]) == [[0, 0], [1, 4]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 5], [2, 3]]) == [[1, 5]]", "assert merge_overlapping_intervals([[6, 8], [1, 9], [2, 4], [4, 7]]) == [[1, 9]]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_205", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a list or tuple of two integers: [start, end].\n The intervals are assumed to be sorted by their start times. If not, the function\n will sort them internally. The end time is inclusive.\n\n For example, [[1, 3], [2, 6], [8, 10], [15, 18]] should merge to\n [[1, 6], [8, 10], [15, 18]].\n\n Args:\n intervals: A list of intervals, where each interval is [start, end].\n\n Returns:\n A new list of merged, non-overlapping intervals, sorted by start time.\n Returns an empty list if the input is empty.\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[6, 8], [1, 9], [2, 4], [4, 7]]) == [[1, 9]]", "assert merge_overlapping_intervals([[1, 2], [3, 4], [5, 6]]) == [[1, 2], [3, 4], [5, 6]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 10]]) == [[1, 10]]"], "kind": "synthetic"} {"id": "rotate_matrix_clockwise_461", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_clockwise(matrix):\n \"\"\"\n Rotates a 2D square matrix 90 degrees clockwise.\n\n The rotation should be performed in-place if possible (modifying the input matrix),\n but returning a new matrix is also acceptable for simplicity.\n\n For example:\n [[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]]\n\n becomes:\n [[7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]]\n\n Args:\n matrix: A list of lists representing a square matrix of integers.\n The matrix will always be non-empty and square (N x N).\n\n Returns:\n A new list of lists representing the rotated matrix.\n \"\"\"", "tests": ["assert rotate_matrix_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]]", "assert rotate_matrix_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "assert rotate_matrix_clockwise([[1]]) == [[1]]", "assert rotate_matrix_clockwise([['a', 'b'], ['c', 'd']]) == [['c', 'a'], ['d', 'b']]", "assert rotate_matrix_clockwise([[10, 20, 30, 40], [11, 21, 31, 41], [12, 22, 32, 42], [13, 23, 33, 43]]) == [[13, 12, 11, 10], [23, 22, 21, 20], [33, 32, 31, 30], [43, 42, 41, 40]]"], "kind": "synthetic"} {"id": "flatten_nested_list_948", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"Flatten a nested list of integers into a single flat list.\n\n The input `nested_list` can contain integers or other lists.\n Sub-lists can be nested to any depth.\n An empty list or a list containing only empty lists should return an empty list.\n\n Args:\n nested_list: A list potentially containing integers and other lists.\n\n Returns:\n A new list containing all integers from the nested_list in the order they appear.\n\n Examples:\n >>> flatten_nested_list([1, [2, 3], 4])\n [1, 2, 3, 4]\n >>> flatten_nested_list([1, [2, [3, 4]], 5])\n [1, 2, 3, 4, 5]\n >>> flatten_nested_list([])\n []\n >>> flatten_nested_list([[], [[]]])\n []\n >>> flatten_nested_list([1, [], [2, [3, []]], 4])\n [1, 2, 3, 4]\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([[], [[]]]) == []", "assert flatten_nested_list([1, [], [2, [3, []]], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([[[1]], 2, [3, [4, [5]]]]) == [1, 2, 3, 4, 5]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_975", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a tuple (start, end), where start <= end.\n The input list is not necessarily sorted.\n\n For example:\n merge_overlapping_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]\n merge_overlapping_intervals([(1, 4), (4, 5)]) == [(1, 5)]\n merge_overlapping_intervals([(6, 8), (1, 9), (2, 4), (4, 7)]) == [(1, 9)]\n merge_overlapping_intervals([]) == []\n \"\"\"", "tests": ["assert merge_overlapping_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]", "assert merge_overlapping_intervals([(1, 4), (4, 5)]) == [(1, 5)]", "assert merge_overlapping_intervals([(6, 8), (1, 9), (2, 4), (4, 7)]) == [(1, 9)]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([(1, 2), (3, 4), (5, 6)]) == [(1, 2), (3, 4), (5, 6)]", "assert merge_overlapping_intervals([(1, 10), (2, 3), (4, 5), (6, 7)]) == [(1, 10)]"], "kind": "synthetic"} {"id": "count_word_frequencies_295", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef count_word_frequencies(text: str) -> dict[str, int]:\n \"\"\"\n Counts the frequency of each word in a given text. Words are case-insensitive\n and the function should return frequencies in lowercase. Punctuation marks\n (periods, commas, exclamation points, question marks, semicolons, colons)\n should be removed from words before counting. Words are separated by spaces.\n\n For example:\n count_word_frequencies(\"Hello world! This is a test. Hello again.\")\n should return:\n {'hello': 2, 'world': 1, 'this': 1, 'is': 1, 'a': 1, 'test': 1, 'again': 1}\n \"\"\"", "tests": ["assert count_word_frequencies(\"Hello world! This is a test. Hello again.\") == {'hello': 2, 'world': 1, 'this': 1, 'is': 1, 'a': 1, 'test': 1, 'again': 1}", "assert count_word_frequencies(\"Python is fun. Python is powerful!\") == {'python': 2, 'is': 2, 'fun': 1, 'powerful': 1}", "assert count_word_frequencies(\"A B C a b c.\") == {'a': 2, 'b': 2, 'c': 2}", "assert count_word_frequencies(\"SingleWord\") == {'singleword': 1}", "assert count_word_frequencies(\"\") == {}", "assert count_word_frequencies(\" Multiple spaces here! \") == {'multiple': 1, 'spaces': 1, 'here': 1}"], "kind": "synthetic"} {"id": "rotate_matrix_90_clockwise_190", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a given square matrix 90 degrees clockwise in-place.\n\n The matrix is represented as a list of lists. The input matrix is guaranteed\n to be square (number of rows equals number of columns) and non-empty.\n The rotation should be performed without creating a new matrix to store\n the result (i.e., modify the input matrix directly).\n\n For example:\n If matrix = [[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]]\n After rotation, matrix should become:\n [[7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]]\n\n Args:\n matrix: A list of lists representing the square matrix.\n The matrix will be modified directly.\n \"\"\"", "tests": ["matrix1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; rotate_matrix_90_clockwise(matrix1); assert matrix1 == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "matrix2 = [[1]]; rotate_matrix_90_clockwise(matrix2); assert matrix2 == [[1]]", "matrix3 = [[1, 2], [3, 4]]; rotate_matrix_90_clockwise(matrix3); assert matrix3 == [[3, 1], [4, 2]]", "matrix4 = [[5, 1, 9, 11], [2, 4, 8, 10], [13, 3, 6, 7], [15, 14, 12, 16]]; rotate_matrix_90_clockwise(matrix4); assert matrix4 == [[15, 13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7, 10, 11]]", "matrix5 = []; rotate_matrix_90_clockwise(matrix5); assert matrix5 == []", "matrix6 = [[10, 20, 30, 40, 50], [1, 2, 3, 4, 5], [11, 12, 13, 14, 15], [21, 22, 23, 24, 25], [31, 32, 33, 34, 35]]; rotate_matrix_90_clockwise(matrix6); assert matrix6 == [[31, 21, 11, 1, 10], [32, 22, 12, 2, 20], [33, 23, 13, 3, 30], [34, 24, 14, 4, 40], [35, 25, 15, 5, 50]]"], "kind": "synthetic"} {"id": "find_peak_elements_386", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_peak_elements(arr):\n \"\"\"\n Given a 0-indexed integer array 'arr', find all peak elements and return their indices in a list.\n\n A peak element is an element that is strictly greater than its neighbors.\n If an element has only one neighbor (e.g., the first or last element), it is considered\n a peak if it is strictly greater than its single neighbor.\n\n For example:\n - In [1, 2, 3, 1], 3 is a peak element because 3 > 2 and 3 > 1. Its index is 2.\n - In [1, 2, 1, 3, 5, 6, 4], 2 is a peak (index 1), 6 is a peak (index 5).\n\n The returned list of indices should be sorted in ascending order.\n If no peak elements are found, return an empty list.\n\n Args:\n arr (list[int]): A list of integers.\n\n Returns:\n list[int]: A list of indices of all peak elements, sorted in ascending order.\n \"\"\"", "tests": ["assert find_peak_elements([1, 2, 3, 1]) == [2]", "assert find_peak_elements([1, 2, 1, 3, 5, 6, 4]) == [1, 5]", "assert find_peak_elements([1, 2, 3, 4, 5]) == [4]", "assert find_peak_elements([5, 4, 3, 2, 1]) == [0]", "assert find_peak_elements([1, 1, 1, 1]) == []", "assert find_peak_elements([]) == []", "assert find_peak_elements([7]) == [0]", "assert find_peak_elements([1, 3, 2, 4, 1, 5, 2]) == [1, 3, 5]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_984", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Given a list of intervals, merge all overlapping intervals and return a new list\n of non-overlapping intervals that cover all intervals in the input.\n\n Each interval is represented as a list or tuple of two integers: [start, end].\n The start of an interval will always be less than or equal to its end.\n\n For example:\n merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]])\n should return [[1, 6], [8, 10], [15, 18]]\n\n merge_overlapping_intervals([[1, 4], [4, 5]])\n should return [[1, 5]]\n\n merge_overlapping_intervals([[1, 4], [0, 4]])\n should return [[0, 4]]\n\n merge_overlapping_intervals([[1, 4], [0, 0]])\n should return [[0, 0], [1, 4]]\n\n Args:\n intervals: A list of intervals, where each interval is [start, end].\n\n Returns:\n A new list of merged, non-overlapping intervals, sorted by start time.\n If the input list is empty, return an empty list.\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 0]]) == [[0, 0], [1, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 1]]) == [[0, 4]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 2], [3, 4], [5, 6]]) == [[1, 2], [3, 4], [5, 6]]", "assert merge_overlapping_intervals([[1, 10], [2, 3], [4, 5]]) == [[1, 10]]", "assert merge_overlapping_intervals([[2, 3], [4, 5], [1, 10]]) == [[1, 10]]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_613", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a list or tuple of two integers: [start, end].\n The intervals are inclusive at the start and end. For example, [1, 3] includes 1, 2, and 3.\n\n The output list should be sorted by the start of each interval.\n\n Args:\n intervals: A list of intervals, e.g., [[1, 3], [2, 6], [8, 10], [15, 18]].\n\n Returns:\n A new list of merged, non-overlapping intervals, sorted by start.\n If the input list is empty, an empty list should be returned.\n\n Examples:\n merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]\n merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]\n merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]\n merge_overlapping_intervals([[1, 4], [0, 0]]) == [[0, 0], [1, 4]]\n merge_overlapping_intervals([]) == []\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 0]]) == [[0, 0], [1, 4]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 2], [3, 4], [5, 6]]) == [[1, 2], [3, 4], [5, 6]]", "assert merge_overlapping_intervals([[1, 5], [2, 3]]) == [[1, 5]]", "assert merge_overlapping_intervals([[10, 20], [1, 5], [3, 7], [25, 30]]) == [[1, 7], [10, 20], [25, 30]]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_988", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a tuple (start, end), where start <= end.\n The input list is not necessarily sorted.\n\n For example:\n merge_overlapping_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]\n merge_overlapping_intervals([(1, 4), (4, 5)]) == [(1, 5)]\n merge_overlapping_intervals([(6, 8), (1, 9), (2, 4), (4, 7)]) == [(1, 9)]\n \"\"\"", "tests": ["assert merge_overlapping_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]", "assert merge_overlapping_intervals([(1, 4), (4, 5)]) == [(1, 5)]", "assert merge_overlapping_intervals([(6, 8), (1, 9), (2, 4), (4, 7)]) == [(1, 9)]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([(1, 2), (3, 4), (5, 6)]) == [(1, 2), (3, 4), (5, 6)]", "assert merge_overlapping_intervals([(1, 10), (2, 3), (4, 5), (6, 7)]) == [(1, 10)]", "assert merge_overlapping_intervals([(5, 7), (1, 3), (2, 4)]) == [(1, 4), (5, 7)]"], "kind": "synthetic"} {"id": "count_word_frequencies_619", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef count_word_frequencies(text: str) -> dict[str, int]:\n \"\"\"\n Counts the frequency of each word in a given text, ignoring case and punctuation.\n \n Words are defined as sequences of alphabetic characters. All words should be\n converted to lowercase before counting. Punctuation and spaces should be\n treated as delimiters. Empty strings or strings with only non-alphabetic characters\n should result in an empty dictionary.\n\n Args:\n text: The input string.\n\n Returns:\n A dictionary where keys are lowercase words and values are their frequencies.\n\n Examples:\n >>> count_word_frequencies(\"Hello world, hello!\")\n {'hello': 2, 'world': 1}\n >>> count_word_frequencies(\"A quick brown fox jumped over the lazy dog.\")\n {'a': 1, 'quick': 1, 'brown': 1, 'fox': 1, 'jumped': 1, 'over': 1, 'the': 1, 'lazy': 1, 'dog': 1}\n >>> count_word_frequencies(\"Python is fun. Is Python easy?\")\n {'python': 2, 'is': 2, 'fun': 1, 'easy': 1}\n >>> count_word_frequencies(\" \")\n {}\n >>> count_word_frequencies(\"123 !@#\")\n {}\n \"\"\"", "tests": ["assert count_word_frequencies(\"Hello world, hello!\") == {'hello': 2, 'world': 1}", "assert count_word_frequencies(\"A quick brown fox jumped over the lazy dog.\") == {'a': 1, 'quick': 1, 'brown': 1, 'fox': 1, 'jumped': 1, 'over': 1, 'the': 1, 'lazy': 1, 'dog': 1}", "assert count_word_frequencies(\"Python is fun. Is Python easy?\") == {'python': 2, 'is': 2, 'fun': 1, 'easy': 1}", "assert count_word_frequencies(\" \") == {}", "assert count_word_frequencies(\"123 !@#\") == {}", "assert count_word_frequencies(\"ONE, two. One more time! TWO\") == {'one': 2, 'two': 2, 'more': 1, 'time': 1}"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_252", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a list or tuple of two integers: [start, end].\n The intervals are assumed to be sorted by their start times. If not sorted, the\n function should sort them internally. An empty list of intervals should return\n an empty list.\n\n For example:\n merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]\n merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]\n merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]\n merge_overlapping_intervals([[1, 4], [0, 1]]) == [[0, 4]]\n\n Args:\n intervals: A list of intervals, where each interval is [start, end].\n\n Returns:\n A new list of merged, non-overlapping intervals.\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 1]]) == [[0, 4]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 5], [2, 3], [6, 8], [7, 9]]) == [[1, 5], [6, 9]]", "assert merge_overlapping_intervals([[6, 8], [1, 9], [2, 4], [4, 7]]) == [[1, 9]]"], "kind": "synthetic"} {"id": "is_prime_factorable", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef is_prime_factorable(n, prime_factors):\n \"\"\"\n Checks if a positive integer 'n' can be formed by multiplying only the given 'prime_factors'.\n Each prime factor in 'prime_factors' can be used multiple times.\n If 'n' is 1, it is considered factorable if 'prime_factors' is not empty (representing the empty product).\n If 'n' is 1 and 'prime_factors' is empty, it returns False.\n\n Args:\n n (int): The positive integer to check (n >= 1).\n prime_factors (list): A list of unique prime numbers (integers > 1) allowed for factorization.\n The list may be empty.\n\n Returns:\n bool: True if 'n' can be formed by multiplying elements from 'prime_factors', False otherwise.\n Returns False if any element in 'prime_factors' is not prime.\n Returns False if any element in 'prime_factors' is not unique.\n \"\"\"", "tests": ["assert is_prime_factorable(12, [2, 3]) == True", "assert is_prime_factorable(30, [2, 3, 5]) == True", "assert is_prime_factorable(7, [2, 3]) == False", "assert is_prime_factorable(1, [2, 3]) == True", "assert is_prime_factorable(1, []) == False", "assert is_prime_factorable(10, [2, 5, 5]) == False", "assert is_prime_factorable(10, [2, 5]) == True", "assert is_prime_factorable(12, [2, 3, 7]) == True", "assert is_prime_factorable(35, [5, 7]) == True", "assert is_prime_factorable(36, [2, 3]) == True", "assert is_prime_factorable(36, [2]) == False", "assert is_prime_factorable(27, [3]) == True", "assert is_prime_factorable(27, [2, 3]) == True", "assert is_prime_factorable(100, [2, 5]) == True", "assert is_prime_factorable(100, [2, 3, 5]) == True", "assert is_prime_factorable(100, [3, 5]) == False", "assert is_prime_factorable(4, [2]) == True", "assert is_prime_factorable(4, [2, 2]) == False", "assert is_prime_factorable(13, [2, 3, 5, 7, 11]) == False", "assert is_prime_factorable(0, [2]) == False", "assert is_prime_factorable(10, [2, 4]) == False", "assert is_prime_factorable(10, [2, -5]) == False", "assert is_prime_factorable(10, [2, 1]) == False", "assert is_prime_factorable(10, [2, 3, 5, 7]) == True"], "kind": "synthetic"} {"id": "rotate_matrix_90_clockwise_345", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a 2D square matrix (list of lists) 90 degrees clockwise in-place.\n\n The matrix is guaranteed to be non-empty and have `n` rows and `n` columns\n (i.e., it's a square matrix). The elements can be any type.\n\n Example:\n If matrix = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n ]\n After rotation, matrix should become:\n [\n [7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]\n ]\n\n This function modifies the input matrix directly and does not return anything.\n \"\"\"", "tests": ["matrix1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; rotate_matrix_90_clockwise(matrix1); assert matrix1 == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "matrix2 = [[1]]; rotate_matrix_90_clockwise(matrix2); assert matrix2 == [[1]]", "matrix3 = [[5, 1], [2, 3]]; rotate_matrix_90_clockwise(matrix3); assert matrix3 == [[2, 5], [3, 1]]", "matrix4 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; rotate_matrix_90_clockwise(matrix4); assert matrix4 == [[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]]", "matrix5 = [['a', 'b'], ['c', 'd']]; rotate_matrix_90_clockwise(matrix5); assert matrix5 == [['c', 'a'], ['d', 'b']]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_957", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Given a list of intervals, merge all overlapping intervals and return a list of the merged intervals.\n\n An interval is represented as a list or tuple of two integers [start, end].\n For example, [[1, 3], [2, 6], [8, 10], [15, 18]] should become [[1, 6], [8, 10], [15, 18]].\n\n If an interval [a, b] overlaps with [c, d], where a <= b and c <= d,\n they can be merged into [min(a, c), max(b, d)].\n\n The input list of intervals is not necessarily sorted.\n\n Args:\n intervals: A list of lists/tuples, where each inner list/tuple contains two integers [start, end].\n Assume start <= end for all given intervals.\n\n Returns:\n A list of merged intervals, sorted by their start times.\n If the input list is empty, an empty list should be returned.\n\n Examples:\n merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]\n merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]\n merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]\n merge_overlapping_intervals([[1, 4], [0, 0]]) == [[0, 0], [1, 4]]\n merge_overlapping_intervals([[1, 4], [0, 1]]) == [[0, 4]]\n merge_overlapping_intervals([]) == []\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 0]]) == [[0, 0], [1, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 1]]) == [[0, 4]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 2], [3, 4], [5, 6]]) == [[1, 2], [3, 4], [5, 6]]", "assert merge_overlapping_intervals([[0, 10], [1, 5], [2, 7]]) == [[0, 10]]"], "kind": "synthetic"} {"id": "find_peak_elements_217", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_peak_elements(nums):\n \"\"\"\n Given a 0-indexed integer array 'nums', find all the peak elements and return their values\n in a list, sorted in ascending order. A peak element is an element that is strictly greater\n than its neighbors. If an element has only one neighbor (i.e., it's an edge element),\n it is considered a peak if it is strictly greater than its single neighbor.\n\n The array 'nums' can contain duplicate numbers, but the peak condition still requires\n strict inequality. An empty input array should return an empty list.\n\n Examples:\n find_peak_elements([1,2,3,1]) == [3]\n find_peak_elements([1,2,1,3,5,6,4]) == [2, 6]\n find_peak_elements([5]) == [5]\n find_peak_elements([1,1,1]) == []\n find_peak_elements([3,2,1]) == [3]\n find_peak_elements([1,2,3]) == [3]\n \"\"\"", "tests": ["assert find_peak_elements([1,2,3,1]) == [3]", "assert find_peak_elements([1,2,1,3,5,6,4]) == [2, 6]", "assert find_peak_elements([5]) == [5]", "assert find_peak_elements([1,1,1]) == []", "assert find_peak_elements([3,2,1]) == [3]", "assert find_peak_elements([1,2,3]) == [3]", "assert find_peak_elements([]) == []", "assert find_peak_elements([10,20,15,2,23,90,67]) == [20, 90]"], "kind": "synthetic"} {"id": "flatten_nested_list_209", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, one-dimensional list.\n\n The input `nested_list` can contain integers or other lists. These inner lists\n can in turn contain integers or further nested lists, and so on.\n\n Example:\n flatten_nested_list([1, [2, 3], [[4], 5]]) == [1, 2, 3, 4, 5]\n flatten_nested_list([]) == []\n flatten_nested_list([1, 2, 3]) == [1, 2, 3]\n flatten_nested_list([[1], [[2, 3]], [[4, [5]]]]) == [1, 2, 3, 4, 5]\n\n Args:\n nested_list: A list potentially containing integers and other lists.\n\n Returns:\n A new list containing all integers from the nested_list, in the order\n they appear when flattened from left to right.\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], [[4], 5]]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([1, 2, 3]) == [1, 2, 3]", "assert flatten_nested_list([[1], [[2, 3]], [[4, [5]]]]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([[[[1]]]]) == [1]", "assert flatten_nested_list([[], [1, []], [[2, [3, []]]]]) == [1, 2, 3]"], "kind": "synthetic"} {"id": "find_median_sorted_arrays_493", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_median_sorted_arrays(nums1: list[int], nums2: list[int]) -> float:\n \"\"\"\n Given two sorted arrays nums1 and nums2 of size m and n respectively,\n return the median of the two sorted arrays.\n\n The overall run time complexity should be O(log(m+n)).\n\n You may assume nums1 and nums2 cannot be both empty.\n \"\"\"", "tests": ["assert find_median_sorted_arrays([1, 3], [2]) == 2.0", "assert find_median_sorted_arrays([1, 2], [3, 4]) == 2.5", "assert find_median_sorted_arrays([0, 0], [0, 0]) == 0.0", "assert find_median_sorted_arrays([], [1]) == 1.0", "assert find_median_sorted_arrays([2], []) == 2.0", "assert find_median_sorted_arrays([1, 5, 8, 10], [2, 3, 6, 7]) == 5.5"], "kind": "synthetic"} {"id": "flatten_nested_list_947", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, non-nested list of integers.\n The input list can contain integers or other lists (which in turn can contain integers or lists, and so on).\n\n For example:\n flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]\n flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]\n flatten_nested_list([]) == []\n flatten_nested_list([1, 2, 3]) == [1, 2, 3]\n flatten_nested_list([[]]) == []\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([1, 2, 3]) == [1, 2, 3]", "assert flatten_nested_list([[], [1, []], [[2, 3], 4]]) == [1, 2, 3, 4]", "assert flatten_nested_list([[[[[1]]]]]) == [1]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_786", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a tuple (start, end), where start <= end.\n The input list is not necessarily sorted.\n\n For example:\n merge_overlapping_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]\n merge_overlapping_intervals([(1, 4), (4, 5)]) == [(1, 5)]\n merge_overlapping_intervals([(6, 8), (1, 9), (2, 4), (4, 7)]) == [(1, 9)]\n merge_overlapping_intervals([]) == []\n\n Args:\n intervals: A list of tuples, where each tuple (start, end) represents an interval.\n\n Returns:\n A new list of non-overlapping intervals, sorted by their start times.\n \"\"\"", "tests": ["assert merge_overlapping_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]", "assert merge_overlapping_intervals([(1, 4), (4, 5)]) == [(1, 5)]", "assert merge_overlapping_intervals([(6, 8), (1, 9), (2, 4), (4, 7)]) == [(1, 9)]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([(1, 5), (2, 3)]) == [(1, 5)]", "assert merge_overlapping_intervals([(1, 2), (3, 4), (5, 6)]) == [(1, 2), (3, 4), (5, 6)]"], "kind": "synthetic"} {"id": "parse_key_value_string_942", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef parse_key_value_string(data_string: str) -> dict:\n \"\"\"\n Parses a string containing key-value pairs separated by newlines.\n Each key-value pair is separated by the first occurrence of an equals sign ('=').\n \n Keys and values should be stripped of leading/trailing whitespace.\n Empty lines or lines without an equals sign should be ignored.\n If a key appears multiple times, the last value associated with that key should be used.\n\n Args:\n data_string: A multi-line string where each line potentially contains a key=value pair.\n\n Returns:\n A dictionary where keys and values are strings, representing the parsed data.\n If data_string is empty or contains no valid pairs, an empty dictionary is returned.\n\n Examples:\n >>> parse_key_value_string(\"key1=value1\\nkey2 = value2\\nkey3 = another value\")\n {'key1': 'value1', 'key2': 'value2', 'key3': 'another value'}\n >>> parse_key_value_string(\" k = v \\n empty line \\n k=new_v \")\n {'k': 'new_v'}\n >>> parse_key_value_string(\"no_equals_sign\\nkey=value\")\n {'key': 'value'}\n >>> parse_key_value_string(\"\")\n {}\n \"\"\"", "tests": ["assert parse_key_value_string(\"key1=value1\\nkey2 = value2\\nkey3 = another value\") == {'key1': 'value1', 'key2': 'value2', 'key3': 'another value'}", "assert parse_key_value_string(\" k = v \\n empty line \\n k=new_v \") == {'k': 'new_v'}", "assert parse_key_value_string(\"no_equals_sign\\nkey=value\\n another_key = value with spaces\") == {'key': 'value', 'another_key': 'value with spaces'}", "assert parse_key_value_string(\"\") == {}", "assert parse_key_value_string(\"only_invalid_lines\\n no_eq \\n=just_value\") == {}", "assert parse_key_value_string(\"a=1\\nb=2\\na=3\\nc=4\") == {'a': '3', 'b': '2', 'c': '4'}", "assert parse_key_value_string(\" \\n \\n key=value \\n \") == {'key': 'value'}"], "kind": "synthetic"} {"id": "sum_of_divisors_920", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Calculates the sum of all positive divisors of a given positive integer n.\n A divisor of n is an integer that divides n without leaving a remainder.\n For example, the divisors of 6 are 1, 2, 3, and 6, so their sum is 1 + 2 + 3 + 6 = 12.\n\n The input n will always be a positive integer (n >= 1).\n\n Args:\n n: A positive integer.\n\n Returns:\n The sum of all positive divisors of n.\n \"\"\"", "tests": ["assert sum_of_divisors(1) == 1", "assert sum_of_divisors(6) == 12", "assert sum_of_divisors(7) == 8", "assert sum_of_divisors(10) == 18", "assert sum_of_divisors(28) == 56", "assert sum_of_divisors(100) == 217"], "kind": "synthetic"} {"id": "sum_of_divisors_202", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Calculates the sum of all positive divisors of a given positive integer n.\n A divisor of n is an integer that divides n without leaving a remainder.\n For example, the divisors of 6 are 1, 2, 3, and 6. Their sum is 1 + 2 + 3 + 6 = 12.\n\n The input n will always be a positive integer (n >= 1).\n\n Args:\n n: A positive integer.\n\n Returns:\n The sum of all positive divisors of n.\n \"\"\"", "tests": ["assert sum_of_divisors(1) == 1", "assert sum_of_divisors(6) == 12", "assert sum_of_divisors(7) == 8", "assert sum_of_divisors(10) == 18", "assert sum_of_divisors(12) == 28", "assert sum_of_divisors(100) == 217"], "kind": "synthetic"} {"id": "flatten_nested_list_378", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"Flattens a deeply nested list of integers into a single, one-dimensional list.\n\n The input list can contain integers or other lists, which in turn can contain\n integers or other lists, and so on. Empty lists or lists containing only empty\n lists should result in an empty flattened list.\n\n Args:\n nested_list: A list potentially containing integers and other lists.\n\n Returns:\n A new list containing all integers from the nested_list in the order they\n appear, but without any nested structure.\n\n Examples:\n flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]\n flatten_nested_list([1, [2, [3, 4], 5], 6]) == [1, 2, 3, 4, 5, 6]\n flatten_nested_list([]) == []\n flatten_nested_list([[], [[]]]) == []\n flatten_nested_list([1, [], [2, [3]], 4]) == [1, 2, 3, 4]\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([1, [2, [3, 4], 5], 6]) == [1, 2, 3, 4, 5, 6]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([[], [[]], 7, [[8, []]], 9]) == [7, 8, 9]", "assert flatten_nested_list([[[[1]]], 2, [3, [4, [5]]]]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([10]) == [10]"], "kind": "synthetic"} {"id": "parse_key_value_string_616", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef parse_key_value_string(data_string: str) -> dict:\n \"\"\"\n Parses a string containing key-value pairs separated by newlines.\n Each key-value pair is separated by an equals sign ('=').\n \n Keys and values are stripped of leading/trailing whitespace.\n Empty lines are ignored. Lines that do not contain an equals sign\n are also ignored.\n \n If a key appears multiple times, the last encountered value for that\n key should be stored.\n\n Example:\n parse_key_value_string(\"\"\"\n key1=value1\n key2 = value2 with spaces\n \n key3= value3\n key1=new_value1\n invalid line\n \"\"\")\n # Expected: {'key1': 'new_value1', 'key2': 'value2 with spaces', 'key3': 'value3'}\n \"\"\"", "tests": ["assert parse_key_value_string(\"key1=value1\\nkey2=value2\") == {'key1': 'value1', 'key2': 'value2'}", "assert parse_key_value_string(\"key1 = value1\\n key2= value2 with spaces \") == {'key1': 'value1', 'key2': 'value2 with spaces'}", "assert parse_key_value_string(\"\\nkey1=val1\\n\\nkey2=val2\\n\") == {'key1': 'val1', 'key2': 'val2'}", "assert parse_key_value_string(\"key1=initial\\nkey2=second\\nkey1=final\") == {'key1': 'final', 'key2': 'second'}", "assert parse_key_value_string(\"no_equals_sign\\nkey=value\\nanother_bad_line\") == {'key': 'value'}", "assert parse_key_value_string(\"\") == {}", "assert parse_key_value_string(\" \\n \\n \") == {}"], "kind": "synthetic"} {"id": "rotate_matrix_90_clockwise_874", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a 2D square matrix 90 degrees clockwise.\n\n The rotation should be performed in-place if possible (or effectively so by returning a new matrix).\n The input matrix is guaranteed to be square (N x N) and non-empty.\n\n For example:\n [[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]]\n becomes\n [[7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]]\n\n Args:\n matrix: A list of lists representing a square matrix of integers.\n\n Returns:\n A new list of lists representing the rotated matrix.\n \"\"\"", "tests": ["assert rotate_matrix_90_clockwise([[1]]) == [[1]]", "assert rotate_matrix_90_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]]", "assert rotate_matrix_90_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "assert rotate_matrix_90_clockwise([[5, 1, 9, 11], [2, 4, 8, 10], [13, 3, 6, 7], [15, 14, 12, 16]]) == [[15, 13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7, 10, 11]]", "assert rotate_matrix_90_clockwise([[10, 20, 30, 40, 50], [1, 2, 3, 4, 5], [11, 12, 13, 14, 15], [21, 22, 23, 24, 25], [31, 32, 33, 34, 35]]) == [[31, 21, 11, 1, 10], [32, 22, 12, 2, 20], [33, 23, 13, 3, 30], [34, 24, 14, 4, 40], [35, 25, 15, 5, 50]]"], "kind": "synthetic"} {"id": "count_word_frequencies_220", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef count_word_frequencies(text_corpus: list[str]) -> dict[str, int]:\n \"\"\"\n Counts the frequency of each unique word across a list of text documents.\n\n The function should process a list of strings, where each string represents a document.\n Words should be case-insensitive (e.g., \"The\" and \"the\" count as the same word).\n Punctuation (e.g., periods, commas, exclamation marks, question marks, colons, semicolons)\n should be removed from words before counting. Hyphenated words (e.g., \"self-contained\")\n should be treated as two separate words if the hyphen is surrounded by letters,\n otherwise the hyphen should be removed (e.g., \"end-.\" becomes \"end\").\n Numbers should also be treated as words.\n\n Args:\n text_corpus: A list of strings, where each string is a document.\n\n Returns:\n A dictionary where keys are lowercase words and values are their total counts\n across all documents.\n\n Examples:\n >>> count_word_frequencies([\"Hello world.\", \"World is great!\"])\n {'hello': 1, 'world': 2, 'is': 1, 'great': 1}\n >>> count_word_frequencies([\"One, two-three.\", \"Two (two) again.\"])\n {'one': 1, 'two': 3, 'three': 1, 'again': 1}\n >>> count_word_frequencies([\"Python is fun-tastic.\", \"Fun-tastic is it?\"])\n {'python': 1, 'is': 2, 'fun': 2, 'tastic': 2, 'it': 1}\n \"\"\"", "tests": ["assert count_word_frequencies([\"Hello world.\", \"World is great!\"]) == {'hello': 1, 'world': 2, 'is': 1, 'great': 1}", "assert count_word_frequencies([\"One, two-three.\", \"Two (two) again.\"]) == {'one': 1, 'two': 3, 'three': 1, 'again': 1}", "assert count_word_frequencies([\"Python is fun-tastic.\", \"Fun-tastic is it?\"]) == {'python': 1, 'is': 2, 'fun': 2, 'tastic': 2, 'it': 1}", "assert count_word_frequencies([\"A B C. D-E-F.\", \"GHI! JKL? MNO; PQR: STU, VWX.\"]) == {'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'ghi': 1, 'jkl': 1, 'mno': 1, 'pqr': 1, 'stu': 1, 'vwx': 1}", "assert count_word_frequencies([\"123 test 456.\", \"Test 123 again.\"]) == {'123': 2, 'test': 2, '456': 1, 'again': 1}", "assert count_word_frequencies([\"\", \" \", \" \", \"!@#$\"]) == {}"], "kind": "synthetic"} {"id": "find_peak_elements_399", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_peak_elements(arr):\n \"\"\"\n Finds all 'peak' elements in a list of numbers. An element is considered a peak\n if it is strictly greater than its immediate neighbors. For elements at the\n boundaries, it only needs to be strictly greater than its single neighbor.\n If the list contains only one element, that element is considered a peak.\n\n The function should return a list of all peak elements in the order they\n appear in the input array. If no peaks are found, return an empty list.\n\n Args:\n arr (list): A list of integers or floats.\n\n Returns:\n list: A list containing all peak elements.\n\n Examples:\n >>> find_peak_elements([1, 2, 3, 2, 1])\n [3]\n >>> find_peak_elements([1, 5, 2, 8, 3])\n [5, 8]\n >>> find_peak_elements([10])\n [10]\n >>> find_peak_elements([5, 4, 3, 2, 1])\n [5]\n >>> find_peak_elements([1, 2, 3, 4, 5])\n [5]\n >>> find_peak_elements([])\n []\n >>> find_peak_elements([3, 1, 4, 1, 5, 9, 2, 6])\n [3, 4, 9, 6]\n \"\"\"", "tests": ["assert find_peak_elements([1, 2, 3, 2, 1]) == [3]", "assert find_peak_elements([1, 5, 2, 8, 3]) == [5, 8]", "assert find_peak_elements([10]) == [10]", "assert find_peak_elements([5, 4, 3, 2, 1]) == [5]", "assert find_peak_elements([1, 2, 3, 4, 5]) == [5]", "assert find_peak_elements([]) == []", "assert find_peak_elements([3, 1, 4, 1, 5, 9, 2, 6]) == [3, 4, 9, 6]", "assert find_peak_elements([1,1,1,1,1]) == []", "assert find_peak_elements([0.5, 1.2, 0.8, 2.1, 1.5]) == [1.2, 2.1]"], "kind": "synthetic"} {"id": "merge_overlapping_intervals_499", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef merge_overlapping_intervals(intervals):\n \"\"\"\n Merges a list of possibly overlapping intervals into a list of non-overlapping intervals.\n\n Each interval is represented as a list or tuple of two integers: [start, end].\n The intervals are assumed to be sorted by their start times. If not sorted, the function\n should sort them first.\n\n For example:\n merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]\n merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]\n merge_overlapping_intervals([]) == []\n merge_overlapping_intervals([[1, 4]]) == [[1, 4]]\n merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]\n\n Args:\n intervals: A list of intervals, where each interval is [start, end].\n\n Returns:\n A new list of merged, non-overlapping intervals, sorted by start time.\n \"\"\"", "tests": ["assert merge_overlapping_intervals([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]", "assert merge_overlapping_intervals([[1, 4], [4, 5]]) == [[1, 5]]", "assert merge_overlapping_intervals([]) == []", "assert merge_overlapping_intervals([[1, 4]]) == [[1, 4]]", "assert merge_overlapping_intervals([[1, 4], [0, 4]]) == [[0, 4]]", "assert merge_overlapping_intervals([[6, 8], [1, 9], [2, 4], [4, 7]]) == [[1, 9]]"], "kind": "synthetic"} {"id": "count_unique_elements_in_lists", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef count_unique_elements_in_lists(list_of_lists: list[list]) -> dict[int, int]:\n \"\"\"\n Given a list of lists of integers, return a dictionary where keys are the unique integers\n found across all inner lists, and values are the total count of occurrences for each integer.\n\n The order of keys in the output dictionary does not matter.\n\n For example:\n count_unique_elements_in_lists([[1, 2, 1], [3, 2], [1, 4]])\n should return {1: 3, 2: 2, 3: 1, 4: 1}\n\n count_unique_elements_in_lists([[], [5, 5], [6]])\n should return {5: 2, 6: 1}\n\n count_unique_elements_in_lists([[]])\n should return {}\n \"\"\"", "tests": ["assert count_unique_elements_in_lists([[1, 2, 1], [3, 2], [1, 4]]) == {1: 3, 2: 2, 3: 1, 4: 1}", "assert count_unique_elements_in_lists([[], [5, 5], [6]]) == {5: 2, 6: 1}", "assert count_unique_elements_in_lists([[]]) == {}", "assert count_unique_elements_in_lists([[10, 20], [30, 40], [10, 30, 50]]) == {10: 2, 20: 1, 30: 2, 40: 1, 50: 1}", "assert count_unique_elements_in_lists([[7, 7, 7], [7]]) == {7: 4}", "assert count_unique_elements_in_lists([[-1, 0], [0, 1]]) == {-1: 1, 0: 2, 1: 1}"], "kind": "synthetic"} {"id": "find_peak_elements_942", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_peak_elements(nums):\n \"\"\"\n Given a list of integers 'nums', find all 'peak elements' and return their indices.\n\n A peak element is an element that is greater than its neighbors. If an element has\n only one neighbor (i.e., it's at an end of the list), it is considered a peak if\n it's greater than that single neighbor.\n\n For example:\n - In [1, 2, 3, 1], 3 is a peak element (index 2).\n - In [1, 5, 2, 6, 3], 5 (index 1) and 6 (index 3) are peak elements.\n - In [3, 2, 1], 3 is a peak element (index 0).\n - In [1, 2, 3], 3 is a peak element (index 2).\n\n The input list 'nums' will contain at least one element.\n Duplicate values are possible, but a peak must be strictly greater than its neighbors.\n\n Args:\n nums (list[int]): The input list of integers.\n\n Returns:\n list[int]: A list of indices of all peak elements, in ascending order.\n \"\"\"", "tests": ["assert find_peak_elements([1, 2, 3, 1]) == [2]", "assert find_peak_elements([1, 5, 2, 6, 3]) == [1, 3]", "assert find_peak_elements([3, 2, 1]) == [0]", "assert find_peak_elements([1, 2, 3]) == [2]", "assert find_peak_elements([5]) == [0]", "assert find_peak_elements([1, 1, 1, 1]) == []", "assert find_peak_elements([1, 3, 2, 5, 4, 6, 0]) == [1, 3, 5]", "assert find_peak_elements([7, 6, 5, 4, 3, 2, 1]) == [0]", "assert find_peak_elements([1, 2, 1, 3, 5, 6, 4]) == [1, 5]"], "kind": "synthetic"} {"id": "rotate_matrix_clockwise_127", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_clockwise(matrix):\n \"\"\"\n Rotates a 2D square matrix 90 degrees clockwise.\n\n The matrix is represented as a list of lists. The input matrix is guaranteed\n to be square (number of rows equals number of columns) and non-empty.\n\n For example:\n rotate_matrix_clockwise([[1, 2],\n [3, 4]])\n should return [[3, 1],\n [4, 2]]\n\n rotate_matrix_clockwise([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]])\n should return [[7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]]\n \"\"\"", "tests": ["assert rotate_matrix_clockwise([[1]]) == [[1]]", "assert rotate_matrix_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]]", "assert rotate_matrix_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "assert rotate_matrix_clockwise([[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]]) == [[130, 90, 50, 10], [140, 100, 60, 20], [150, 110, 70, 30], [160, 120, 80, 40]]", "assert rotate_matrix_clockwise([['a', 'b'], ['c', 'd']]) == [['c', 'a'], ['d', 'b']]"], "kind": "synthetic"} {"id": "sum_of_divisors_860", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Calculate the sum of all positive divisors of a given positive integer n.\n A divisor of n is an integer d such that n/d is an integer.\n For example, the divisors of 6 are 1, 2, 3, and 6. Their sum is 1 + 2 + 3 + 6 = 12.\n\n The input n will always be a positive integer (n >= 1).\n \"\"\"", "tests": ["assert sum_of_divisors(1) == 1", "assert sum_of_divisors(6) == 12", "assert sum_of_divisors(7) == 8", "assert sum_of_divisors(10) == 18", "assert sum_of_divisors(28) == 56", "assert sum_of_divisors(100) == 217"], "kind": "synthetic"} {"id": "rotate_matrix_90_clockwise_597", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a given square matrix 90 degrees clockwise in-place.\n The function modifies the input matrix directly and does not return anything.\n\n A square matrix 'matrix' of size N x N is given as a list of lists.\n\n For example:\n If matrix = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n ]\n\n After rotation, matrix should become:\n [\n [7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]\n ]\n\n Assumes the input 'matrix' is always a non-empty square matrix (N >= 1).\n \"\"\"", "tests": ["matrix1 = [[1, 2], [3, 4]]; rotate_matrix_90_clockwise(matrix1); assert matrix1 == [[3, 1], [4, 2]]", "matrix2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; rotate_matrix_90_clockwise(matrix2); assert matrix2 == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "matrix3 = [[5]]; rotate_matrix_90_clockwise(matrix3); assert matrix3 == [[5]]", "matrix4 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; rotate_matrix_90_clockwise(matrix4); assert matrix4 == [[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]]", "matrix5 = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]; rotate_matrix_90_clockwise(matrix5); assert matrix5 == [[70, 40, 10], [80, 50, 20], [90, 60, 30]]"], "kind": "synthetic"} {"id": "flatten_nested_list_181", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef flatten_nested_list(nested_list):\n \"\"\"\n Recursively flattens a nested list of integers into a single, one-dimensional list.\n\n The input `nested_list` can contain integers directly or other lists.\n These inner lists can in turn contain integers or further nested lists, and so on.\n Empty lists should be ignored.\n\n For example:\n flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]\n flatten_nested_list([1, [], [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]\n flatten_nested_list([]) == []\n flatten_nested_list([1, 2, 3]) == [1, 2, 3]\n flatten_nested_list([[[1]], [2, [3]]]) == [1, 2, 3]\n \"\"\"", "tests": ["assert flatten_nested_list([1, [2, 3], 4]) == [1, 2, 3, 4]", "assert flatten_nested_list([1, [], [2, [3, 4]], 5]) == [1, 2, 3, 4, 5]", "assert flatten_nested_list([]) == []", "assert flatten_nested_list([1, 2, 3]) == [1, 2, 3]", "assert flatten_nested_list([[[1]], [2, [3]]]) == [1, 2, 3]", "assert flatten_nested_list([[[[[], 1]]], [2, [3, []], 4], 5]) == [1, 2, 3, 4, 5]"], "kind": "synthetic"} {"id": "rotate_matrix_90_clockwise_405", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates a given square matrix 90 degrees clockwise in-place.\n\n The matrix is represented as a list of lists. The input matrix will\n always be square (n x n) and non-empty. Modifications should be\n made directly to the input 'matrix' list of lists, and the function\n should not return anything.\n\n For example:\n If matrix = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n ]\n After rotation, matrix should become:\n [\n [7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]\n ]\n \"\"\"", "tests": ["m1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; rotate_matrix_90_clockwise(m1); assert m1 == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "m2 = [[1]]; rotate_matrix_90_clockwise(m2); assert m2 == [[1]]", "m3 = [[1, 2], [3, 4]]; rotate_matrix_90_clockwise(m3); assert m3 == [[3, 1], [4, 2]]", "m4 = [[5, 1, 9, 11], [2, 4, 8, 10], [13, 3, 6, 7], [15, 14, 12, 16]]; rotate_matrix_90_clockwise(m4); assert m4 == [[15, 13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7, 10, 11]]", "m5 = [[10, 20], [30, 40]]; rotate_matrix_90_clockwise(m5); assert m5 == [[30, 10], [40, 20]]"], "kind": "synthetic"} {"id": "rotate_matrix_clockwise_948", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_clockwise(matrix):\n \"\"\"\n Rotates a square matrix clockwise by 90 degrees.\n\n The rotation should be performed in-place if possible (by modifying the input list of lists),\n but returning a new matrix is also acceptable for simplicity.\n The input matrix is guaranteed to be square (N x N) and non-empty.\n\n For example:\n rotate_matrix_clockwise([ [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9] ])\n should return:\n [ [7, 4, 1],\n [8, 5, 2],\n [9, 6, 3] ]\n \"\"\"", "tests": ["assert rotate_matrix_clockwise([[1]]) == [[1]]", "assert rotate_matrix_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]]", "assert rotate_matrix_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "assert rotate_matrix_clockwise([[10, 11, 12, 13], [14, 15, 16, 17], [18, 19, 20, 21], [22, 23, 24, 25]]) == [[22, 18, 14, 10], [23, 19, 15, 11], [24, 20, 16, 12], [25, 21, 17, 13]]", "assert rotate_matrix_clockwise([[1,0],[0,1]]) == [[0,1],[1,0]]"], "kind": "synthetic"} {"id": "sum_of_divisors_317", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Calculates the sum of all positive divisors of a given positive integer n.\n A divisor of n is an integer that divides n without leaving a remainder.\n The divisors include 1 and n itself.\n\n For example:\n sum_of_divisors(1) == 1 (divisors: 1)\n sum_of_divisors(6) == 1 + 2 + 3 + 6 == 12 (divisors: 1, 2, 3, 6)\n sum_of_divisors(7) == 1 + 7 == 8 (divisors: 1, 7)\n\n Args:\n n: A positive integer.\n\n Returns:\n The sum of all positive divisors of n.\n\n Raises:\n ValueError: If n is not a positive integer.\n \"\"\"", "tests": ["assert sum_of_divisors(1) == 1", "assert sum_of_divisors(6) == 12", "assert sum_of_divisors(7) == 8", "assert sum_of_divisors(12) == 28", "assert sum_of_divisors(100) == 217", "assert sum_of_divisors(36) == 91"], "kind": "synthetic"} {"id": "sum_of_divisors_651", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Calculates the sum of all positive divisors of a given positive integer n.\n\n A divisor of n is an integer that divides n without leaving a remainder.\n For example, the divisors of 6 are 1, 2, 3, and 6. Their sum is 1 + 2 + 3 + 6 = 12.\n\n The function should work efficiently for moderately large n.\n\n Args:\n n: A positive integer (n >= 1).\n\n Returns:\n The sum of all positive divisors of n.\n\n Examples:\n sum_of_divisors(1) == 1\n sum_of_divisors(6) == 12\n sum_of_divisors(10) == 18\n \"\"\"", "tests": ["assert sum_of_divisors(1) == 1", "assert sum_of_divisors(6) == 12", "assert sum_of_divisors(10) == 18", "assert sum_of_divisors(12) == 28", "assert sum_of_divisors(25) == 31", "assert sum_of_divisors(100) == 217", "assert sum_of_divisors(997) == 998"], "kind": "synthetic"} {"id": "parse_key_value_string_804", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef parse_key_value_string(data_string: str) -> dict:\n \"\"\"\n Parses a string containing key-value pairs separated by semicolons, \n where each key and value are separated by a colon.\n\n Keys and values are stripped of leading/trailing whitespace.\n If a key appears multiple times, the last encountered value for that key should be used.\n Empty keys or values (after stripping) should be ignored.\n Key-value pairs that do not contain a colon separator should also be ignored.\n\n For example:\n 'name: Alice; age: 30; city: New York' -> {'name': 'Alice', 'age': '30', 'city': 'New York'}\n ' item: apple ; price: 1.25 ; size: M ' -> {'item': 'apple', 'price': '1.25', 'size': 'M'}\n 'key1:value1;key2:value2;key1:new_value' -> {'key1': 'new_value', 'key2': 'value2'}\n 'empty:; invalid_pair; another: valid' -> {'another': 'valid'}\n ' key: value ; : ' -> {'key': 'value'}\n \"\"\"", "tests": ["assert parse_key_value_string('name: Alice; age: 30; city: New York') == {'name': 'Alice', 'age': '30', 'city': 'New York'}", "assert parse_key_value_string(' item: apple ; price: 1.25 ; size: M ') == {'item': 'apple', 'price': '1.25', 'size': 'M'}", "assert parse_key_value_string('key1:value1;key2:value2;key1:new_value') == {'key1': 'new_value', 'key2': 'value2'}", "assert parse_key_value_string('empty:; invalid_pair; another: valid; :') == {'another': 'valid'}", "assert parse_key_value_string('') == {}", "assert parse_key_value_string(' single_key: single_value ') == {'single_key': 'single_value'}", "assert parse_key_value_string('first:a;second:b;first:c;third:d') == {'first': 'c', 'second': 'b', 'third': 'd'}"], "kind": "synthetic"} {"id": "rotate_matrix_clockwise_689", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef rotate_matrix_clockwise(matrix):\n \"\"\"\n Rotates a 2D square matrix clockwise by 90 degrees.\n\n The rotation should be performed in-place if possible (modifying the original list of lists),\n but returning a new matrix is also acceptable. The core requirement is the correct\n transformation. For simplicity, assume the input matrix is always square (N x N)\n and contains only integers.\n\n For example:\n [[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]]\n\n becomes:\n [[7, 4, 1],\n [8, 5, 2],\n [9, 6, 3]]\n\n Args:\n matrix: A list of lists representing a square matrix of integers.\n\n Returns:\n A new list of lists representing the rotated matrix.\n \"\"\"", "tests": ["assert rotate_matrix_clockwise([[1]]) == [[1]]", "assert rotate_matrix_clockwise([[1, 2], [3, 4]]) == [[3, 1], [4, 2]]", "assert rotate_matrix_clockwise([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[7, 4, 1], [8, 5, 2], [9, 6, 3]]", "assert rotate_matrix_clockwise([[10, 20, 30, 40], [11, 21, 31, 41], [12, 22, 32, 42], [13, 23, 33, 43]]) == [[13, 12, 11, 10], [23, 22, 21, 20], [33, 32, 31, 30], [43, 42, 41, 40]]", "assert rotate_matrix_clockwise([]) == []"], "kind": "synthetic"} {"id": "find_median_sorted_arrays_324", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_median_sorted_arrays(nums1: list[int], nums2: list[int]) -> float:\n \"\"\"\n Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median\n of the two sorted arrays. The overall run time complexity should be O(log(m+n)).\n\n You may assume nums1 and nums2 cannot be both empty.\n\n Example 1:\n nums1 = [1, 3], nums2 = [2]\n The merged array is [1, 2, 3] and its median is 2.0.\n\n Example 2:\n nums1 = [1, 2], nums2 = [3, 4]\n The merged array is [1, 2, 3, 4] and its median is (2 + 3) / 2 = 2.5.\n \"\"\"", "tests": ["assert find_median_sorted_arrays([1, 3], [2]) == 2.0", "assert find_median_sorted_arrays([1, 2], [3, 4]) == 2.5", "assert find_median_sorted_arrays([0, 0], [0, 0]) == 0.0", "assert find_median_sorted_arrays([], [1]) == 1.0", "assert find_median_sorted_arrays([2], []) == 2.0", "assert find_median_sorted_arrays([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]) == 5.5", "assert find_median_sorted_arrays([1, 1, 3, 3], [1, 1, 3, 3]) == 2.0"], "kind": "synthetic"} {"id": "find_median_sorted_arrays_353", "prompt": "Implement the following Python function. Return ONLY the function definition, no explanation.\n\ndef find_median_sorted_arrays(nums1: list[int], nums2: list[int]) -> float:\n \"\"\"\n Given two sorted arrays nums1 and nums2 of size m and n respectively,\n return the median of the two sorted arrays.\n\n The overall run time complexity should be O(log(m+n)).\n\n You may assume nums1 and nums2 are both non-empty and do not contain duplicate elements.\n They are sorted in ascending order.\n\n Examples:\n find_median_sorted_arrays([1, 3], [2]) == 2.0\n find_median_sorted_arrays([1, 2], [3, 4]) == 2.5\n find_median_sorted_arrays([0, 0], [0, 0]) == 0.0\n \"\"\"", "tests": ["assert find_median_sorted_arrays([1, 3], [2]) == 2.0", "assert find_median_sorted_arrays([1, 2], [3, 4]) == 2.5", "assert find_median_sorted_arrays([0, 0], [0, 0]) == 0.0", "assert find_median_sorted_arrays([10], [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 5.5", "assert find_median_sorted_arrays([2, 3, 4, 5, 6, 7], [1]) == 4.0", "assert find_median_sorted_arrays([1, 5, 7, 9], [2, 4, 6, 8]) == 5.5"], "kind": "synthetic"}