Prompt:
from typing import List
def buildWall(height: int, width: int, bricks: List[int]) -> int:
    """
    You are given integers height and width which specify the dimensions of a brick wall you are building. You are also given a 0-indexed array of unique integers bricks, where the ith brick has a height of 1 and a width of bricks[i]. You have an infinite supply of each type of brick and bricks may not be rotated.
    Each row in the wall must be exactly width units long. For the wall to be sturdy, adjacent rows in the wall should not join bricks at the same location, except at the ends of the wall.
    Return the number of ways to build a sturdy wall. Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> buildWall(height = 2, width = 3, bricks = [1,2])
    >>> 2
    Explanation:
    The first two walls in the diagram show the only two ways to build a sturdy brick wall.
    Note that the third wall in the diagram is not sturdy because adjacent rows join bricks 2 units from the left.

    Example 2:

    >>> buildWall(height = 1, width = 1, bricks = [5])
    >>> 0
    Explanation:
    There are no ways to build a sturdy wall because the only type of brick we have is longer than the width of the wall.
    """


Prompt:
from typing import List
def prefixCount(words: List[str], pref: str) -> int:
    """
    You are given an array of strings words and a string pref.
    Return the number of strings in words that contain pref as a prefix.
    A prefix of a string s is any leading contiguous substring of s.

    Example 1:

    >>> prefixCount(words = ["pay","attention","practice","attend"], pref = "at")
    >>> 2
    Explanation: The 2 strings that contain "at" as a prefix are: "attention" and "attend".

    Example 2:

    >>> prefixCount(words = ["leetcode","win","loops","success"], pref = "code")
    >>> 0
    Explanation: There are no strings that contain "code" as a prefix.
    """


Prompt:
def minSteps(s: str, t: str) -> int:
    """
    You are given two strings s and t. In one step, you can append any character to either s or t.
    Return the minimum number of steps to make s and t anagrams of each other.
    An anagram of a string is a string that contains the same characters with a different (or the same) ordering.

    Example 1:

    >>> minSteps(s = "leetcode", t = "coats")
    >>> 7
    Explanation:
    - In 2 steps, we can append the letters in "as" onto s = "leetcode", forming s = "leetcodeas".
    - In 5 steps, we can append the letters in "leede" onto t = "coats", forming t = "coatsleede".
    "leetcodeas" and "coatsleede" are now anagrams of each other.
    We used a total of 2 + 5 = 7 steps.
    It can be shown that there is no way to make them anagrams of each other with less than 7 steps.

    Example 2:

    >>> minSteps(s = "night", t = "thing")
    >>> 0
    Explanation: The given strings are already anagrams of each other. Thus, we do not need any further steps.
    """


Prompt:
from typing import List
def minimumTime(time: List[int], totalTrips: int) -> int:
    """
    You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip.
    Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.
    You are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.

    Example 1:

    >>> minimumTime(time = [1,2,3], totalTrips = 5)
    >>> 3
    Explanation:
    - At time t = 1, the number of trips completed by each bus are [1,0,0].
      The total number of trips completed is 1 + 0 + 0 = 1.
    - At time t = 2, the number of trips completed by each bus are [2,1,0].
      The total number of trips completed is 2 + 1 + 0 = 3.
    - At time t = 3, the number of trips completed by each bus are [3,1,1].
      The total number of trips completed is 3 + 1 + 1 = 5.
    So the minimum time needed for all buses to complete at least 5 trips is 3.

    Example 2:

    >>> minimumTime(time = [2], totalTrips = 1)
    >>> 2
    Explanation:
    There is only one bus, and it will complete its first trip at t = 2.
    So the minimum time needed to complete 1 trip is 2.
    """


Prompt:
from typing import List
def minimumFinishTime(tires: List[List[int]], changeTime: int, numLaps: int) -> int:
    """
    You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds.

    For example, if fi = 3 and ri = 2, then the tire would finish its 1st lap in 3 seconds, its 2nd lap in 3 * 2 = 6 seconds, its 3rd lap in 3 * 22 = 12 seconds, etc.

    You are also given an integer changeTime and an integer numLaps.
    The race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire (including the current tire type) if you wait changeTime seconds.
    Return the minimum time to finish the race.

    Example 1:

    >>> minimumFinishTime(tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4)
    >>> 21
    Explanation:
    Lap 1: Start with tire 0 and finish the lap in 2 seconds.
    Lap 2: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.
    Lap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.
    Lap 4: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.
    Total time = 2 + 6 + 5 + 2 + 6 = 21 seconds.
    The minimum time to complete the race is 21 seconds.

    Example 2:

    >>> minimumFinishTime(tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5)
    >>> 25
    Explanation:
    Lap 1: Start with tire 1 and finish the lap in 2 seconds.
    Lap 2: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.
    Lap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.
    Lap 4: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.
    Lap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.
    Total time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.
    The minimum time to complete the race is 25 seconds.
    """


Prompt:
from typing import Any
def houseOfCards(n: int) -> int:
    """
    You are given an integer n representing the number of playing cards you have. A house of cards meets the following conditions:

    A house of cards consists of one or more rows of triangles and horizontal cards.
    Triangles are created by leaning two cards against each other.
    One card must be placed horizontally between all adjacent triangles in a row.
    Any triangle on a row higher than the first must be placed on a horizontal card from the previous row.
    Each triangle is placed in the leftmost available spot in the row.

    Return the number of distinct house of cards you can build using all n cards. Two houses of cards are considered distinct if there exists a row where the two houses contain a different number of cards.

    Example 1:

    >>> houseOfCards(n = 16)
    >>> 2
    Explanation: The two valid houses of cards are shown.
    The third house of cards in the diagram is not valid because the rightmost triangle on the top row is not placed on top of a horizontal card.

    Example 2:

    >>> houseOfCards(n = 2)
    >>> 1
    Explanation: The one valid house of cards is shown.

    Example 3:

    >>> houseOfCards(n = 4)
    >>> 0
    Explanation: The three houses of cards in the diagram are not valid.
    The first house of cards needs a horizontal card placed between the two triangles.
    The second house of cards uses 5 cards.
    The third house of cards uses 2 cards.
    """


Prompt:
from typing import List
def mostFrequent(nums: List[int], key: int) -> int:
    """
    You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.
    For every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that:

    0 <= i <= nums.length - 2,
    nums[i] == key and,
    nums[i + 1] == target.

    Return the target with the maximum count. The test cases will be generated such that the target with maximum count is unique.

    Example 1:

    >>> mostFrequent(nums = [1,100,200,1,100], key = 1)
    >>> 100
    Explanation: For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.
    No other integers follow an occurrence of key, so we return 100.

    Example 2:

    >>> mostFrequent(nums = [2,2,2,2,3], key = 2)
    >>> 2
    Explanation: For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.
    For target = 3, there is only one occurrence at index 4 which follows an occurrence of key.
    target = 2 has the maximum number of occurrences following an occurrence of key, so we return 2.
    """


Prompt:
from typing import List
def sortJumbled(mapping: List[int], nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.
    The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.
    You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.
    Notes:

    Elements with the same mapped values should appear in the same relative order as in the input.
    The elements of nums should only be sorted based on their mapped values and not be replaced by them.

    Example 1:

    >>> sortJumbled(mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38])
    >>> [338,38,991]
    Explanation:
    Map the number 991 as follows:
    1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
    2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
    Therefore, the mapped value of 991 is 669.
    338 maps to 007, or 7 after removing the leading zeros.
    38 maps to 07, which is also 7 after removing leading zeros.
    Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
    Thus, the sorted array is [338,38,991].

    Example 2:

    >>> sortJumbled(mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123])
    >>> [123,456,789]
    Explanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].
    """


Prompt:
from typing import List
def getAncestors(n: int, edges: List[List[int]]) -> List[List[int]]:
    """
    You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).
    You are also given a 2D integer array edges, where edges[i] = [fromi, toi] denotes that there is a unidirectional edge from fromi to toi in the graph.
    Return a list answer, where answer[i] is the list of ancestors of the ith node, sorted in ascending order.
    A node u is an ancestor of another node v if u can reach v via a set of edges.

    Example 1:

    >>> getAncestors(n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]])
    >>> [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]
    Explanation:
    The above diagram represents the input graph.
    - Nodes 0, 1, and 2 do not have any ancestors.
    - Node 3 has two ancestors 0 and 1.
    - Node 4 has two ancestors 0 and 2.
    - Node 5 has three ancestors 0, 1, and 3.
    - Node 6 has five ancestors 0, 1, 2, 3, and 4.
    - Node 7 has four ancestors 0, 1, 2, and 3.

    Example 2:

    >>> getAncestors(n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]])
    >>> [[],[0],[0,1],[0,1,2],[0,1,2,3]]
    Explanation:
    The above diagram represents the input graph.
    - Node 0 does not have any ancestor.
    - Node 1 has one ancestor 0.
    - Node 2 has two ancestors 0 and 1.
    - Node 3 has three ancestors 0, 1, and 2.
    - Node 4 has four ancestors 0, 1, 2, and 3.
    """


Prompt:
def minMovesToMakePalindrome(s: str) -> int:
    """
    You are given a string s consisting only of lowercase English letters.
    In one move, you can select any two adjacent characters of s and swap them.
    Return the minimum number of moves needed to make s a palindrome.
    Note that the input will be generated such that s can always be converted to a palindrome.

    Example 1:

    >>> minMovesToMakePalindrome(s = "aabb")
    >>> 2
    Explanation:
    We can obtain two palindromes from s, "abba" and "baab".
    - We can obtain "abba" from s in 2 moves: "aabb" -> "abab" -> "abba".
    - We can obtain "baab" from s in 2 moves: "aabb" -> "abab" -> "baab".
    Thus, the minimum number of moves needed to make s a palindrome is 2.

    Example 2:

    >>> minMovesToMakePalindrome(s = "letelt")
    >>> 2
    Explanation:
    One of the palindromes we can obtain from s in 2 moves is "lettel".
    One of the ways we can obtain it is "letelt" -> "letetl" -> "lettel".
    Other palindromes such as "tleelt" can also be obtained in 2 moves.
    It can be shown that it is not possible to obtain a palindrome in less than 2 moves.
    """


Prompt:
from typing import List
def cellsInRange(s: str) -> List[str]:
    """
    A cell (r, c) of an excel sheet is represented as a string "" where:

     denotes the column number c of the cell. It is represented by alphabetical letters.

    For example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.

     is the row number r of the cell. The rth row is represented by the integer r.

    You are given a string s in the format ":", where  represents the column c1,  represents the row r1,  represents the column c2, and  represents the row r2, such that r1 <= r2 and c1 <= c2.
    Return the list of cells (x, y) such that r1 <= x <= r2 and c1 <= y <= c2. The cells should be represented as strings in the format mentioned above and be sorted in non-decreasing order first by columns and then by rows.

    Example 1:

    >>> cellsInRange(s = "K1:L2")
    >>> ["K1","K2","L1","L2"]
    Explanation:
    The above diagram shows the cells which should be present in the list.
    The red arrows denote the order in which the cells should be presented.

    Example 2:

    >>> cellsInRange(s = "A1:F1")
    >>> ["A1","B1","C1","D1","E1","F1"]
    Explanation:
    The above diagram shows the cells which should be present in the list.
    The red arrow denotes the order in which the cells should be presented.
    """


Prompt:
from typing import List
def minimalKSum(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum.
    Return the sum of the k integers appended to nums.

    Example 1:

    >>> minimalKSum(nums = [1,4,25,10,25], k = 2)
    >>> 5
    Explanation: The two unique positive integers that do not appear in nums which we append are 2 and 3.
    The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.
    The sum of the two integers appended is 2 + 3 = 5, so we return 5.
    Example 2:

    >>> minimalKSum(nums = [5,6], k = 6)
    >>> 25
    Explanation: The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.
    The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.
    The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25.
    """


Prompt:
from typing import List, Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def createBinaryTree(descriptions: List[List[int]]) -> Optional[TreeNode]:
"""
You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,

If isLefti == 1, then childi is the left child of parenti.
If isLefti == 0, then childi is the right child of parenti.

Construct the binary tree described by descriptions and return its root.
The test cases will be generated such that the binary tree is valid.

Example 1:

>>> createBinaryTree(descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]])
>>> [50,20,80,15,17,19]
Explanation: The root node is the node with value 50 since it has no parent.
The resulting binary tree is shown in the diagram.

Example 2:

>>> createBinaryTree(descriptions = [[1,2,1],[2,3,0],[3,4,1]])
>>> [1,2,null,null,3,4]
Explanation: The root node is the node with value 1 since it has no parent.
The resulting binary tree is shown in the diagram.
"""


Prompt:
from typing import List
def replaceNonCoprimes(nums: List[int]) -> List[int]:
    """
    You are given an array of integers nums. Perform the following steps:

    Find any two adjacent numbers in nums that are non-coprime.
    If no such numbers are found, stop the process.
    Otherwise, delete the two numbers and replace them with their LCM (Least Common Multiple).
    Repeat this process as long as you keep finding two adjacent non-coprime numbers.

    Return the final modified array. It can be shown that replacing adjacent non-coprime numbers in any arbitrary order will lead to the same result.
    The test cases are generated such that the values in the final array are less than or equal to 108.
    Two values x and y are non-coprime if GCD(x, y) > 1 where GCD(x, y) is the Greatest Common Divisor of x and y.

    Example 1:

    >>> replaceNonCoprimes(nums = [6,4,3,2,7,6,2])
    >>> [12,7,6]
    Explanation:
    - (6, 4) are non-coprime with LCM(6, 4) = 12. Now, nums = [12,3,2,7,6,2].
    - (12, 3) are non-coprime with LCM(12, 3) = 12. Now, nums = [12,2,7,6,2].
    - (12, 2) are non-coprime with LCM(12, 2) = 12. Now, nums = [12,7,6,2].
    - (6, 2) are non-coprime with LCM(6, 2) = 6. Now, nums = [12,7,6].
    There are no more adjacent non-coprime numbers in nums.
    Thus, the final modified array is [12,7,6].
    Note that there are other ways to obtain the same resultant array.

    Example 2:

    >>> replaceNonCoprimes(nums = [2,2,1,1,3,3,3])
    >>> [2,1,1,3]
    Explanation:
    - (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3,3].
    - (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3].
    - (2, 2) are non-coprime with LCM(2, 2) = 2. Now, nums = [2,1,1,3].
    There are no more adjacent non-coprime numbers in nums.
    Thus, the final modified array is [2,1,1,3].
    Note that there are other ways to obtain the same resultant array.
    """


Prompt:
from typing import List
def singleDivisorTriplet(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of positive integers nums. A triplet of three distinct indices (i, j, k) is called a single divisor triplet of nums if nums[i] + nums[j] + nums[k] is divisible by exactly one of nums[i], nums[j], or nums[k].
    Return the number of single divisor triplets of nums.

    Example 1:

    >>> singleDivisorTriplet(nums = [4,6,7,3,2])
    >>> 12
    Explanation:
    The triplets (0, 3, 4), (0, 4, 3), (3, 0, 4), (3, 4, 0), (4, 0, 3), and (4, 3, 0) have the values of [4, 3, 2] (or a permutation of [4, 3, 2]).
    4 + 3 + 2 = 9 which is only divisible by 3, so all such triplets are single divisor triplets.
    The triplets (0, 2, 3), (0, 3, 2), (2, 0, 3), (2, 3, 0), (3, 0, 2), and (3, 2, 0) have the values of [4, 7, 3] (or a permutation of [4, 7, 3]).
    4 + 7 + 3 = 14 which is only divisible by 7, so all such triplets are single divisor triplets.
    There are 12 single divisor triplets in total.

    Example 2:

    >>> singleDivisorTriplet(nums = [1,2,2])
    >>> 6
    Explanation:
    The triplets (0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), and (2, 1, 0) have the values of [1, 2, 2] (or a permutation of [1, 2, 2]).
    1 + 2 + 2 = 5 which is only divisible by 1, so all such triplets are single divisor triplets.
    There are 6 single divisor triplets in total.

    Example 3:

    >>> singleDivisorTriplet(nums = [1,1,1])
    >>> 0
    Explanation:
    There are no single divisor triplets.
    Note that (0, 1, 2) is not a single divisor triplet because nums[0] + nums[1] + nums[2] = 3 and 3 is divisible by nums[0], nums[1], and nums[2].
    """


Prompt:
from typing import List
def findKDistantIndices(nums: List[int], key: int, k: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.
    Return a list of all k-distant indices sorted in increasing order.

    Example 1:

    >>> findKDistantIndices(nums = [3,4,9,1,3,9,5], key = 9, k = 1)
    >>> [1,2,3,4,5,6]
    Explanation: Here, nums[2] == key and nums[5] == key.
    - For index 0, |0 - 2| > k and |0 - 5| > k, so there is no j where |0 - j| <= k and nums[j] == key. Thus, 0 is not a k-distant index.
    - For index 1, |1 - 2| <= k and nums[2] == key, so 1 is a k-distant index.
    - For index 2, |2 - 2| <= k and nums[2] == key, so 2 is a k-distant index.
    - For index 3, |3 - 2| <= k and nums[2] == key, so 3 is a k-distant index.
    - For index 4, |4 - 5| <= k and nums[5] == key, so 4 is a k-distant index.
    - For index 5, |5 - 5| <= k and nums[5] == key, so 5 is a k-distant index.
    - For index 6, |6 - 5| <= k and nums[5] == key, so 6 is a k-distant index.
    Thus, we return [1,2,3,4,5,6] which is sorted in increasing order.

    Example 2:

    >>> findKDistantIndices(nums = [2,2,2,2,2], key = 2, k = 2)
    >>> [0,1,2,3,4]
    Explanation: For all indices i in nums, there exists some index j such that |i - j| <= k and nums[j] == key, so every index is a k-distant index.
    Hence, we return [0,1,2,3,4].
    """


Prompt:
from typing import List
def digArtifacts(n: int, artifacts: List[List[int]], dig: List[List[int]]) -> int:
    """
    There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1i, c1i, r2i, c2i] denotes that the ith artifact is buried in the subgrid where:

    (r1i, c1i) is the coordinate of the top-left cell of the ith artifact and
    (r2i, c2i) is the coordinate of the bottom-right cell of the ith artifact.

    You will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.
    Given a 0-indexed 2D integer array dig where dig[i] = [ri, ci] indicates that you will excavate the cell (ri, ci), return the number of artifacts that you can extract.
    The test cases are generated such that:

    No two artifacts overlap.
    Each artifact only covers at most 4 cells.
    The entries of dig are unique.

    Example 1:

    >>> digArtifacts(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]])
    >>> 1
    Explanation:
    The different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid.
    There is 1 artifact that can be extracted, namely the red artifact.
    The blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it.
    Thus, we return 1.

    Example 2:

    >>> digArtifacts(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]])
    >>> 2
    Explanation: Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2.
    """


Prompt:
from typing import List
def maximumTop(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile.
    In one move, you can perform either of the following:

    If the pile is not empty, remove the topmost element of the pile.
    If there are one or more removed elements, add any one of them back onto the pile. This element becomes the new topmost element.

    You are also given an integer k, which denotes the total number of moves to be made.
    Return the maximum value of the topmost element of the pile possible after exactly k moves. In case it is not possible to obtain a non-empty pile after k moves, return -1.

    Example 1:

    >>> maximumTop(nums = [5,2,2,4,0,6], k = 4)
    >>> 5
    Explanation:
    One of the ways we can end with 5 at the top of the pile after 4 moves is as follows:
    - Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6].
    - Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6].
    - Step 3: Remove the topmost element = 2. The pile becomes [4,0,6].
    - Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6].
    Note that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves.

    Example 2:

    >>> maximumTop(nums = [2], k = 1)
    >>> -1
    Explanation:
    In the first move, our only option is to pop the topmost element of the pile.
    Since it is not possible to obtain a non-empty pile after one move, we return -1.
    """


Prompt:
from typing import List
def minimumWeight(n: int, edges: List[List[int]], src1: int, src2: int, dest: int) -> int:
    """
    You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1.
    You are also given a 2D integer array edges where edges[i] = [fromi, toi, weighti] denotes that there exists a directed edge from fromi to toi with weight weighti.
    Lastly, you are given three distinct integers src1, src2, and dest denoting three distinct nodes of the graph.
    Return the minimum weight of a subgraph of the graph such that it is possible to reach dest from both src1 and src2 via a set of edges of this subgraph. In case such a subgraph does not exist, return -1.
    A subgraph is a graph whose vertices and edges are subsets of the original graph. The weight of a subgraph is the sum of weights of its constituent edges.

    Example 1:

    >>> minimumWeight(n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5)
    >>> 9
    Explanation:
    The above figure represents the input graph.
    The blue edges represent one of the subgraphs that yield the optimal answer.
    Note that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints.

    Example 2:

    >>> minimumWeight(n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2)
    >>> -1
    Explanation:
    The above figure represents the input graph.
    It can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints.
    """


Prompt:
from typing import List
def distanceToCycle(n: int, edges: List[List[int]]) -> List[int]:
    """
    You are given a positive integer n representing the number of nodes in a connected undirected graph containing exactly one cycle. The nodes are numbered from 0 to n - 1 (inclusive).
    You are also given a 2D integer array edges, where edges[i] = [node1i, node2i] denotes that there is a bidirectional edge connecting node1i and node2i in the graph.
    The distance between two nodes a and b is defined to be the minimum number of edges that are needed to go from a to b.
    Return an integer array answer of size n, where answer[i] is the minimum distance between the ith node and any node in the cycle.

    Example 1:

    >>> distanceToCycle(n = 7, edges = [[1,2],[2,4],[4,3],[3,1],[0,1],[5,2],[6,5]])
    >>> [1,0,0,0,0,1,2]
    Explanation:
    The nodes 1, 2, 3, and 4 form the cycle.
    The distance from 0 to 1 is 1.
    The distance from 1 to 1 is 0.
    The distance from 2 to 2 is 0.
    The distance from 3 to 3 is 0.
    The distance from 4 to 4 is 0.
    The distance from 5 to 2 is 1.
    The distance from 6 to 2 is 2.

    Example 2:

    >>> distanceToCycle(n = 9, edges = [[0,1],[1,2],[0,2],[2,6],[6,7],[6,8],[0,3],[3,4],[3,5]])
    >>> [0,0,0,1,2,2,1,2,2]
    Explanation:
    The nodes 0, 1, and 2 form the cycle.
    The distance from 0 to 0 is 0.
    The distance from 1 to 1 is 0.
    The distance from 2 to 2 is 0.
    The distance from 3 to 1 is 1.
    The distance from 4 to 1 is 2.
    The distance from 5 to 1 is 2.
    The distance from 6 to 2 is 1.
    The distance from 7 to 2 is 2.
    The distance from 8 to 2 is 2.
    """


Prompt:
from typing import List
def divideArray(nums: List[int]) -> bool:
    """
    You are given an integer array nums consisting of 2 * n integers.
    You need to divide nums into n pairs such that:

    Each element belongs to exactly one pair.
    The elements present in a pair are equal.

    Return true if nums can be divided into n pairs, otherwise return false.

    Example 1:

    >>> divideArray(nums = [3,2,3,2,2,2])
    >>> true
    Explanation:
    There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.
    If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.

    Example 2:

    >>> divideArray(nums = [1,2,3,4])
    >>> false
    Explanation:
    There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.
    """


Prompt:
def maximumSubsequenceCount(text: str, pattern: str) -> int:
    """
    You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters.
    You can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text.
    Return the maximum number of times pattern can occur as a subsequence of the modified text.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

    Example 1:

    >>> maximumSubsequenceCount(text = "abdcdbc", pattern = "ac")
    >>> 4
    Explanation:
    If we add pattern[0] = 'a' in between text[1] and text[2], we get "abadcdbc". Now, the number of times "ac" occurs as a subsequence is 4.
    Some other strings which have 4 subsequences "ac" after adding a character to text are "aabdcdbc" and "abdacdbc".
    However, strings such as "abdcadbc", "abdccdbc", and "abdcdbcc", although obtainable, have only 3 subsequences "ac" and are thus suboptimal.
    It can be shown that it is not possible to get more than 4 subsequences "ac" by adding only one character.

    Example 2:

    >>> maximumSubsequenceCount(text = "aabb", pattern = "ab")
    >>> 6
    Explanation:
    Some of the strings which can be obtained from text and have 6 subsequences "ab" are "aaabb", "aaabb", and "aabbb".
    """


Prompt:
from typing import List
def halveArray(nums: List[int]) -> int:
    """
    You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)
    Return the minimum number of operations to reduce the sum of nums by at least half.

    Example 1:

    >>> halveArray(nums = [5,19,8,1])
    >>> 3
    Explanation: The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.
    The following is one of the ways to reduce the sum by at least half:
    Pick the number 19 and reduce it to 9.5.
    Pick the number 9.5 and reduce it to 4.75.
    Pick the number 8 and reduce it to 4.
    The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75.
    The sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5.
    Overall, 3 operations were used so we return 3.
    It can be shown that we cannot reduce the sum by at least half in less than 3 operations.

    Example 2:

    >>> halveArray(nums = [3,8,20])
    >>> 3
    Explanation: The initial sum of nums is equal to 3 + 8 + 20 = 31.
    The following is one of the ways to reduce the sum by at least half:
    Pick the number 20 and reduce it to 10.
    Pick the number 10 and reduce it to 5.
    Pick the number 3 and reduce it to 1.5.
    The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5.
    The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 15.5.
    Overall, 3 operations were used so we return 3.
    It can be shown that we cannot reduce the sum by at least half in less than 3 operations.
    """


Prompt:
def minimumWhiteTiles(floor: str, numCarpets: int, carpetLen: int) -> int:
    """
    You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:

    floor[i] = '0' denotes that the ith tile of the floor is colored black.
    On the other hand, floor[i] = '1' denotes that the ith tile of the floor is colored white.

    You are also given numCarpets and carpetLen. You have numCarpets black carpets, each of length carpetLen tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.
    Return the minimum number of white tiles still visible.

    Example 1:

    >>> minimumWhiteTiles(floor = "10110101", numCarpets = 2, carpetLen = 2)
    >>> 2
    Explanation:
    The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.
    No other way of covering the tiles with the carpets can leave less than 2 white tiles visible.

    Example 2:

    >>> minimumWhiteTiles(floor = "11111", numCarpets = 2, carpetLen = 3)
    >>> 0
    Explanation:
    The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.
    Note that the carpets are able to overlap one another.
    """


Prompt:
from typing import List
def countHillValley(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]. Adjacent indices i and j are part of the same hill or valley if nums[i] == nums[j].
    Note that for an index to be part of a hill or valley, it must have a non-equal neighbor on both the left and right of the index.
    Return the number of hills and valleys in nums.

    Example 1:

    >>> countHillValley(nums = [2,4,1,1,6,5])
    >>> 3
    Explanation:
    At index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley.
    At index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill.
    At index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley.
    At index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2.
    At index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill.
    At index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley.
    There are 3 hills and valleys so we return 3.

    Example 2:

    >>> countHillValley(nums = [6,6,5,5,4,1])
    >>> 0
    Explanation:
    At index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley.
    At index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley.
    At index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley.
    At index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley.
    At index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley.
    At index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley.
    There are 0 hills and valleys so we return 0.
    """


Prompt:
def countCollisions(directions: str) -> int:
    """
    There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point.
    You are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whether the ith car is moving towards the left, towards the right, or staying at its current point respectively. Each moving car has the same speed.
    The number of collisions can be calculated as follows:

    When two cars moving in opposite directions collide with each other, the number of collisions increases by 2.
    When a moving car collides with a stationary car, the number of collisions increases by 1.

    After a collision, the cars involved can no longer move and will stay at the point where they collided. Other than that, cars cannot change their state or direction of motion.
    Return the total number of collisions that will happen on the road.

    Example 1:

    >>> countCollisions(directions = "RLRSLL")
    >>> 5
    Explanation:
    The collisions that will happen on the road are:
    - Cars 0 and 1 will collide with each other. Since they are moving in opposite directions, the number of collisions becomes 0 + 2 = 2.
    - Cars 2 and 3 will collide with each other. Since car 3 is stationary, the number of collisions becomes 2 + 1 = 3.
    - Cars 3 and 4 will collide with each other. Since car 3 is stationary, the number of collisions becomes 3 + 1 = 4.
    - Cars 4 and 5 will collide with each other. After car 4 collides with car 3, it will stay at the point of collision and get hit by car 5. The number of collisions becomes 4 + 1 = 5.
    Thus, the total number of collisions that will happen on the road is 5.

    Example 2:

    >>> countCollisions(directions = "LLRR")
    >>> 0
    Explanation:
    No cars will collide with each other. Thus, the total number of collisions that will happen on the road is 0.
    """


Prompt:
from typing import List
def maximumBobPoints(numArrows: int, aliceArrows: List[int]) -> List[int]:
    """
    Alice and Bob are opponents in an archery competition. The competition has set the following rules:

    Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.
    The points are then calculated as follows:

    The target has integer scoring sections ranging from 0 to 11 inclusive.
    For each section of the target with score k (in between 0 to 11), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak >= bk, then Alice takes k points. If ak < bk, then Bob takes k points.
    However, if ak == bk == 0, then nobody takes k points.

    For example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 points.

    You are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Now, Bob wants to maximize the total number of points he can obtain.
    Return the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.
    If there are multiple ways for Bob to earn the maximum total points, return any one of them.

    Example 1:

    >>> maximumBobPoints(numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0])
    >>> [0,0,0,0,1,1,0,0,1,2,3,1]
    Explanation: The table above shows how the competition is scored.
    Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.
    It can be shown that Bob cannot obtain a score higher than 47 points.

    Example 2:

    >>> maximumBobPoints(numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2])
    >>> [0,0,0,0,0,0,0,0,1,1,1,0]
    Explanation: The table above shows how the competition is scored.
    Bob earns a total point of 8 + 9 + 10 = 27.
    It can be shown that Bob cannot obtain a score higher than 27 points.
    """


Prompt:
from typing import List
def longestRepeating(s: str, queryCharacters: str, queryIndices: List[int]) -> List[int]:
    """
    You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries.
    The ith query updates the character in s at index queryIndices[i] to the character queryCharacters[i].
    Return an array lengths of length k where lengths[i] is the length of the longest substring of s consisting of only one repeating character after the ith query is performed.

    Example 1:

    >>> longestRepeating(s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3])
    >>> [3,3,4]
    Explanation:
    - 1st query updates s = "bbbacc". The longest substring consisting of one repeating character is "bbb" with length 3.
    - 2nd query updates s = "bbbccc".
      The longest substring consisting of one repeating character can be "bbb" or "ccc" with length 3.
    - 3rd query updates s = "bbbbcc". The longest substring consisting of one repeating character is "bbbb" with length 4.
    Thus, we return [3,3,4].

    Example 2:

    >>> longestRepeating(s = "abyzz", queryCharacters = "aa", queryIndices = [2,1])
    >>> [2,3]
    Explanation:
    - 1st query updates s = "abazz". The longest substring consisting of one repeating character is "zz" with length 2.
    - 2nd query updates s = "aaazz". The longest substring consisting of one repeating character is "aaa" with length 3.
    Thus, we return [2,3].
    """


Prompt:
from typing import List
def minimumHealth(damage: List[int], armor: int) -> int:
    """
    You are playing a game that has n levels numbered from 0 to n - 1. You are given a 0-indexed integer array damage where damage[i] is the amount of health you will lose to complete the ith level.
    You are also given an integer armor. You may use your armor ability at most once during the game on any level which will protect you from at most armor damage.
    You must complete the levels in order and your health must be greater than 0 at all times to beat the game.
    Return the minimum health you need to start with to beat the game.

    Example 1:

    >>> minimumHealth(damage = [2,7,4,3], armor = 4)
    >>> 13
    Explanation: One optimal way to beat the game starting at 13 health is:
    On round 1, take 2 damage. You have 13 - 2 = 11 health.
    On round 2, take 7 damage. You have 11 - 7 = 4 health.
    On round 3, use your armor to protect you from 4 damage. You have 4 - 0 = 4 health.
    On round 4, take 3 damage. You have 4 - 3 = 1 health.
    Note that 13 is the minimum health you need to start with to beat the game.

    Example 2:

    >>> minimumHealth(damage = [2,5,3,4], armor = 7)
    >>> 10
    Explanation: One optimal way to beat the game starting at 10 health is:
    On round 1, take 2 damage. You have 10 - 2 = 8 health.
    On round 2, use your armor to protect you from 5 damage. You have 8 - 0 = 8 health.
    On round 3, take 3 damage. You have 8 - 3 = 5 health.
    On round 4, take 4 damage. You have 5 - 4 = 1 health.
    Note that 10 is the minimum health you need to start with to beat the game.

    Example 3:

    >>> minimumHealth(damage = [3,3,3], armor = 0)
    >>> 10
    Explanation: One optimal way to beat the game starting at 10 health is:
    On round 1, take 3 damage. You have 10 - 3 = 7 health.
    On round 2, take 3 damage. You have 7 - 3 = 4 health.
    On round 3, take 3 damage. You have 4 - 3 = 1 health.
    Note that you did not use your armor ability.
    """


Prompt:
from typing import List
def findDifference(nums1: List[int], nums2: List[int]) -> List[List[int]]:
    """
    Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:

    answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
    answer[1] is a list of all distinct integers in nums2 which are not present in nums1.

    Note that the integers in the lists may be returned in any order.

    Example 1:

    >>> findDifference(nums1 = [1,2,3], nums2 = [2,4,6])
    >>> [[1,3],[4,6]]
    Explanation:
    For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
    For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].
    Example 2:

    >>> findDifference(nums1 = [1,2,3,3], nums2 = [1,1,2,2])
    >>> [[3],[]]
    Explanation:
    For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].
    Every integer in nums2 is present in nums1. Therefore, answer[1] = [].
    """


Prompt:
from typing import List
def minDeletion(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. The array nums is beautiful if:

    nums.length is even.
    nums[i] != nums[i + 1] for all i % 2 == 0.

    Note that an empty array is considered beautiful.
    You can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted element will be shifted one unit to the left to fill the gap created and all the elements to the left of the deleted element will remain unchanged.
    Return the minimum number of elements to delete from nums to make it beautiful.

    Example 1:

    >>> minDeletion(nums = [1,1,2,3,5])
    >>> 1
    Explanation: You can delete either nums[0] or nums[1] to make nums = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make nums beautiful.

    Example 2:

    >>> minDeletion(nums = [1,1,2,2,3,3])
    >>> 2
    Explanation: You can delete nums[0] and nums[5] to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.
    """


Prompt:
from typing import List
def kthPalindrome(queries: List[int], intLength: int) -> List[int]:
    """
    Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]th smallest positive palindrome of length intLength or -1 if no such palindrome exists.
    A palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.

    Example 1:

    >>> kthPalindrome(queries = [1,2,3,4,5,90], intLength = 3)
    >>> [101,111,121,131,141,999]
    Explanation:
    The first few palindromes of length 3 are:
    101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...
    The 90th palindrome of length 3 is 999.

    Example 2:

    >>> kthPalindrome(queries = [2,4,6], intLength = 4)
    >>> [1111,1331,1551]
    Explanation:
    The first six palindromes of length 4 are:
    1001, 1111, 1221, 1331, 1441, and 1551.
    """


Prompt:
from typing import List
def maxValueOfCoins(piles: List[List[int]], k: int) -> int:
    """
    There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations.
    In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet.
    Given a list piles, where piles[i] is a list of integers denoting the composition of the ith pile from top to bottom, and a positive integer k, return the maximum total value of coins you can have in your wallet if you choose exactly k coins optimally.

    Example 1:

    >>> maxValueOfCoins(piles = [[1,100,3],[7,8,9]], k = 2)
    >>> 101
    Explanation:
    The above diagram shows the different ways we can choose k coins.
    The maximum total we can obtain is 101.

    Example 2:

    >>> maxValueOfCoins(piles = [[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7)
    >>> 706
    Explanation:
    The maximum total can be obtained if we choose all coins from the last pile.
    """


Prompt:
from typing import List
def maximumSumScore(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n.
    The sum score of nums at an index i where 0 <= i < n is the maximum of:

    The sum of the first i + 1 elements of nums.
    The sum of the last n - i elements of nums.

    Return the maximum sum score of nums at any index.

    Example 1:

    >>> maximumSumScore(nums = [4,3,-2,5])
    >>> 10
    Explanation:
    The sum score at index 0 is max(4, 4 + 3 + -2 + 5) = max(4, 10) = 10.
    The sum score at index 1 is max(4 + 3, 3 + -2 + 5) = max(7, 6) = 7.
    The sum score at index 2 is max(4 + 3 + -2, -2 + 5) = max(5, 3) = 5.
    The sum score at index 3 is max(4 + 3 + -2 + 5, 5) = max(10, 5) = 10.
    The maximum sum score of nums is 10.

    Example 2:

    >>> maximumSumScore(nums = [-3,-5])
    >>> -3
    Explanation:
    The sum score at index 0 is max(-3, -3 + -5) = max(-3, -8) = -3.
    The sum score at index 1 is max(-3 + -5, -5) = max(-8, -5) = -5.
    The maximum sum score of nums is -3.
    """


Prompt:
def minBitFlips(start: int, goal: int) -> int:
    """
    A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0.

    For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc.

    Given two integers start and goal, return the minimum number of bit flips to convert start to goal.

    Example 1:

    >>> minBitFlips(start = 10, goal = 7)
    >>> 3
    Explanation: The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps:
    - Flip the first bit from the right: 1010 -> 1011.
    - Flip the third bit from the right: 1011 -> 1111.
    - Flip the fourth bit from the right: 1111 -> 0111.
    It can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.
    Example 2:

    >>> minBitFlips(start = 3, goal = 4)
    >>> 3
    Explanation: The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps:
    - Flip the first bit from the right: 011 -> 010.
    - Flip the second bit from the right: 010 -> 000.
    - Flip the third bit from the right: 000 -> 100.
    It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3.
    """


Prompt:
from typing import List
def triangularSum(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).
    The triangular sum of nums is the value of the only element present in nums after the following process terminates:

    Let nums comprise of n elements. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n - 1.
    For each index i, where 0 <= i < n - 1, assign the value of newNums[i] as (nums[i] + nums[i+1]) % 10, where % denotes modulo operator.
    Replace the array nums with newNums.
    Repeat the entire process starting from step 1.

    Return the triangular sum of nums.

    Example 1:

    >>> triangularSum(nums = [1,2,3,4,5])
    >>> 8
    Explanation:
    The above diagram depicts the process from which we obtain the triangular sum of the array.
    Example 2:

    >>> triangularSum(nums = [5])
    >>> 5
    Explanation:
    Since there is only one element in nums, the triangular sum is the value of that element itself.
    """


Prompt:
def numberOfWays(s: str) -> int:
    """
    You are given a 0-indexed binary string s which represents the types of buildings along a street where:

    s[i] = '0' denotes that the ith building is an office and
    s[i] = '1' denotes that the ith building is a restaurant.

    As a city official, you would like to select 3 buildings for random inspection. However, to ensure variety, no two consecutive buildings out of the selected buildings can be of the same type.

    For example, given s = "001101", we cannot select the 1st, 3rd, and 5th buildings as that would form "011" which is not allowed due to having two consecutive buildings of the same type.

    Return the number of valid ways to select 3 buildings.

    Example 1:

    >>> numberOfWays(s = "001101")
    >>> 6
    Explanation:
    The following sets of indices selected are valid:
    - [0,2,4] from "001101" forms "010"
    - [0,3,4] from "001101" forms "010"
    - [1,2,4] from "001101" forms "010"
    - [1,3,4] from "001101" forms "010"
    - [2,4,5] from "001101" forms "101"
    - [3,4,5] from "001101" forms "101"
    No other selection is valid. Thus, there are 6 total ways.

    Example 2:

    >>> numberOfWays(s = "11100")
    >>> 0
    Explanation: It can be shown that there are no valid selections.
    """


Prompt:
def sumScores(s: str) -> int:
    """
    You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled si.

    For example, for s = "abaca", s1 == "a", s2 == "ca", s3 == "aca", etc.

    The score of si is the length of the longest common prefix between si and sn (Note that s == sn).
    Given the final string s, return the sum of the score of every si.

    Example 1:

    >>> sumScores(s = "babab")
    >>> 9
    Explanation:
    For s1 == "b", the longest common prefix is "b" which has a score of 1.
    For s2 == "ab", there is no common prefix so the score is 0.
    For s3 == "bab", the longest common prefix is "bab" which has a score of 3.
    For s4 == "abab", there is no common prefix so the score is 0.
    For s5 == "babab", the longest common prefix is "babab" which has a score of 5.
    The sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.
    Example 2:

    >>> sumScores(s = "azbazbzaz")
    >>> 14
    Explanation:
    For s2 == "az", the longest common prefix is "az" which has a score of 2.
    For s6 == "azbzaz", the longest common prefix is "azb" which has a score of 3.
    For s9 == "azbazbzaz", the longest common prefix is "azbazbzaz" which has a score of 9.
    For all other si, the score is 0.
    The sum of the scores is 2 + 3 + 9 = 14, so we return 14.
    """


Prompt:
def convertTime(current: str, correct: str) -> int:
    """
    You are given two strings current and correct representing two 24-hour times.
    24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.
    In one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.
    Return the minimum number of operations needed to convert current to correct.

    Example 1:

    >>> convertTime(current = "02:30", correct = "04:35")
    >>> 3
    Explanation:
    We can convert current to correct in 3 operations as follows:
    - Add 60 minutes to current. current becomes "03:30".
    - Add 60 minutes to current. current becomes "04:30".
    - Add 5 minutes to current. current becomes "04:35".
    It can be proven that it is not possible to convert current to correct in fewer than 3 operations.
    Example 2:

    >>> convertTime(current = "11:00", correct = "11:01")
    >>> 1
    Explanation: We only have to add one minute to current, so the minimum number of operations needed is 1.
    """


Prompt:
from typing import List
def findWinners(matches: List[List[int]]) -> List[List[int]]:
    """
    You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.
    Return a list answer of size 2 where:

    answer[0] is a list of all players that have not lost any matches.
    answer[1] is a list of all players that have lost exactly one match.

    The values in the two lists should be returned in increasing order.
    Note:

    You should only consider the players that have played at least one match.
    The testcases will be generated such that no two matches will have the same outcome.

    Example 1:

    >>> findWinners(matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]])
    >>> [[1,2,10],[4,5,7,8]]
    Explanation:
    Players 1, 2, and 10 have not lost any matches.
    Players 4, 5, 7, and 8 each have lost one match.
    Players 3, 6, and 9 each have lost two matches.
    Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].

    Example 2:

    >>> findWinners(matches = [[2,3],[1,3],[5,4],[6,4]])
    >>> [[1,2,5,6],[]]
    Explanation:
    Players 1, 2, 5, and 6 have not lost any matches.
    Players 3 and 4 each have lost two matches.
    Thus, answer[0] = [1,2,5,6] and answer[1] = [].
    """


Prompt:
from typing import List
def maximumCandies(candies: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.
    You are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can be allocated candies from only one pile of candies and some piles of candies may go unused.
    Return the maximum number of candies each child can get.

    Example 1:

    >>> maximumCandies(candies = [5,8,6], k = 3)
    >>> 5
    Explanation: We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies.

    Example 2:

    >>> maximumCandies(candies = [2,5], k = 11)
    >>> 0
    Explanation: There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0.
    """


Prompt:
from typing import List
def isConsecutive(nums: List[int]) -> bool:
    """
    Given an integer array nums, return true if nums is consecutive, otherwise return false.
    An array is consecutive if it contains every number in the range [x, x + n - 1] (inclusive), where x is the minimum number in the array and n is the length of the array.

    Example 1:

    >>> isConsecutive(nums = [1,3,4,2])
    >>> true
    Explanation:
    The minimum value is 1 and the length of nums is 4.
    All of the values in the range [x, x + n - 1] = [1, 1 + 4 - 1] = [1, 4] = (1, 2, 3, 4) occur in nums.
    Therefore, nums is consecutive.

    Example 2:

    >>> isConsecutive(nums = [1,3])
    >>> false
    Explanation:
    The minimum value is 1 and the length of nums is 2.
    The value 2 in the range [x, x + n - 1] = [1, 1 + 2 - 1], = [1, 2] = (1, 2) does not occur in nums.
    Therefore, nums is not consecutive.

    Example 3:

    >>> isConsecutive(nums = [3,5,4])
    >>> true
    Explanation:
    The minimum value is 3 and the length of nums is 3.
    All of the values in the range [x, x + n - 1] = [3, 3 + 3 - 1] = [3, 5] = (3, 4, 5) occur in nums.
    Therefore, nums is consecutive.
    """


Prompt:
def largestInteger(num: int) -> int:
    """
    You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).
    Return the largest possible value of num after any number of swaps.

    Example 1:

    >>> largestInteger(num = 1234)
    >>> 3412
    Explanation: Swap the digit 3 with the digit 1, this results in the number 3214.
    Swap the digit 2 with the digit 4, this results in the number 3412.
    Note that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.
    Also note that we may not swap the digit 4 with the digit 1 since they are of different parities.

    Example 2:

    >>> largestInteger(num = 65875)
    >>> 87655
    Explanation: Swap the digit 8 with the digit 6, this results in the number 85675.
    Swap the first digit 5 with the digit 7, this results in the number 87655.
    Note that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number.
    """


Prompt:
def minimizeResult(expression: str) -> str:
    """
    You are given a 0-indexed string expression of the form "+" where  and  represent positive integers.
    Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of '+' and the right parenthesis must be added to the right of '+'.
    Return expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If there are multiple answers that yield the same result, return any of them.
    The input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.

    Example 1:

    >>> minimizeResult(expression = "247+38")
    >>> "2(47+38)"
    Explanation: The expression evaluates to 2 * (47 + 38) = 2 * 85 = 170.
    Note that "2(4)7+38" is invalid because the right parenthesis must be to the right of the '+'.
    It can be shown that 170 is the smallest possible value.

    Example 2:

    >>> minimizeResult(expression = "12+34")
    >>> "1(2+3)4"
    Explanation: The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20.

    Example 3:

    >>> minimizeResult(expression = "999+999")
    >>> "(999+999)"
    Explanation: The expression evaluates to 999 + 999 = 1998.
    """


Prompt:
from typing import List
def maximumProduct(nums: List[int], k: int) -> int:
    """
    You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.
    Return the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 109 + 7. Note that you should maximize the product before taking the modulo.

    Example 1:

    >>> maximumProduct(nums = [0,4], k = 5)
    >>> 20
    Explanation: Increment the first number 5 times.
    Now nums = [5, 4], with a product of 5 * 4 = 20.
    It can be shown that 20 is maximum product possible, so we return 20.
    Note that there may be other ways to increment nums to have the maximum product.

    Example 2:

    >>> maximumProduct(nums = [6,3,3,2], k = 2)
    >>> 216
    Explanation: Increment the second number 1 time and increment the fourth number 1 time.
    Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.
    It can be shown that 216 is maximum product possible, so we return 216.
    Note that there may be other ways to increment nums to have the maximum product.
    """


Prompt:
from typing import List
def maximumBeauty(flowers: List[int], newFlowers: int, target: int, full: int, partial: int) -> int:
    """
    Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.
    You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the ith garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.
    A garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:

    The number of complete gardens multiplied by full.
    The minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.

    Return the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.

    Example 1:

    >>> maximumBeauty(flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1)
    >>> 14
    Explanation: Alice can plant
    - 2 flowers in the 0th garden
    - 3 flowers in the 1st garden
    - 1 flower in the 2nd garden
    - 1 flower in the 3rd garden
    The gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.
    There is 1 garden that is complete.
    The minimum number of flowers in the incomplete gardens is 2.
    Thus, the total beauty is 1 * 12 + 2 * 1 = 12 + 2 = 14.
    No other way of planting flowers can obtain a total beauty higher than 14.

    Example 2:

    >>> maximumBeauty(flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6)
    >>> 30
    Explanation: Alice can plant
    - 3 flowers in the 0th garden
    - 0 flowers in the 1st garden
    - 0 flowers in the 2nd garden
    - 2 flowers in the 3rd garden
    The gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.
    There are 3 gardens that are complete.
    The minimum number of flowers in the incomplete gardens is 4.
    Thus, the total beauty is 3 * 2 + 4 * 6 = 6 + 24 = 30.
    No other way of planting flowers can obtain a total beauty higher than 30.
    Note that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty.
    """


Prompt:
def sum(num1: int, num2: int) -> int:
    """
    Given two integers num1 and num2, return the sum of the two integers.

    Example 1:

    >>> sum(num1 = 12, num2 = 5)
    >>> 17
    Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.

    Example 2:

    >>> sum(num1 = -10, num2 = 4)
    >>> -6
    Explanation: num1 + num2 = -6, so -6 is returned.
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def checkTree(root: Optional[TreeNode]) -> bool:
"""
You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.
Return true if the value of the root is equal to the sum of the values of its two children, or false otherwise.

Example 1:

>>> checkTree(root = [10,4,6])
>>> true
Explanation: The values of the root, its left child, and its right child are 10, 4, and 6, respectively.
10 is equal to 4 + 6, so we return true.

Example 2:

>>> checkTree(root = [5,3,1])
>>> false
Explanation: The values of the root, its left child, and its right child are 5, 3, and 1, respectively.
5 is not equal to 3 + 1, so we return false.
"""


Prompt:
from typing import List
def meetRequirement(n: int, lights: List[List[int]], requirement: List[int]) -> int:
    """
    You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that lights up the area from [max(0, positioni - rangei), min(n - 1, positioni + rangei)] (inclusive).
    The brightness of a position p is defined as the number of street lamps that light up the position p. You are given a 0-indexed integer array requirement of size n where requirement[i] is the minimum brightness of the ith position on the street.
    Return the number of positions i on the street between 0 and n - 1 that have a brightness of at least requirement[i].

    Example 1:

    >>> meetRequirement(n = 5, lights = [[0,1],[2,1],[3,2]], requirement = [0,2,1,4,1])
    >>> 4
    Explanation:
    - The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 1] (inclusive).
    - The second street lamp lights up the area from [max(0, 2 - 1), min(n - 1, 2 + 1)] = [1, 3] (inclusive).
    - The third street lamp lights up the area from [max(0, 3 - 2), min(n - 1, 3 + 2)] = [1, 4] (inclusive).

    - Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is greater than requirement[0].
    - Position 1 is covered by the first, second, and third street lamps. It is covered by 3 street lamps which is greater than requirement[1].
    - Position 2 is covered by the second and third street lamps. It is covered by 2 street lamps which is greater than requirement[2].
    - Position 3 is covered by the second and third street lamps. It is covered by 2 street lamps which is less than requirement[3].
    - Position 4 is covered by the third street lamp. It is covered by 1 street lamp which is equal to requirement[4].

    Positions 0, 1, 2, and 4 meet the requirement so we return 4.

    Example 2:

    >>> meetRequirement(n = 1, lights = [[0,1]], requirement = [2])
    >>> 0
    Explanation:
    - The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 0] (inclusive).
    - Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is less than requirement[0].
    - We return 0 because no position meets their brightness requirement.
    """


Prompt:
from typing import List
def findClosestNumber(nums: List[int]) -> int:
    """
    Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value.

    Example 1:

    >>> findClosestNumber(nums = [-4,-2,1,4,8])
    >>> 1
    Explanation:
    The distance from -4 to 0 is |-4| = 4.
    The distance from -2 to 0 is |-2| = 2.
    The distance from 1 to 0 is |1| = 1.
    The distance from 4 to 0 is |4| = 4.
    The distance from 8 to 0 is |8| = 8.
    Thus, the closest number to 0 in the array is 1.

    Example 2:

    >>> findClosestNumber(nums = [2,-1,1])
    >>> 1
    Explanation: 1 and -1 are both the closest numbers to 0, so 1 being larger is returned.
    """


Prompt:
def waysToBuyPensPencils(total: int, cost1: int, cost2: int) -> int:
    """
    You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.
    Return the number of distinct ways you can buy some number of pens and pencils.

    Example 1:

    >>> waysToBuyPensPencils(total = 20, cost1 = 10, cost2 = 5)
    >>> 9
    Explanation: The price of a pen is 10 and the price of a pencil is 5.
    - If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.
    - If you buy 1 pen, you can buy 0, 1, or 2 pencils.
    - If you buy 2 pens, you cannot buy any pencils.
    The total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.

    Example 2:

    >>> waysToBuyPensPencils(total = 5, cost1 = 10, cost2 = 10)
    >>> 1
    Explanation: The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.
    """


Prompt:
from typing import List
def maximumScore(scores: List[int], edges: List[List[int]]) -> int:
    """
    There is an undirected graph with n nodes, numbered from 0 to n - 1.
    You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.
    A node sequence is valid if it meets the following conditions:

    There is an edge connecting every pair of adjacent nodes in the sequence.
    No node appears more than once in the sequence.

    The score of a node sequence is defined as the sum of the scores of the nodes in the sequence.
    Return the maximum score of a valid node sequence with a length of 4. If no such sequence exists, return -1.

    Example 1:

    >>> maximumScore(scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]])
    >>> 24
    Explanation: The figure above shows the graph and the chosen node sequence [0,1,2,3].
    The score of the node sequence is 5 + 2 + 9 + 8 = 24.
    It can be shown that no other node sequence has a score of more than 24.
    Note that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.
    The sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3.

    Example 2:

    >>> maximumScore(scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]])
    >>> -1
    Explanation: The figure above shows the graph.
    There are no valid node sequences of length 4, so we return -1.
    """


Prompt:
def digitSum(s: str, k: int) -> str:
    """
    You are given a string s consisting of digits and an integer k.
    A round can be completed if the length of s is greater than k. In one round, do the following:

    Divide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on. Note that the size of the last group can be smaller than k.
    Replace each group of s with a string representing the sum of all its digits. For example, "346" is replaced with "13" because 3 + 4 + 6 = 13.
    Merge consecutive groups together to form a new string. If the length of the string is greater than k, repeat from step 1.

    Return s after all rounds have been completed.

    Example 1:

    >>> digitSum(s = "11111222223", k = 3)
    >>> "135"
    Explanation:
    - For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".
      Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
      So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.
    - For the second round, we divide s into "346" and "5".
      Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
      So, s becomes "13" + "5" = "135" after second round.
    Now, s.length <= k, so we return "135" as the answer.

    Example 2:

    >>> digitSum(s = "00000000", k = 3)
    >>> "000"
    Explanation:
    We divide s into "000", "000", and "00".
    Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
    s becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".
    """


Prompt:
from typing import List
def minimumRounds(tasks: List[int]) -> int:
    """
    You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.
    Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.

    Example 1:

    >>> minimumRounds(tasks = [2,2,3,3,2,4,4,4,4,4])
    >>> 4
    Explanation: To complete all the tasks, a possible plan is:
    - In the first round, you complete 3 tasks of difficulty level 2.
    - In the second round, you complete 2 tasks of difficulty level 3.
    - In the third round, you complete 3 tasks of difficulty level 4.
    - In the fourth round, you complete 2 tasks of difficulty level 4.
    It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.

    Example 2:

    >>> minimumRounds(tasks = [2,3,3])
    >>> -1
    Explanation: There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.
    """


Prompt:
from typing import List
def maxTrailingZeros(grid: List[List[int]]) -> int:
    """
    You are given a 2D integer array grid of size m x n, where each cell contains a positive integer.
    A cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the alternate direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell.
    The product of a path is defined as the product of all the values in the path.
    Return the maximum number of trailing zeros in the product of a cornered path found in grid.
    Note:

    Horizontal movement means moving in either the left or right direction.
    Vertical movement means moving in either the up or down direction.

    Example 1:

    >>> maxTrailingZeros(grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]])
    >>> 3
    Explanation: The grid on the left shows a valid cornered path.
    It has a product of 15 * 20 * 6 * 1 * 10 = 18000 which has 3 trailing zeros.
    It can be shown that this is the maximum trailing zeros in the product of a cornered path.

    The grid in the middle is not a cornered path as it has more than one turn.
    The grid on the right is not a cornered path as it requires a return to a previously visited cell.

    Example 2:

    >>> maxTrailingZeros(grid = [[4,3,2],[7,6,1],[8,8,8]])
    >>> 0
    Explanation: The grid is shown in the figure above.
    There are no cornered paths in the grid that result in a product with a trailing zero.
    """


Prompt:
from typing import List
def longestPath(parent: List[int], s: str) -> int:
    """
    You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
    You are also given a string s of length n, where s[i] is the character assigned to node i.
    Return the length of the longest path in the tree such that no pair of adjacent nodes on the path have the same character assigned to them.

    Example 1:

    >>> longestPath(parent = [-1,0,0,1,1,2], s = "abacbe")
    >>> 3
    Explanation: The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.
    It can be proven that there is no longer path that satisfies the conditions.

    Example 2:

    >>> longestPath(parent = [-1,0,0,0], s = "aabc")
    >>> 3
    Explanation: The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned.
    """


Prompt:
from typing import List
def maximumCost(n: int, highways: List[List[int]], k: int) -> int:
    """
    A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, allowing a car to go from city1i to city2i and vice versa for a cost of tolli.
    You are also given an integer k. You are going on a trip that crosses exactly k highways. You may start at any city, but you may only visit each city at most once during your trip.
    Return the maximum cost of your trip. If there is no trip that meets the requirements, return -1.

    Example 1:

    >>> maximumCost(n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], k = 3)
    >>> 17
    Explanation:
    One possible trip is to go from 0 -> 1 -> 4 -> 3. The cost of this trip is 4 + 11 + 2 = 17.
    Another possible trip is to go from 4 -> 1 -> 2 -> 3. The cost of this trip is 11 + 3 + 3 = 17.
    It can be proven that 17 is the maximum possible cost of any valid trip.

    Note that the trip 4 -> 1 -> 0 -> 1 is not allowed because you visit the city 1 twice.

    Example 2:

    >>> maximumCost(n = 4, highways = [[0,1,3],[2,3,2]], k = 2)
    >>> -1
    Explanation: There are no valid trips of length 2, so return -1.
    """


Prompt:
from typing import List
def intersection(nums: List[List[int]]) -> List[int]:
    """
    Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.

    Example 1:

    >>> intersection(nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]])
    >>> [3,4]
    Explanation:
    The only integers present in each of nums[0] = [3,1,2,4,5], nums[1] = [1,2,3,4], and nums[2] = [3,4,5,6] are 3 and 4, so we return [3,4].
    Example 2:

    >>> intersection(nums = [[1,2,3],[4,5,6]])
    >>> []
    Explanation:
    There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].
    """


Prompt:
from typing import List
def countLatticePoints(circles: List[List[int]]) -> int:
    """
    Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one circle.
    Note:

    A lattice point is a point with integer coordinates.
    Points that lie on the circumference of a circle are also considered to be inside it.

    Example 1:

    >>> countLatticePoints(circles = [[2,2,1]])
    >>> 5
    Explanation:
    The figure above shows the given circle.
    The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.
    Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.
    Hence, the number of lattice points present inside at least one circle is 5.
    Example 2:

    >>> countLatticePoints(circles = [[2,2,2],[3,4,1]])
    >>> 16
    Explanation:
    The figure above shows the given circles.
    There are exactly 16 lattice points which are present inside at least one circle.
    Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
    """


Prompt:
from typing import List
def countRectangles(rectangles: List[List[int]], points: List[List[int]]) -> List[int]:
    """
    You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is a point with coordinates (xj, yj).
    The ith rectangle has its bottom-left corner point at the coordinates (0, 0) and its top-right corner point at (li, hi).
    Return an integer array count of length points.length where count[j] is the number of rectangles that contain the jth point.
    The ith rectangle contains the jth point if 0 <= xj <= li and 0 <= yj <= hi. Note that points that lie on the edges of a rectangle are also considered to be contained by that rectangle.

    Example 1:

    >>> countRectangles(rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]])
    >>> [2,1]
    Explanation:
    The first rectangle contains no points.
    The second rectangle contains only the point (2, 1).
    The third rectangle contains the points (2, 1) and (1, 4).
    The number of rectangles that contain the point (2, 1) is 2.
    The number of rectangles that contain the point (1, 4) is 1.
    Therefore, we return [2, 1].

    Example 2:

    >>> countRectangles(rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]])
    >>> [1,3]
    Explanation:
    The first rectangle contains only the point (1, 1).
    The second rectangle contains only the point (1, 1).
    The third rectangle contains the points (1, 3) and (1, 1).
    The number of rectangles that contain the point (1, 3) is 1.
    The number of rectangles that contain the point (1, 1) is 3.
    Therefore, we return [1, 3].
    """


Prompt:
from typing import List
def fullBloomFlowers(flowers: List[List[int]], people: List[int]) -> List[int]:
    """
    You are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the ith flower will be in full bloom from starti to endi (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is the time that the ith person will arrive to see the flowers.
    Return an integer array answer of size n, where answer[i] is the number of flowers that are in full bloom when the ith person arrives.

    Example 1:

    >>> fullBloomFlowers(flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11])
    >>> [1,2,2,2]
    Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
    For each person, we return the number of flowers in full bloom during their arrival.

    Example 2:

    >>> fullBloomFlowers(flowers = [[1,10],[3,3]], people = [3,3,2])
    >>> [2,2,1]
    Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
    For each person, we return the number of flowers in full bloom during their arrival.
    """


Prompt:
from typing import List
def countPrefixes(words: List[str], s: str) -> int:
    """
    You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters.
    Return the number of strings in words that are a prefix of s.
    A prefix of a string is a substring that occurs at the beginning of the string. A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> countPrefixes(words = ["a","b","c","ab","bc","abc"], s = "abc")
    >>> 3
    Explanation:
    The strings in words which are a prefix of s = "abc" are:
    "a", "ab", and "abc".
    Thus the number of strings in words which are a prefix of s is 3.
    Example 2:

    >>> countPrefixes(words = ["a","a"], s = "aa")
    >>> 2
    Explanation:
    Both of the strings are a prefix of s.
    Note that the same string can occur multiple times in words, and it should be counted each time.
    """


Prompt:
from typing import List
def minimumAverageDifference(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n.
    The average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer.
    Return the index with the minimum average difference. If there are multiple such indices, return the smallest one.
    Note:

    The absolute difference of two numbers is the absolute value of their difference.
    The average of n elements is the sum of the n elements divided (integer division) by n.
    The average of 0 elements is considered to be 0.

    Example 1:

    >>> minimumAverageDifference(nums = [2,5,3,9,5,3])
    >>> 3
    Explanation:
    - The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.
    - The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.
    - The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.
    - The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.
    - The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.
    - The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.
    The average difference of index 3 is the minimum average difference so return 3.

    Example 2:

    >>> minimumAverageDifference(nums = [0])
    >>> 0
    Explanation:
    The only index is 0 so return 0.
    The average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0.
    """


Prompt:
from typing import List
def countUnguarded(m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int:
    """
    You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of the ith guard and jth wall respectively.
    A guard can see every cell in the four cardinal directions (north, east, south, or west) starting from their position unless obstructed by a wall or another guard. A cell is guarded if there is at least one guard that can see it.
    Return the number of unoccupied cells that are not guarded.

    Example 1:

    >>> countUnguarded(m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]])
    >>> 7
    Explanation: The guarded and unguarded cells are shown in red and green respectively in the above diagram.
    There are a total of 7 unguarded cells, so we return 7.

    Example 2:

    >>> countUnguarded(m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]])
    >>> 4
    Explanation: The unguarded cells are shown in green in the above diagram.
    There are a total of 4 unguarded cells, so we return 4.
    """


Prompt:
from typing import List
def maximumMinutes(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values:

    0 represents grass,
    1 represents fire,
    2 represents a wall that you and fire cannot pass through.

    You are situated in the top-left cell, (0, 0), and you want to travel to the safehouse at the bottom-right cell, (m - 1, n - 1). Every minute, you may move to an adjacent grass cell. After your move, every fire cell will spread to all adjacent cells that are not walls.
    Return the maximum number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse. If this is impossible, return -1. If you can always reach the safehouse regardless of the minutes stayed, return 109.
    Note that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.
    A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).

    Example 1:

    >>> maximumMinutes(grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]])
    >>> 3
    Explanation: The figure above shows the scenario where you stay in the initial position for 3 minutes.
    You will still be able to safely reach the safehouse.
    Staying for more than 3 minutes will not allow you to safely reach the safehouse.
    Example 2:

    >>> maximumMinutes(grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]])
    >>> -1
    Explanation: The figure above shows the scenario where you immediately move towards the safehouse.
    Fire will spread to any cell you move towards and it is impossible to safely reach the safehouse.
    Thus, -1 is returned.

    Example 3:

    >>> maximumMinutes(grid = [[0,0,0],[2,2,0],[1,2,0]])
    >>> 1000000000
    Explanation: The figure above shows the initial grid.
    Notice that the fire is contained by walls and you will always be able to safely reach the safehouse.
    Thus, 109 is returned.
    """


Prompt:
def removeDigit(number: str, digit: str) -> str:
    """
    You are given a string number representing a positive integer and a character digit.
    Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in number.

    Example 1:

    >>> removeDigit(number = "123", digit = "3")
    >>> "12"
    Explanation: There is only one '3' in "123". After removing '3', the result is "12".

    Example 2:

    >>> removeDigit(number = "1231", digit = "1")
    >>> "231"
    Explanation: We can remove the first '1' to get "231" or remove the second '1' to get "123".
    Since 231 > 123, we return "231".

    Example 3:

    >>> removeDigit(number = "551", digit = "5")
    >>> "51"
    Explanation: We can remove either the first or second '5' from "551".
    Both result in the string "51".
    """


Prompt:
from typing import List
def minimumCardPickup(cards: List[int]) -> int:
    """
    You are given an integer array cards where cards[i] represents the value of the ith card. A pair of cards are matching if the cards have the same value.
    Return the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. If it is impossible to have matching cards, return -1.

    Example 1:

    >>> minimumCardPickup(cards = [3,4,2,3,4,7])
    >>> 4
    Explanation: We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal.

    Example 2:

    >>> minimumCardPickup(cards = [1,0,5,3])
    >>> -1
    Explanation: There is no way to pick up a set of consecutive cards that contain a pair of matching cards.
    """


Prompt:
from typing import List
def countDistinct(nums: List[int], k: int, p: int) -> int:
    """
    Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p.
    Two arrays nums1 and nums2 are said to be distinct if:

    They are of different lengths, or
    There exists at least one index i where nums1[i] != nums2[i].

    A subarray is defined as a non-empty contiguous sequence of elements in an array.

    Example 1:

    >>> countDistinct(nums = [2,3,3,2,2], k = 2, p = 2)
    >>> 11
    Explanation:
    The elements at indices 0, 3, and 4 are divisible by p = 2.
    The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:
    [2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].
    Note that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.
    The subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.

    Example 2:

    >>> countDistinct(nums = [1,2,3,4], k = 4, p = 1)
    >>> 10
    Explanation:
    All element of nums are divisible by p = 1.
    Also, every subarray of nums will have at most 4 elements that are divisible by 1.
    Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.
    """


Prompt:
def appealSum(s: str) -> int:
    """
    The appeal of a string is the number of distinct characters found in the string.

    For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.

    Given a string s, return the total appeal of all of its substrings.
    A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> appealSum(s = "abbca")
    >>> 28
    Explanation: The following are the substrings of "abbca":
    - Substrings of length 1: "a", "b", "b", "c", "a" have an appeal of 1, 1, 1, 1, and 1 respectively. The sum is 5.
    - Substrings of length 2: "ab", "bb", "bc", "ca" have an appeal of 2, 1, 2, and 2 respectively. The sum is 7.
    - Substrings of length 3: "abb", "bbc", "bca" have an appeal of 2, 2, and 3 respectively. The sum is 7.
    - Substrings of length 4: "abbc", "bbca" have an appeal of 3 and 3 respectively. The sum is 6.
    - Substrings of length 5: "abbca" has an appeal of 3. The sum is 3.
    The total sum is 5 + 7 + 7 + 6 + 3 = 28.

    Example 2:

    >>> appealSum(s = "code")
    >>> 20
    Explanation: The following are the substrings of "code":
    - Substrings of length 1: "c", "o", "d", "e" have an appeal of 1, 1, 1, and 1 respectively. The sum is 4.
    - Substrings of length 2: "co", "od", "de" have an appeal of 2, 2, and 2 respectively. The sum is 6.
    - Substrings of length 3: "cod", "ode" have an appeal of 3 and 3 respectively. The sum is 6.
    - Substrings of length 4: "code" has an appeal of 4. The sum is 4.
    The total sum is 4 + 6 + 6 + 4 = 20.
    """


Prompt:
from typing import List, Set
def convertArray(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. In one operation, you can:

    Choose an index i in the range 0 <= i < nums.length
    Set nums[i] to nums[i] + 1 or nums[i] - 1

    Return the minimum number of operations to make nums non-decreasing or non-increasing.

    Example 1:

    >>> convertArray(nums = [3,2,4,5,0])
    >>> 4
    Explanation:
    One possible way to turn nums into non-increasing order is to:
    - Add 1 to nums[1] once so that it becomes 3.
    - Subtract 1 from nums[2] once so it becomes 3.
    - Subtract 1 from nums[3] twice so it becomes 3.
    After doing the 4 operations, nums becomes [3,3,3,3,0] which is in non-increasing order.
    Note that it is also possible to turn nums into [4,4,4,4,0] in 4 operations.
    It can be proven that 4 is the minimum number of operations needed.

    Example 2:

    >>> convertArray(nums = [2,2,3,4])
    >>> 0
    Explanation: nums is already in non-decreasing order, so no operations are needed and we return 0.

    Example 3:

    >>> convertArray(nums = [0])
    >>> 0
    Explanation: nums is already in non-decreasing order, so no operations are needed and we return 0.
    """


Prompt:
def largestGoodInteger(num: str) -> str:
    """
    You are given a string num representing a large integer. An integer is good if it meets the following conditions:

    It is a substring of num with length 3.
    It consists of only one unique digit.

    Return the maximum good integer as a string or an empty string "" if no such integer exists.
    Note:

    A substring is a contiguous sequence of characters within a string.
    There may be leading zeroes in num or a good integer.

    Example 1:

    >>> largestGoodInteger(num = "6777133339")
    >>> "777"
    Explanation: There are two distinct good integers: "777" and "333".
    "777" is the largest, so we return "777".

    Example 2:

    >>> largestGoodInteger(num = "2300019")
    >>> "000"
    Explanation: "000" is the only good integer.

    Example 3:

    >>> largestGoodInteger(num = "42352338")
    >>> ""
    Explanation: No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
    """