Prompt:
def countInterestingSubarrays(nums: List[int], modulo: int, k: int) -> int:
    """
    You are given a 0-indexed integer array nums, an integer modulo, and an integer k.
    Your task is to find the count of subarrays that are interesting.
    A subarray nums[l..r] is interesting if the following condition holds:

    Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k.

    Return an integer denoting the count of interesting subarrays.
    Note: A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> countInterestingSubarrays(nums = [3,2,4], modulo = 2, k = 1)
    >>> 3
    Explanation: In this example the interesting subarrays are:
    The subarray nums[0..0] which is [3].
    - There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k.
    - Hence, cnt = 1 and cnt % modulo == k.
    The subarray nums[0..1] which is [3,2].
    - There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.
    - Hence, cnt = 1 and cnt % modulo == k.
    The subarray nums[0..2] which is [3,2,4].
    - There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k.
    - Hence, cnt = 1 and cnt % modulo == k.
    It can be shown that there are no other interesting subarrays. So, the answer is 3.
    Example 2:

    >>> countInterestingSubarrays(nums = [3,1,9,6], modulo = 3, k = 0)
    >>> 2
    Explanation: In this example the interesting subarrays are:
    The subarray nums[0..3] which is [3,1,9,6].
    - There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k.
    - Hence, cnt = 3 and cnt % modulo == k.
    The subarray nums[1..1] which is [1].
    - There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k.
    - Hence, cnt = 0 and cnt % modulo == k.
    It can be shown that there are no other interesting subarrays. So, the answer is 2.
    """


Prompt:
def minOperationsQueries(n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi in the tree.
    You are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, find the minimum number of operations required to make the weight of every edge on the path from ai to bi equal. In one operation, you can choose any edge of the tree and change its weight to any value.
    Note that:

    Queries are independent of each other, meaning that the tree returns to its initial state on each new query.
    The path from ai to bi is a sequence of distinct nodes starting with node ai and ending with node bi such that every two adjacent nodes in the sequence share an edge in the tree.

    Return an array answer of length m where answer[i] is the answer to the ith query.

    Example 1:

    >>> minOperationsQueries(n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]])
    >>> [0,0,1,3]
    Explanation: In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.
    In the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0.
    In the third query, we change the weight of edge [2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.
    In the fourth query, we change the weights of edges [0,1], [1,2] and [2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3.
    For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.

    Example 2:

    >>> minOperationsQueries(n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]])
    >>> [1,2,2,3]
    Explanation: In the first query, we change the weight of edge [1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.
    In the second query, we change the weight of edges [0,3] and [3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.
    In the third query, we change the weight of edges [1,3] and [5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.
    In the fourth query, we change the weights of edges [0,7], [0,3] and [1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3.
    For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.
    """


Prompt:
def smallestNumber(n: int) -> str:
    """
    Given a positive integer n, return a string representing the smallest positive integer such that the product of its digits is equal to n, or "-1" if no such number exists.

    Example 1:

    >>> smallestNumber(n = 105)
    >>> "357"
    Explanation: 3 * 5 * 7 = 105. It can be shown that 357 is the smallest number with a product of digits equal to 105. So the answer would be "357".

    Example 2:

    >>> smallestNumber(n = 7)
    >>> "7"
    Explanation: Since 7 has only one digit, its product of digits would be 7. We will show that 7 is the smallest number with a product of digits equal to 7. Since the product of numbers 1 to 6 is 1 to 6 respectively, so "7" would be the answer.

    Example 3:

    >>> smallestNumber(n = 44)
    >>> "-1"
    Explanation: It can be shown that there is no number such that its product of digits is equal to 44. So the answer would be "-1".
    """


Prompt:
def numberOfPoints(nums: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.
    Return the number of integer points on the line that are covered with any part of a car.

    Example 1:

    >>> numberOfPoints(nums = [[3,6],[1,5],[4,7]])
    >>> 7
    Explanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.

    Example 2:

    >>> numberOfPoints(nums = [[1,3],[5,8]])
    >>> 7
    Explanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.
    """


Prompt:
def isReachableAtTime(sx: int, sy: int, fx: int, fy: int, t: int) -> bool:
    """
    You are given four integers sx, sy, fx, fy, and a non-negative integer t.
    In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.
    Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.
    A cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.

    Example 1:

    >>> isReachableAtTime(sx = 2, sy = 4, fx = 7, fy = 7, t = 6)
    >>> true
    Explanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.

    Example 2:

    >>> isReachableAtTime(sx = 3, sy = 1, fx = 7, fy = 3, t = 3)
    >>> false
    Explanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.
    """


Prompt:
def minimumMoves(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.
    In one move, you can move a single stone from its current cell to any other cell if the two cells share a side.
    Return the minimum number of moves required to place one stone in each cell.

    Example 1:

    >>> minimumMoves(grid = [[1,1,0],[1,1,1],[1,2,1]])
    >>> 3
    Explanation: One possible sequence of moves to place one stone in each cell is:
    1- Move one stone from cell (2,1) to cell (2,2).
    2- Move one stone from cell (2,2) to cell (1,2).
    3- Move one stone from cell (1,2) to cell (0,2).
    In total, it takes 3 moves to place one stone in each cell of the grid.
    It can be shown that 3 is the minimum number of moves required to place one stone in each cell.

    Example 2:

    >>> minimumMoves(grid = [[1,3,0],[1,0,0],[1,0,3]])
    >>> 4
    Explanation: One possible sequence of moves to place one stone in each cell is:
    1- Move one stone from cell (0,1) to cell (0,2).
    2- Move one stone from cell (0,1) to cell (1,1).
    3- Move one stone from cell (2,2) to cell (1,2).
    4- Move one stone from cell (2,2) to cell (2,1).
    In total, it takes 4 moves to place one stone in each cell of the grid.
    It can be shown that 4 is the minimum number of moves required to place one stone in each cell.
    """


Prompt:
def numberOfWays(s: str, t: str, k: int) -> int:
    """
    You are given two strings s and t of equal length n. You can perform the following operation on the string s:

    Remove a suffix of s of length l where 0 < l < n and append it at the start of s.
    	For example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab'.

    You are also given an integer k. Return the number of ways in which s can be transformed into t in exactly k operations.
    Since the answer can be large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfWays(s = "abcd", t = "cdab", k = 2)
    >>> 2
    Explanation:
    First way:
    In first operation, choose suffix from index = 3, so resulting s = "dabc".
    In second operation, choose suffix from index = 3, so resulting s = "cdab".

    Second way:
    In first operation, choose suffix from index = 1, so resulting s = "bcda".
    In second operation, choose suffix from index = 1, so resulting s = "cdab".

    Example 2:

    >>> numberOfWays(s = "ababab", t = "ababab", k = 1)
    >>> 2
    Explanation:
    First way:
    Choose suffix from index = 2, so resulting s = "ababab".

    Second way:
    Choose suffix from index = 4, so resulting s = "ababab".
    """


Prompt:
def sumRemoteness(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed matrix grid of order n * n. Each cell in this matrix has a value grid[i][j], which is either a positive integer or -1 representing a blocked cell.
    You can move from a non-blocked cell to any non-blocked cell that shares an edge.
    For any cell (i, j), we represent its remoteness as R[i][j] which is defined as the following:

    If the cell (i, j) is a non-blocked cell, R[i][j] is the sum of the values grid[x][y] such that there is no path from the non-blocked cell (x, y) to the cell (i, j).
    For blocked cells, R[i][j] == 0.

    Return the sum of R[i][j] over all cells.

    Example 1:

    >>> sumRemoteness(grid = [[-1,1,-1],[5,-1,4],[-1,3,-1]])
    >>> 39
    Explanation: In the picture above, there are four grids. The top-left grid contains the initial values in the grid. Blocked cells are colored black, and other cells get their values as it is in the input. In the top-right grid, you can see the value of R[i][j] for all cells. So the answer would be the sum of them. That is: 0 + 12 + 0 + 8 + 0 + 9 + 0 + 10 + 0 = 39.
    Let's jump on the bottom-left grid in the above picture and calculate R[0][1] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (0, 1). These cells are colored yellow in this grid. So R[0][1] = 5 + 4 + 3 = 12.
    Now let's jump on the bottom-right grid in the above picture and calculate R[1][2] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (1, 2). These cells are colored yellow in this grid. So R[1][2] = 1 + 5 + 3 = 9.

    Example 2:

    >>> sumRemoteness(grid = [[-1,3,4],[-1,-1,-1],[3,-1,-1]])
    >>> 13
    Explanation: In the picture above, there are four grids. The top-left grid contains the initial values in the grid. Blocked cells are colored black, and other cells get their values as it is in the input. In the top-right grid, you can see the value of R[i][j] for all cells. So the answer would be the sum of them. That is: 3 + 3 + 0 + 0 + 0 + 0 + 7 + 0 + 0 = 13.
    Let's jump on the bottom-left grid in the above picture and calculate R[0][2] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (0, 2). This cell is colored yellow in this grid. So R[0][2] = 3.
    Now let's jump on the bottom-right grid in the above picture and calculate R[2][0] (the target cell is colored green). We should sum up the value of cells that can't be reached by the cell (2, 0). These cells are colored yellow in this grid. So R[2][0] = 3 + 4 = 7.

    Example 3:

    >>> sumRemoteness(grid = [[1]])
    >>> 0
    Explanation: Since there are no other cells than (0, 0), R[0][0] is equal to 0. So the sum of R[i][j] over all cells would be 0.
    """


Prompt:
def minimumRightShifts(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.
    A right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.

    Example 1:

    >>> minimumRightShifts(nums = [3,4,5,1,2])
    >>> 2
    Explanation:
    After the first right shift, nums = [2,3,4,5,1].
    After the second right shift, nums = [1,2,3,4,5].
    Now nums is sorted; therefore the answer is 2.

    Example 2:

    >>> minimumRightShifts(nums = [1,3,5])
    >>> 0
    Explanation: nums is already sorted therefore, the answer is 0.
    Example 3:

    >>> minimumRightShifts(nums = [2,1,4])
    >>> -1
    Explanation: It's impossible to sort the array using right shifts.
    """


Prompt:
def minLengthAfterRemovals(nums: List[int]) -> int:
    """
    Given an integer array num sorted in non-decreasing order.
    You can perform the following operation any number of times:

    Choose two indices, i and j, where nums[i] < nums[j].
    Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.

    Return the minimum length of nums after applying the operation zero or more times.

    Example 1:

    >>> minLengthAfterRemovals(nums = [1,2,3,4])
    >>> 0
    Explanation:

    Example 2:

    >>> minLengthAfterRemovals(nums = [1,1,2,2,3,3])
    >>> 0
    Explanation:

    Example 3:

    >>> minLengthAfterRemovals(nums = [1000000000,1000000000])
    >>> 2
    Explanation:
    Since both numbers are equal, they cannot be removed.

    Example 4:

    >>> minLengthAfterRemovals(nums = [2,3,4,4,4])
    >>> 1
    Explanation:
    """


Prompt:
def countPairs(coordinates: List[List[int]], k: int) -> int:
    """
    You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane.
    We define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.
    Return the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.

    Example 1:

    >>> countPairs(coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5)
    >>> 2
    Explanation: We can choose the following pairs:
    - (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.
    - (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.

    Example 2:

    >>> countPairs(coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0)
    >>> 10
    Explanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.
    """


Prompt:
def minEdgeReversals(n: int, edges: List[List[int]]) -> List[int]:
    """
    There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.
    You are given an integer n and a 2D integer array edges, where edges[i] = [ui, vi] represents a directed edge going from node ui to node vi.
    An edge reversal changes the direction of an edge, i.e., a directed edge going from node ui to node vi becomes a directed edge going from node vi to node ui.
    For every node i in the range [0, n - 1], your task is to independently calculate the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.
    Return an integer array answer, where answer[i] is the  minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.

    Example 1:

    >>> minEdgeReversals(n = 4, edges = [[2,0],[2,1],[1,3]])
    >>> [1,1,0,2]
    Explanation: The image above shows the graph formed by the edges.
    For node 0: after reversing the edge [2,0], it is possible to reach any other node starting from node 0.
    So, answer[0] = 1.
    For node 1: after reversing the edge [2,1], it is possible to reach any other node starting from node 1.
    So, answer[1] = 1.
    For node 2: it is already possible to reach any other node starting from node 2.
    So, answer[2] = 0.
    For node 3: after reversing the edges [1,3] and [2,1], it is possible to reach any other node starting from node 3.
    So, answer[3] = 2.

    Example 2:

    >>> minEdgeReversals(n = 3, edges = [[1,2],[2,0]])
    >>> [2,0,1]
    Explanation: The image above shows the graph formed by the edges.
    For node 0: after reversing the edges [2,0] and [1,2], it is possible to reach any other node starting from node 0.
    So, answer[0] = 2.
    For node 1: it is already possible to reach any other node starting from node 1.
    So, answer[1] = 0.
    For node 2: after reversing the edge [1, 2], it is possible to reach any other node starting from node 2.
    So, answer[2] = 1.
    """


Prompt:
def sumIndicesWithKSetBits(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.
    Return an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.
    The set bits in an integer are the 1's present when it is written in binary.

    For example, the binary representation of 21 is 10101, which has 3 set bits.

    Example 1:

    >>> sumIndicesWithKSetBits(nums = [5,10,1,5,2], k = 1)
    >>> 13
    Explanation: The binary representation of the indices are:
    0 = 0002
    1 = 0012
    2 = 0102
    3 = 0112
    4 = 1002
    Indices 1, 2, and 4 have k = 1 set bits in their binary representation.
    Hence, the answer is nums[1] + nums[2] + nums[4] = 13.
    Example 2:

    >>> sumIndicesWithKSetBits(nums = [4,3,2,1], k = 2)
    >>> 1
    Explanation: The binary representation of the indices are:
    0 = 002
    1 = 012
    2 = 102
    3 = 112
    Only index 3 has k = 2 set bits in its binary representation.
    Hence, the answer is nums[3] = 1.
    """


Prompt:
def countWays(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.
    The ith student will become happy if one of these two conditions is met:

    The student is selected and the total number of selected students is strictly greater than nums[i].
    The student is not selected and the total number of selected students is strictly less than nums[i].

    Return the number of ways to select a group of students so that everyone remains happy.

    Example 1:

    >>> countWays(nums = [1,1])
    >>> 2
    Explanation:
    The two possible ways are:
    The class teacher selects no student.
    The class teacher selects both students to form the group.
    If the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.

    Example 2:

    >>> countWays(nums = [6,0,3,3,6,7,2,7])
    >>> 3
    Explanation:
    The three possible ways are:
    The class teacher selects the student with index = 1 to form the group.
    The class teacher selects the students with index = 1, 2, 3, 6 to form the group.
    The class teacher selects all the students to form the group.
    """


Prompt:
def maxNumberOfAlloys(n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:
    """
    You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.
    For the ith machine to create an alloy, it needs composition[i][j] units of metal of type j. Initially, you have stock[i] units of metal type i, and purchasing one unit of metal type i costs cost[i] coins.
    Given integers n, k, budget, a 1-indexed 2D array composition, and 1-indexed arrays stock and cost, your goal is to maximize the number of alloys the company can create while staying within the budget of budget coins.
    All alloys must be created with the same machine.
    Return the maximum number of alloys that the company can create.

    Example 1:

    >>> maxNumberOfAlloys(n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3])
    >>> 2
    Explanation: It is optimal to use the 1st machine to create alloys.
    To create 2 alloys we need to buy the:
    - 2 units of metal of the 1st type.
    - 2 units of metal of the 2nd type.
    - 2 units of metal of the 3rd type.
    In total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.
    Notice that we have 0 units of metal of each type and we have to buy all the required units of metal.
    It can be proven that we can create at most 2 alloys.

    Example 2:

    >>> maxNumberOfAlloys(n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3])
    >>> 5
    Explanation: It is optimal to use the 2nd machine to create alloys.
    To create 5 alloys we need to buy:
    - 5 units of metal of the 1st type.
    - 5 units of metal of the 2nd type.
    - 0 units of metal of the 3rd type.
    In total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.
    It can be proven that we can create at most 5 alloys.

    Example 3:

    >>> maxNumberOfAlloys(n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5])
    >>> 2
    Explanation: It is optimal to use the 3rd machine to create alloys.
    To create 2 alloys we need to buy the:
    - 1 unit of metal of the 1st type.
    - 1 unit of metal of the 2nd type.
    In total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.
    It can be proven that we can create at most 2 alloys.
    """


Prompt:
def maximumSum(nums: List[int]) -> int:
    """
    You are given a 1-indexed array nums. Your task is to select a complete subset from nums where every pair of selected indices multiplied is a perfect square,. i. e. if you select ai and aj, i * j must be a perfect square.
    Return the sum of the complete subset with the maximum sum.

    Example 1:

    >>> maximumSum(nums = [8,7,3,5,7,2,4,9])
    >>> 16
    Explanation:
    We select elements at indices 2 and 8 and 2 * 8 is a perfect square.

    Example 2:

    >>> maximumSum(nums = [8,10,3,8,1,13,7,9,4])
    >>> 20
    Explanation:
    We select elements at indices 1, 4, and 9. 1 * 4, 1 * 9, 4 * 9 are perfect squares.
    """


Prompt:
def maxSubarrayLength(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    Return the length of the longest semi-decreasing subarray of nums, and 0 if there are no such subarrays.

    A subarray is a contiguous non-empty sequence of elements within an array.
    A non-empty array is semi-decreasing if its first element is strictly greater than its last element.

    Example 1:

    >>> maxSubarrayLength(nums = [7,6,5,4,3,2,1,6,10,11])
    >>> 8
    Explanation: Take the subarray [7,6,5,4,3,2,1,6].
    The first element is 7 and the last one is 6 so the condition is met.
    Hence, the answer would be the length of the subarray or 8.
    It can be shown that there aren't any subarrays with the given condition with a length greater than 8.

    Example 2:

    >>> maxSubarrayLength(nums = [57,55,50,60,61,58,63,59,64,60,63])
    >>> 6
    Explanation: Take the subarray [61,58,63,59,64,60].
    The first element is 61 and the last one is 60 so the condition is met.
    Hence, the answer would be the length of the subarray or 6.
    It can be shown that there aren't any subarrays with the given condition with a length greater than 6.

    Example 3:

    >>> maxSubarrayLength(nums = [1,2,3,4])
    >>> 0
    Explanation: Since there are no semi-decreasing subarrays in the given array, the answer is 0.
    """


Prompt:
def maximumOddBinaryNumber(s: str) -> str:
    """
    You are given a binary string s that contains at least one '1'.
    You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.
    Return a string representing the maximum odd binary number that can be created from the given combination.
    Note that the resulting string can have leading zeros.

    Example 1:

    >>> maximumOddBinaryNumber(s = "010")
    >>> "001"
    Explanation: Because there is just one '1', it must be in the last position. So the answer is "001".

    Example 2:

    >>> maximumOddBinaryNumber(s = "0101")
    >>> "1001"
    Explanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is "100". So the answer is "1001".
    """


Prompt:
def maximumSumOfHeights(heights: List[int]) -> int:
    """
    You are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a mountain-shaped tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing.
    Return the maximum possible sum of heights of a mountain-shaped tower arrangement.

    Example 1:

    >>> maximumSumOfHeights(heights = [5,3,4,1,1])
    >>> 13
    Explanation:
    We remove some bricks to make heights = [5,3,3,1,1], the peak is at index 0.

    Example 2:

    >>> maximumSumOfHeights(heights = [6,5,3,9,2,7])
    >>> 22
    Explanation:
    We remove some bricks to make heights = [3,3,3,9,2,2], the peak is at index 3.

    Example 3:

    >>> maximumSumOfHeights(heights = [3,2,5,5,2,3])
    >>> 18
    Explanation:
    We remove some bricks to make heights = [2,2,5,5,2,2], the peak is at index 2 or 3.
    """


Prompt:
def maximumSumOfHeights(maxHeights: List[int]) -> int:
    """
    You are given a 0-indexed array maxHeights of n integers.
    You are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].
    A configuration of towers is beautiful if the following conditions hold:

    1 <= heights[i] <= maxHeights[i]
    heights is a mountain array.

    Array heights is a mountain if there exists an index i such that:

    For all 0 < j <= i, heights[j - 1] <= heights[j]
    For all i <= k < n - 1, heights[k + 1] <= heights[k]

    Return the maximum possible sum of heights of a beautiful configuration of towers.

    Example 1:

    >>> maximumSumOfHeights(maxHeights = [5,3,4,1,1])
    >>> 13
    Explanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
    - 1 <= heights[i] <= maxHeights[i]
    - heights is a mountain of peak i = 0.
    It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.
    Example 2:

    >>> maximumSumOfHeights(maxHeights = [6,5,3,9,2,7])
    >>> 22
    Explanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
    - 1 <= heights[i] <= maxHeights[i]
    - heights is a mountain of peak i = 3.
    It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.
    Example 3:

    >>> maximumSumOfHeights(maxHeights = [3,2,5,5,2,3])
    >>> 18
    Explanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
    - 1 <= heights[i] <= maxHeights[i]
    - heights is a mountain of peak i = 2.
    Note that, for this configuration, i = 3 can also be considered a peak.
    It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.
    """


Prompt:
def countPaths(n: int, edges: List[List[int]]) -> int:
    """
    There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.
    Return the number of valid paths in the tree.
    A path (a, b) is valid if there exists exactly one prime number among the node labels in the path from a to b.
    Note that:

    The path (a, b) is a sequence of distinct nodes starting with node a and ending with node b such that every two adjacent nodes in the sequence share an edge in the tree.
    Path (a, b) and path (b, a) are considered the same and counted only once.

    Example 1:

    >>> countPaths(n = 5, edges = [[1,2],[1,3],[2,4],[2,5]])
    >>> 4
    Explanation: The pairs with exactly one prime number on the path between them are:
    - (1, 2) since the path from 1 to 2 contains prime number 2.
    - (1, 3) since the path from 1 to 3 contains prime number 3.
    - (1, 4) since the path from 1 to 4 contains prime number 2.
    - (2, 4) since the path from 2 to 4 contains prime number 2.
    It can be shown that there are only 4 valid paths.

    Example 2:

    >>> countPaths(n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]])
    >>> 6
    Explanation: The pairs with exactly one prime number on the path between them are:
    - (1, 2) since the path from 1 to 2 contains prime number 2.
    - (1, 3) since the path from 1 to 3 contains prime number 3.
    - (1, 4) since the path from 1 to 4 contains prime number 2.
    - (1, 6) since the path from 1 to 6 contains prime number 3.
    - (2, 4) since the path from 2 to 4 contains prime number 2.
    - (3, 6) since the path from 3 to 6 contains prime number 3.
    It can be shown that there are only 6 valid paths.
    """


Prompt:
def canAliceWin(a: List[str], b: List[str]) -> bool:
    """
    Alice and Bob each have a lexicographically sorted array of strings named a and b respectively.
    They are playing a wording game with the following rules:

    On each turn, the current player should play a word from their list such that the new word is closely greater than the last played word; then it's the other player's turn.
    If a player can't play a word on their turn, they lose.

    Alice starts the game by playing her lexicographically smallest word.
    Given a and b, return true if Alice can win knowing that both players play their best, and false otherwise.
    A word w is closely greater than a word z if the following conditions are met:

    w is lexicographically greater than z.
    If w1 is the first letter of w and z1 is the first letter of z, w1 should either be equal to z1 or be the letter after z1 in the alphabet.
    For example, the word "care" is closely greater than "book" and "car", but is not closely greater than "ant" or "cook".

    A string s is lexicographically greater than a string t if in the first position where s and t differ, string s has a letter that appears later in the alphabet than the corresponding letter in t. If the first min(s.length, t.length) characters do not differ, then the longer string is the lexicographically greater one.

    Example 1:

    >>> canAliceWin(a = ["avokado","dabar"], b = ["brazil"])
    >>> false
    Explanation: Alice must start the game by playing the word "avokado" since it's her smallest word, then Bob plays his only word, "brazil", which he can play because its first letter, 'b', is the letter after Alice's word's first letter, 'a'.
    Alice can't play a word since the first letter of the only word left is not equal to 'b' or the letter after 'b', 'c'.
    So, Alice loses, and the game ends.
    Example 2:

    >>> canAliceWin(a = ["ananas","atlas","banana"], b = ["albatros","cikla","nogomet"])
    >>> true
    Explanation: Alice must start the game by playing the word "ananas".
    Bob can't play a word since the only word he has that starts with the letter 'a' or 'b' is "albatros", which is smaller than Alice's word.
    So Alice wins, and the game ends.
    Example 3:

    >>> canAliceWin(a = ["hrvatska","zastava"], b = ["bijeli","galeb"])
    >>> true
    Explanation: Alice must start the game by playing the word "hrvatska".
    Bob can't play a word since the first letter of both of his words are smaller than the first letter of Alice's word, 'h'.
    So Alice wins, and the game ends.
    """


Prompt:
def minOperations(nums: List[int], k: int) -> int:
    """
    You are given an array nums of positive integers and an integer k.
    In one operation, you can remove the last element of the array and add it to your collection.
    Return the minimum number of operations needed to collect elements 1, 2, ..., k.

    Example 1:

    >>> minOperations(nums = [3,1,5,4,2], k = 2)
    >>> 4
    Explanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.

    Example 2:

    >>> minOperations(nums = [3,1,5,4,2], k = 5)
    >>> 5
    Explanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.

    Example 3:

    >>> minOperations(nums = [3,2,5,3,1], k = 3)
    >>> 4
    Explanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.
    """


Prompt:
def minOperations(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums consisting of positive integers.
    There are two types of operations that you can apply on the array any number of times:

    Choose two elements with equal values and delete them from the array.
    Choose three elements with equal values and delete them from the array.

    Return the minimum number of operations required to make the array empty, or -1 if it is not possible.

    Example 1:

    >>> minOperations(nums = [2,3,3,2,2,4,2,3,4])
    >>> 4
    Explanation: We can apply the following operations to make the array empty:
    - Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
    - Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].
    - Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].
    - Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].
    It can be shown that we cannot make the array empty in less than 4 operations.

    Example 2:

    >>> minOperations(nums = [2,1,2,2,3,3])
    >>> -1
    Explanation: It is impossible to empty the array.
    """


Prompt:
def maxSubarrays(nums: List[int]) -> int:
    """
    You are given an array nums consisting of non-negative integers.
    We define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.
    Consider splitting the array into one or more subarrays such that the following conditions are satisfied:

    Each element of the array belongs to exactly one subarray.
    The sum of scores of the subarrays is the minimum possible.

    Return the maximum number of subarrays in a split that satisfies the conditions above.
    A subarray is a contiguous part of an array.

    Example 1:

    >>> maxSubarrays(nums = [1,0,2,0,1,2])
    >>> 3
    Explanation: We can split the array into the following subarrays:
    - [1,0]. The score of this subarray is 1 AND 0 = 0.
    - [2,0]. The score of this subarray is 2 AND 0 = 0.
    - [1,2]. The score of this subarray is 1 AND 2 = 0.
    The sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.
    It can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.

    Example 2:

    >>> maxSubarrays(nums = [5,7,1,3])
    >>> 1
    Explanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.
    It can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.
    """


Prompt:
def maxKDivisibleComponents(n: int, edges: List[List[int]], values: List[int], k: int) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.
    A valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.
    Return the maximum number of components in any valid split.

    Example 1:

    >>> maxKDivisibleComponents(n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6)
    >>> 2
    Explanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:
    - The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.
    - The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.
    It can be shown that no other valid split has more than 2 connected components.
    Example 2:

    >>> maxKDivisibleComponents(n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3)
    >>> 3
    Explanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:
    - The value of the component containing node 0 is values[0] = 3.
    - The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.
    - The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.
    It can be shown that no other valid split has more than 3 connected components.
    """


Prompt:
def maximumTripletValue(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
    The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].

    Example 1:

    >>> maximumTripletValue(nums = [12,6,1,2,7])
    >>> 77
    Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
    It can be shown that there are no ordered triplets of indices with a value greater than 77.

    Example 2:

    >>> maximumTripletValue(nums = [1,10,3,4,19])
    >>> 133
    Explanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
    It can be shown that there are no ordered triplets of indices with a value greater than 133.

    Example 3:

    >>> maximumTripletValue(nums = [1,2,3])
    >>> 0
    Explanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.
    """


Prompt:
def maximumTripletValue(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
    The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].

    Example 1:

    >>> maximumTripletValue(nums = [12,6,1,2,7])
    >>> 77
    Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
    It can be shown that there are no ordered triplets of indices with a value greater than 77.

    Example 2:

    >>> maximumTripletValue(nums = [1,10,3,4,19])
    >>> 133
    Explanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
    It can be shown that there are no ordered triplets of indices with a value greater than 133.

    Example 3:

    >>> maximumTripletValue(nums = [1,2,3])
    >>> 0
    Explanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.
    """


Prompt:
def minSizeSubarray(nums: List[int], target: int) -> int:
    """
    You are given a 0-indexed array nums and an integer target.
    A 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.
    Return the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.

    Example 1:

    >>> minSizeSubarray(nums = [1,2,3], target = 5)
    >>> 2
    Explanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].
    The subarray in the range [1,2], has the sum equal to target = 5 and length = 2.
    It can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.

    Example 2:

    >>> minSizeSubarray(nums = [1,1,1,2,3], target = 4)
    >>> 2
    Explanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].
    The subarray in the range [4,5], has the sum equal to target = 4 and length = 2.
    It can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.

    Example 3:

    >>> minSizeSubarray(nums = [2,4,6,8], target = 3)
    >>> -1
    Explanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].
    It can be proven that there is no subarray with sum equal to target = 3.
    """


Prompt:
def countVisitedNodes(edges: List[int]) -> List[int]:
    """
    There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.
    You are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].
    Consider the following process on the graph:

    You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.

    Return an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.

    Example 1:

    >>> countVisitedNodes(edges = [1,2,0,0])
    >>> [3,3,3,4]
    Explanation: We perform the process starting from each node in the following way:
    - Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.
    - Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.
    - Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.
    - Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.

    Example 2:

    >>> countVisitedNodes(edges = [1,2,3,4,0])
    >>> [5,5,5,5,5]
    Explanation: Starting from any node we can visit every node in the graph in the process.
    """


Prompt:
def minArrayLength(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, you can perform the following operation on the array any number of times:

    Select two adjacent elements of the array like x and y, such that x * y <= k, and replace both of them with a single element with value x * y (e.g. in one operation the array [1, 2, 2, 3] with k = 5 can become [1, 4, 3] or [2, 2, 3], but can't become [1, 2, 6]).

    Return the minimum possible length of nums after any number of operations.

    Example 1:

    >>> minArrayLength(nums = [2,3,3,7,3,5], k = 20)
    >>> 3
    Explanation: We perform these operations:
    1. [2,3,3,7,3,5] -> [6,3,7,3,5]
    2. [6,3,7,3,5] -> [18,7,3,5]
    3. [18,7,3,5] -> [18,7,15]
    It can be shown that 3 is the minimum length possible to achieve with the given operation.

    Example 2:

    >>> minArrayLength(nums = [3,3,3,3], k = 6)
    >>> 4
    Explanation: We can't perform any operations since the product of every two adjacent elements is greater than 6.
    Hence, the answer is 4.
    """


Prompt:
def differenceOfSums(n: int, m: int) -> int:
    """
    You are given positive integers n and m.
    Define two integers as follows:

    num1: The sum of all integers in the range [1, n] (both inclusive) that are not divisible by m.
    num2: The sum of all integers in the range [1, n] (both inclusive) that are divisible by m.

    Return the integer num1 - num2.

    Example 1:

    >>> differenceOfSums(n = 10, m = 3)
    >>> 19
    Explanation: In the given example:
    - Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.
    - Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.
    We return 37 - 18 = 19 as the answer.

    Example 2:

    >>> differenceOfSums(n = 5, m = 6)
    >>> 15
    Explanation: In the given example:
    - Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.
    - Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.
    We return 15 - 0 = 15 as the answer.

    Example 3:

    >>> differenceOfSums(n = 5, m = 1)
    >>> -15
    Explanation: In the given example:
    - Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.
    - Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.
    We return 0 - 15 = -15 as the answer.
    """


Prompt:
def minProcessingTime(processorTime: List[int], tasks: List[int]) -> int:
    """
    You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.
    You are given an array processorTime representing the time each processor becomes available and an array tasks representing how long each task takes to complete. Return the minimum time needed to complete all tasks.

    Example 1:

    >>> minProcessingTime(processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5])
    >>> 16
    Explanation:
    Assign the tasks at indices 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indices 0, 1, 2, 3 to the second processor which becomes available at time = 10.
    The time taken by the first processor to finish the execution of all tasks is max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.
    The time taken by the second processor to finish the execution of all tasks is max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.

    Example 2:

    >>> minProcessingTime(processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3])
    >>> 23
    Explanation:
    Assign the tasks at indices 1, 4, 5, 6 to the first processor and the others to the second processor.
    The time taken by the first processor to finish the execution of all tasks is max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.
    The time taken by the second processor to finish the execution of all tasks is max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.
    """


Prompt:
def minOperations(s1: str, s2: str, x: int) -> int:
    """
    You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.
    You can perform any of the following operations on the string s1 any number of times:

    Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.
    Choose an index i such that i < n - 1 and flip both s1[i] and s1[i + 1]. The cost of this operation is 1.

    Return the minimum cost needed to make the strings s1 and s2 equal, or return -1 if it is impossible.
    Note that flipping a character means changing it from 0 to 1 or vice-versa.

    Example 1:

    >>> minOperations(s1 = "1100011000", s2 = "0101001010", x = 2)
    >>> 4
    Explanation: We can do the following operations:
    - Choose i = 3 and apply the second operation. The resulting string is s1 = "1101111000".
    - Choose i = 4 and apply the second operation. The resulting string is s1 = "1101001000".
    - Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = "0101001010" = s2.
    The total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible.

    Example 2:

    >>> minOperations(s1 = "10110", s2 = "00011", x = 4)
    >>> -1
    Explanation: It is not possible to make the two strings equal.
    """


Prompt:
def maxSum(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and a positive integer k.
    You can do the following operation on the array any number of times:

    Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwise OR operation, and AND denotes the bitwise AND operation.

    You have to choose k elements from the final array and calculate the sum of their squares.
    Return the maximum sum of squares you can achieve.
    Since the answer can be very large, return it modulo 109 + 7.

    Example 1:

    >>> maxSum(nums = [2,6,5,8], k = 2)
    >>> 261
    Explanation: We can do the following operations on the array:
    - Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10].
    - Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15].
    We can choose the elements 15 and 6 from the final array. The sum of squares is 152 + 62 = 261.
    It can be shown that this is the maximum value we can get.

    Example 2:

    >>> maxSum(nums = [4,5,4,7], k = 3)
    >>> 90
    Explanation: We do not need to apply any operations.
    We can choose the elements 7, 5, and 4 with a sum of squares: 72 + 52 + 42 = 90.
    It can be shown that this is the maximum value we can get.
    """


Prompt:
def maxScore(prices: List[int]) -> int:
    """
    Given a 1-indexed integer array prices, where prices[i] is the price of a particular stock on the ith day, your task is to select some of the elements of prices such that your selection is linear.
    A selection indexes, where indexes is a 1-indexed integer array of length k which is a subsequence of the array [1, 2, ..., n], is linear if:

    For every 1 < j <= k, prices[indexes[j]] - prices[indexes[j - 1]] == indexes[j] - indexes[j - 1].

    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
    The score of a selection indexes, is equal to the sum of the following array: [prices[indexes[1]], prices[indexes[2]], ..., prices[indexes[k]].
    Return the maximum score that a linear selection can have.

    Example 1:

    >>> maxScore(prices = [1,5,3,7,8])
    >>> 20
    Explanation: We can select the indexes [2,4,5]. We show that our selection is linear:
    For j = 2, we have:
    indexes[2] - indexes[1] = 4 - 2 = 2.
    prices[4] - prices[2] = 7 - 5 = 2.
    For j = 3, we have:
    indexes[3] - indexes[2] = 5 - 4 = 1.
    prices[5] - prices[4] = 8 - 7 = 1.
    The sum of the elements is: prices[2] + prices[4] + prices[5] = 20.
    It can be shown that the maximum sum a linear selection can have is 20.

    Example 2:

    >>> maxScore(prices = [5,6,7,8,9])
    >>> 35
    Explanation: We can select all of the indexes [1,2,3,4,5]. Since each element has a difference of exactly 1 from its previous element, our selection is linear.
    The sum of all the elements is 35 which is the maximum possible some out of every selection.
    """


Prompt:
def lastVisitedIntegers(nums: List[int]) -> List[int]:
    """
    Given an integer array nums where nums[i] is either a positive integer or -1. We need to find for each -1 the respective positive integer, which we call the last visited integer.
    To achieve this goal, let's define two empty arrays: seen and ans.
    Start iterating from the beginning of the array nums.

    If a positive integer is encountered, prepend it to the front of seen.
    If -1 is encountered, let k be the number of consecutive -1s seen so far (including the current -1),

    If k is less than or equal to the length of seen, append the k-th element of seen to ans.
    If k is strictly greater than the length of seen, append -1 to ans.

    Return the array ans.

    Example 1:

    >>> lastVisitedIntegers(nums = [1,2,-1,-1,-1])
    >>> [2,1,-1]
    Explanation:
    Start with seen = [] and ans = [].

    Process nums[0]: The first element in nums is 1. We prepend it to the front of seen. Now, seen == [1].
    Process nums[1]: The next element is 2. We prepend it to the front of seen. Now, seen == [2, 1].
    Process nums[2]: The next element is -1. This is the first occurrence of -1, so k == 1. We look for the first element in seen. We append 2 to ans. Now, ans == [2].
    Process nums[3]: Another -1. This is the second consecutive -1, so k == 2. The second element in seen is 1, so we append 1 to ans. Now, ans == [2, 1].
    Process nums[4]: Another -1, the third in a row, making k = 3. However, seen only has two elements ([2, 1]). Since k is greater than the number of elements in seen, we append -1 to ans. Finally, ans == [2, 1, -1].

    Example 2:

    >>> lastVisitedIntegers(nums = [1,-1,2,-1,-1])
    >>> [1,2,1]
    Explanation:
    Start with seen = [] and ans = [].

    Process nums[0]: The first element in nums is 1. We prepend it to the front of seen. Now, seen == [1].
    Process nums[1]: The next element is -1. This is the first occurrence of -1, so k == 1. We look for the first element in seen, which is 1. Append 1 to ans. Now, ans == [1].
    Process nums[2]: The next element is 2. Prepend this to the front of seen. Now, seen == [2, 1].
    Process nums[3]: The next element is -1. This -1 is not consecutive to the first -1 since 2 was in between. Thus, k resets to 1. The first element in seen is 2, so append 2 to ans. Now, ans == [1, 2].
    Process nums[4]: Another -1. This is consecutive to the previous -1, so k == 2. The second element in seen is 1, append 1 to ans. Finally, ans == [1, 2, 1].
    """


Prompt:
def getLongestSubsequence(words: List[str], groups: List[int]) -> List[str]:
    """
    You are given a string array words and a binary array groups both of length n, where words[i] is associated with groups[i].
    Your task is to select the longest alternating subsequence from words. A subsequence of words is alternating if for any two consecutive strings in the sequence, their corresponding elements in the binary array groups differ. Essentially, you are to choose strings such that adjacent elements have non-matching corresponding bits in the groups array.
    Formally, you need to find the longest subsequence of an array of indices [0, 1, ..., n - 1] denoted as [i0, i1, ..., ik-1], such that groups[ij] != groups[ij+1] for each 0 <= j < k - 1 and then find the words corresponding to these indices.
    Return the selected subsequence. If there are multiple answers, return any of them.
    Note: The elements in words are distinct.

    Example 1:

    >>> getLongestSubsequence(words = ["e","a","b"], groups = [0,0,1])
    >>> ["e","b"]
    Explanation: A subsequence that can be selected is ["e","b"] because groups[0] != groups[2]. Another subsequence that can be selected is ["a","b"] because groups[1] != groups[2]. It can be demonstrated that the length of the longest subsequence of indices that satisfies the condition is 2.

    Example 2:

    >>> getLongestSubsequence(words = ["a","b","c","d"], groups = [1,0,1,1])
    >>> ["a","b","c"]
    Explanation: A subsequence that can be selected is ["a","b","c"] because groups[0] != groups[1] and groups[1] != groups[2]. Another subsequence that can be selected is ["a","b","d"] because groups[0] != groups[1] and groups[1] != groups[3]. It can be shown that the length of the longest subsequence of indices that satisfies the condition is 3.
    """


Prompt:
def getWordsInLongestSubsequence(words: List[str], groups: List[int]) -> List[str]:
    """
    You are given a string array words, and an array groups, both arrays having length n.
    The hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different.
    You need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i0, i1, ..., ik-1] having length k, the following holds:

    For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[ij] != groups[ij+1], for each j where 0 < j + 1 < k.
    words[ij] and words[ij+1] are equal in length, and the hamming distance between them is 1, where 0 < j + 1 < k, for all indices in the subsequence.

    Return a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.
    Note: strings in words may be unequal in length.

    Example 1:

    >>> getWordsInLongestSubsequence(words = ["bab","dab","cab"], groups = [1,2,2])
    >>> ["bab","cab"]
    Explanation: A subsequence that can be selected is [0,2].

    groups[0] != groups[2]
    words[0].length == words[2].length, and the hamming distance between them is 1.

    So, a valid answer is [words[0],words[2]] = ["bab","cab"].
    Another subsequence that can be selected is [0,1].

    groups[0] != groups[1]
    words[0].length == words[1].length, and the hamming distance between them is 1.

    So, another valid answer is [words[0],words[1]] = ["bab","dab"].
    It can be shown that the length of the longest subsequence of indices that satisfies the conditions is 2.

    Example 2:

    >>> getWordsInLongestSubsequence(words = ["a","b","c","d"], groups = [1,2,3,4])
    >>> ["a","b","c","d"]
    Explanation: We can select the subsequence [0,1,2,3].
    It satisfies both conditions.
    Hence, the answer is [words[0],words[1],words[2],words[3]] = ["a","b","c","d"].
    It has the longest length among all subsequences of indices that satisfy the conditions.
    Hence, it is the only answer.
    """


Prompt:
def countSubMultisets(nums: List[int], l: int, r: int) -> int:
    """
    You are given a 0-indexed array nums of non-negative integers, and two integers l and r.
    Return the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].
    Since the answer may be large, return it modulo 109 + 7.
    A sub-multiset is an unordered collection of elements of the array in which a given value x can occur 0, 1, ..., occ[x] times, where occ[x] is the number of occurrences of x in the array.
    Note that:

    Two sub-multisets are the same if sorting both sub-multisets results in identical multisets.
    The sum of an empty multiset is 0.

    Example 1:

    >>> countSubMultisets(nums = [1,2,2,3], l = 6, r = 6)
    >>> 1
    Explanation: The only subset of nums that has a sum of 6 is {1, 2, 3}.

    Example 2:

    >>> countSubMultisets(nums = [2,1,4,2,7], l = 1, r = 5)
    >>> 7
    Explanation: The subsets of nums that have a sum within the range [1, 5] are {1}, {2}, {4}, {2, 2}, {1, 2}, {1, 4}, and {1, 2, 2}.

    Example 3:

    >>> countSubMultisets(nums = [1,2,1,3,5,2], l = 3, r = 5)
    >>> 9
    Explanation: The subsets of nums that have a sum within the range [3, 5] are {3}, {5}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {1, 1, 2}, {1, 1, 3}, and {1, 2, 2}.
    """


Prompt:
def findIndices(nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.
    Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:

    abs(i - j) >= indexDifference, and
    abs(nums[i] - nums[j]) >= valueDifference

    Return an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.
    Note: i and j may be equal.

    Example 1:

    >>> findIndices(nums = [5,1,4,1], indexDifference = 2, valueDifference = 4)
    >>> [0,3]
    Explanation: In this example, i = 0 and j = 3 can be selected.
    abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.
    Hence, a valid answer is [0,3].
    [3,0] is also a valid answer.

    Example 2:

    >>> findIndices(nums = [2,1], indexDifference = 0, valueDifference = 0)
    >>> [0,0]
    Explanation: In this example, i = 0 and j = 0 can be selected.
    abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.
    Hence, a valid answer is [0,0].
    Other valid answers are [0,1], [1,0], and [1,1].

    Example 3:

    >>> findIndices(nums = [1,2,3], indexDifference = 2, valueDifference = 4)
    >>> [-1,-1]
    Explanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.
    Hence, [-1,-1] is returned.
    """


Prompt:
def shortestBeautifulSubstring(s: str, k: int) -> str:
    """
    You are given a binary string s and a positive integer k.
    A substring of s is beautiful if the number of 1's in it is exactly k.
    Let len be the length of the shortest beautiful substring.
    Return the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful substring, return an empty string.
    A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.

    For example, "abcd" is lexicographically larger than "abcc" because the first position they differ is at the fourth character, and d is greater than c.

    Example 1:

    >>> shortestBeautifulSubstring(s = "100011001", k = 3)
    >>> "11001"
    Explanation: There are 7 beautiful substrings in this example:
    1. The substring "100011001".
    2. The substring "100011001".
    3. The substring "100011001".
    4. The substring "100011001".
    5. The substring "100011001".
    6. The substring "100011001".
    7. The substring "100011001".
    The length of the shortest beautiful substring is 5.
    The lexicographically smallest beautiful substring with length 5 is the substring "11001".

    Example 2:

    >>> shortestBeautifulSubstring(s = "1011", k = 2)
    >>> "11"
    Explanation: There are 3 beautiful substrings in this example:
    1. The substring "1011".
    2. The substring "1011".
    3. The substring "1011".
    The length of the shortest beautiful substring is 2.
    The lexicographically smallest beautiful substring with length 2 is the substring "11".

    Example 3:

    >>> shortestBeautifulSubstring(s = "000", k = 1)
    >>> ""
    Explanation: There are no beautiful substrings in this example.
    """


Prompt:
def findIndices(nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:
    """
    You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.
    Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:

    abs(i - j) >= indexDifference, and
    abs(nums[i] - nums[j]) >= valueDifference

    Return an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.
    Note: i and j may be equal.

    Example 1:

    >>> findIndices(nums = [5,1,4,1], indexDifference = 2, valueDifference = 4)
    >>> [0,3]
    Explanation: In this example, i = 0 and j = 3 can be selected.
    abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.
    Hence, a valid answer is [0,3].
    [3,0] is also a valid answer.

    Example 2:

    >>> findIndices(nums = [2,1], indexDifference = 0, valueDifference = 0)
    >>> [0,0]
    Explanation: In this example, i = 0 and j = 0 can be selected.
    abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.
    Hence, a valid answer is [0,0].
    Other valid answers are [0,1], [1,0], and [1,1].

    Example 3:

    >>> findIndices(nums = [1,2,3], indexDifference = 2, valueDifference = 4)
    >>> [-1,-1]
    Explanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.
    Hence, [-1,-1] is returned.
    """


Prompt:
def constructProductMatrix(grid: List[List[int]]) -> List[List[int]]:
    """
    Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:

    Each element p[i][j] is calculated as the product of all elements in grid except for the element grid[i][j]. This product is then taken modulo 12345.

    Return the product matrix of grid.

    Example 1:

    >>> constructProductMatrix(grid = [[1,2],[3,4]])
    >>> [[24,12],[8,6]]
    Explanation: p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24
    p[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12
    p[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8
    p[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6
    So the answer is [[24,12],[8,6]].
    Example 2:

    >>> constructProductMatrix(grid = [[12345],[2],[1]])
    >>> [[2],[0],[0]]
    Explanation: p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2.
    p[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0. So p[0][1] = 0.
    p[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0. So p[0][2] = 0.
    So the answer is [[2],[0],[0]].
    """


Prompt:
def maxProfit(prices: List[int], profits: List[int]) -> int:
    """
    Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].
    We have to pick three items with the following condition:

    prices[i] < prices[j] < prices[k] where i < j < k.

    If we pick items with indices i, j and k satisfying the above condition, the profit would be profits[i] + profits[j] + profits[k].
    Return the maximum profit we can get, and -1 if it's not possible to pick three items with the given condition.

    Example 1:

    >>> maxProfit(prices = [10,2,3,4], profits = [100,2,7,10])
    >>> 19
    Explanation: We can't pick the item with index i=0 since there are no indices j and k such that the condition holds.
    So the only triplet we can pick, are the items with indices 1, 2 and 3 and it's a valid pick since prices[1] < prices[2] < prices[3].
    The answer would be sum of their profits which is 2 + 7 + 10 = 19.
    Example 2:

    >>> maxProfit(prices = [1,2,3,4,5], profits = [1,5,3,4,6])
    >>> 15
    Explanation: We can select any triplet of items since for each triplet of indices i, j and k such that i < j < k, the condition holds.
    Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4.
    The answer would be sum of their profits which is 5 + 4 + 6 = 15.
    Example 3:

    >>> maxProfit(prices = [4,3,2,1], profits = [33,20,19,87])
    >>> -1
    Explanation: We can't select any triplet of indices such that the condition holds, so we return -1.
    """


Prompt:
def minimumSum(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums of integers.
    A triplet of indices (i, j, k) is a mountain if:

    i < j < k
    nums[i] < nums[j] and nums[k] < nums[j]

    Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.

    Example 1:

    >>> minimumSum(nums = [8,6,1,5,3])
    >>> 9
    Explanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:
    - 2 < 3 < 4
    - nums[2] < nums[3] and nums[4] < nums[3]
    And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.

    Example 2:

    >>> minimumSum(nums = [5,4,8,7,10,2])
    >>> 13
    Explanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:
    - 1 < 3 < 5
    - nums[1] < nums[3] and nums[5] < nums[3]
    And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.

    Example 3:

    >>> minimumSum(nums = [6,5,4,3,4,5])
    >>> -1
    Explanation: It can be shown that there are no mountain triplets in nums.
    """


Prompt:
def minimumSum(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums of integers.
    A triplet of indices (i, j, k) is a mountain if:

    i < j < k
    nums[i] < nums[j] and nums[k] < nums[j]

    Return the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.

    Example 1:

    >>> minimumSum(nums = [8,6,1,5,3])
    >>> 9
    Explanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:
    - 2 < 3 < 4
    - nums[2] < nums[3] and nums[4] < nums[3]
    And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.

    Example 2:

    >>> minimumSum(nums = [5,4,8,7,10,2])
    >>> 13
    Explanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:
    - 1 < 3 < 5
    - nums[1] < nums[3] and nums[5] < nums[3]
    And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.

    Example 3:

    >>> minimumSum(nums = [6,5,4,3,4,5])
    >>> -1
    Explanation: It can be shown that there are no mountain triplets in nums.
    """


Prompt:
def minimumChanges(s: str, k: int) -> int:
    """
    Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized.
    Return the minimum number of letter changes required.
    A semi-palindrome is a special type of string that can be divided into palindromes based on a repeating pattern. To check if a string is a semi-palindrome:

    Choose a positive divisor d of the string's length. d can range from 1 up to, but not including, the string's length. For a string of length 1, it does not have a valid divisor as per this definition, since the only divisor is its length, which is not allowed.
    For a given divisor d, divide the string into groups where each group contains characters from the string that follow a repeating pattern of length d. Specifically, the first group consists of characters at positions 1, 1 + d, 1 + 2d, and so on; the second group includes characters at positions 2, 2 + d, 2 + 2d, etc.
    The string is considered a semi-palindrome if each of these groups forms a palindrome.

    Consider the string "abcabc":

    The length of "abcabc" is 6. Valid divisors are 1, 2, and 3.
    For d = 1: The entire string "abcabc" forms one group. Not a palindrome.
    For d = 2:

    Group 1 (positions 1, 3, 5): "acb"
    Group 2 (positions 2, 4, 6): "bac"
    Neither group forms a palindrome.

    For d = 3:

    Group 1 (positions 1, 4): "aa"
    Group 2 (positions 2, 5): "bb"
    Group 3 (positions 3, 6): "cc"
    All groups form palindromes. Therefore, "abcabc" is a semi-palindrome.

    Example 1:

    >>> minimumChanges(s = "abcac", k = 2)
    >>> 1
    Explanation:  Divide s into "ab" and "cac". "cac" is already semi-palindrome. Change "ab" to "aa", it becomes semi-palindrome with d = 1.

    Example 2:

    >>> minimumChanges(s = "abcdef", k = 2)
    >>> 2
    Explanation:  Divide s into substrings "abc" and "def". Each needs one change to become semi-palindrome.

    Example 3:

    >>> minimumChanges(s = "aabbaa", k = 3)
    >>> 0
    Explanation:  Divide s into substrings "aa", "bb" and "aa". All are already semi-palindromes.
    """


Prompt:
def numberOfWays(n: int, m: int, k: int, source: List[int], dest: List[int]) -> int:
    """
    You are given two integers n and m which represent the size of a 1-indexed grid. You are also given an integer k, a 1-indexed integer array source and a 1-indexed integer array dest, where source and dest are in the form [x, y] representing a cell on the given grid.
    You can move through the grid in the following way:

    You can go from cell [x1, y1] to cell [x2, y2] if either x1 == x2 or y1 == y2.
    Note that you can't move to the cell you are already in e.g. x1 == x2 and y1 == y2.

    Return the number of ways you can reach dest from source by moving through the grid exactly k times.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfWays(n = 3, m = 2, k = 2, source = [1,1], dest = [2,2])
    >>> 2
    Explanation: There are 2 possible sequences of reaching [2,2] from [1,1]:
    - [1,1] -> [1,2] -> [2,2]
    - [1,1] -> [2,1] -> [2,2]

    Example 2:

    >>> numberOfWays(n = 3, m = 4, k = 3, source = [1,2], dest = [2,3])
    >>> 9
    Explanation: There are 9 possible sequences of reaching [2,3] from [1,2]:
    - [1,2] -> [1,1] -> [1,3] -> [2,3]
    - [1,2] -> [1,1] -> [2,1] -> [2,3]
    - [1,2] -> [1,3] -> [3,3] -> [2,3]
    - [1,2] -> [1,4] -> [1,3] -> [2,3]
    - [1,2] -> [1,4] -> [2,4] -> [2,3]
    - [1,2] -> [2,2] -> [2,1] -> [2,3]
    - [1,2] -> [2,2] -> [2,4] -> [2,3]
    - [1,2] -> [3,2] -> [2,2] -> [2,3]
    - [1,2] -> [3,2] -> [3,3] -> [2,3]
    """


Prompt:
def sumCounts(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    The distinct count of a subarray of nums is defined as:

    Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].

    Return the sum of the squares of distinct counts of all subarrays of nums.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> sumCounts(nums = [1,2,1])
    >>> 15
    Explanation: Six possible subarrays are:
    [1]: 1 distinct value
    [2]: 1 distinct value
    [1]: 1 distinct value
    [1,2]: 2 distinct values
    [2,1]: 2 distinct values
    [1,2,1]: 2 distinct values
    The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.

    Example 2:

    >>> sumCounts(nums = [1,1])
    >>> 3
    Explanation: Three possible subarrays are:
    [1]: 1 distinct value
    [1]: 1 distinct value
    [1,1]: 1 distinct value
    The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.
    """


Prompt:
def minChanges(s: str) -> int:
    """
    You are given a 0-indexed binary string s having an even length.
    A string is beautiful if it's possible to partition it into one or more substrings such that:

    Each substring has an even length.
    Each substring contains only 1's or only 0's.

    You can change any character in s to 0 or 1.
    Return the minimum number of changes required to make the string s beautiful.

    Example 1:

    >>> minChanges(s = "1001")
    >>> 2
    Explanation: We change s[1] to 1 and s[3] to 0 to get string "1100".
    It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
    It can be proven that 2 is the minimum number of changes needed to make the string beautiful.

    Example 2:

    >>> minChanges(s = "10")
    >>> 1
    Explanation: We change s[1] to 1 to get string "11".
    It can be seen that the string "11" is beautiful because we can partition it into "11".
    It can be proven that 1 is the minimum number of changes needed to make the string beautiful.

    Example 3:

    >>> minChanges(s = "0000")
    >>> 0
    Explanation: We don't need to make any changes as the string "0000" is beautiful already.
    """


Prompt:
def lengthOfLongestSubsequence(nums: List[int], target: int) -> int:
    """
    You are given a 0-indexed array of integers nums, and an integer target.
    Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> lengthOfLongestSubsequence(nums = [1,2,3,4,5], target = 9)
    >>> 3
    Explanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.

    Example 2:

    >>> lengthOfLongestSubsequence(nums = [4,1,3,2,1,5], target = 7)
    >>> 4
    Explanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.

    Example 3:

    >>> lengthOfLongestSubsequence(nums = [1,1,5,4,5], target = 3)
    >>> -1
    Explanation: It can be shown that nums has no subsequence that sums up to 3.
    """


Prompt:
def sumCounts(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    The distinct count of a subarray of nums is defined as:

    Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].

    Return the sum of the squares of distinct counts of all subarrays of nums.
    Since the answer may be very large, return it modulo 109 + 7.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> sumCounts(nums = [1,2,1])
    >>> 15
    Explanation: Six possible subarrays are:
    [1]: 1 distinct value
    [2]: 1 distinct value
    [1]: 1 distinct value
    [1,2]: 2 distinct values
    [2,1]: 2 distinct values
    [1,2,1]: 2 distinct values
    The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.

    Example 2:

    >>> sumCounts(nums = [2,2])
    >>> 3
    Explanation: Three possible subarrays are:
    [2]: 1 distinct value
    [2]: 1 distinct value
    [2,2]: 1 distinct value
    The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.
    """


Prompt:
def findKOr(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums, and an integer k. Let's introduce K-or operation by extending the standard bitwise OR. In K-or, a bit position in the result is set to 1 if at least k numbers in nums have a 1 in that position.
    Return the K-or of nums.

    Example 1:

    >>> findKOr(nums = [7,12,9,8,9,15], k = 4)
    >>> 9
    Explanation:
    Represent numbers in binary:

    Number
    Bit 3
    Bit 2
    Bit 1
    Bit 0

    7
    0
    1
    1
    1

    12
    1
    1
    0
    0

    9
    1
    0
    0
    1

    8
    1
    0
    0
    0

    9
    1
    0
    0
    1

    15
    1
    1
    1
    1

    Result = 9
    1
    0
    0
    1

    Bit 0 is set in 7, 9, 9, and 15. Bit 3 is set in 12, 9, 8, 9, and 15.
    Only bits 0 and 3 qualify. The result is (1001)2 = 9.

    Example 2:

    >>> findKOr(nums = [2,12,1,11,4,5], k = 6)
    >>> 0
    Explanation: No bit appears as 1 in all six array numbers, as required for K-or with k = 6. Thus, the result is 0.

    Example 3:

    >>> findKOr(nums = [10,8,5,9,11,6,8], k = 1)
    >>> 15
    Explanation:  Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.
    """


Prompt:
def minSum(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two arrays nums1 and nums2 consisting of positive integers.
    You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.
    Return the minimum equal sum you can obtain, or -1 if it is impossible.

    Example 1:

    >>> minSum(nums1 = [3,2,0,1,0], nums2 = [6,5,0])
    >>> 12
    Explanation: We can replace 0's in the following way:
    - Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].
    - Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].
    Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.

    Example 2:

    >>> minSum(nums1 = [2,0,2,0], nums2 = [1,4])
    >>> -1
    Explanation: It is impossible to make the sum of both arrays equal.
    """


Prompt:
def minIncrementOperations(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums having length n, and an integer k.
    You can perform the following increment operation any number of times (including zero):

    Choose an index i in the range [0, n - 1], and increase nums[i] by 1.

    An array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.
    Return an integer denoting the minimum number of increment operations needed to make nums beautiful.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> minIncrementOperations(nums = [2,3,0,0,2], k = 4)
    >>> 3
    Explanation: We can perform the following increment operations to make nums beautiful:
    Choose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].
    Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].
    Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].
    The subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].
    In all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.
    It can be shown that nums cannot be made beautiful with fewer than 3 increment operations.
    Hence, the answer is 3.

    Example 2:

    >>> minIncrementOperations(nums = [0,1,3,3], k = 5)
    >>> 2
    Explanation: We can perform the following increment operations to make nums beautiful:
    Choose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].
    Choose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].
    The subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].
    In all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.
    It can be shown that nums cannot be made beautiful with fewer than 2 increment operations.
    Hence, the answer is 2.

    Example 3:

    >>> minIncrementOperations(nums = [1,1,2], k = 1)
    >>> 0
    Explanation: The only subarray with a size of 3 or more in this example is [1,1,2].
    The maximum element, 2, is already greater than k = 1, so we don't need any increment operation.
    Hence, the answer is 0.
    """


Prompt:
def maximumPoints(edges: List[List[int]], coins: List[int], k: int) -> int:
    """
    There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.
    Starting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.
    Coins at nodei can be collected in one of the following ways:

    Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.
    Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the nodej present in the subtree of nodei, coins[j] will get reduced to floor(coins[j] / 2).

    Return the maximum points you can get after collecting the coins from all the tree nodes.

    Example 1:

    >>> maximumPoints(edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5)
    >>> 11
    Explanation:
    Collect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.
    Collect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.
    Collect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.
    Collect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.
    It can be shown that the maximum points we can get after collecting coins from all the nodes is 11.

    Example 2:

    >>> maximumPoints(edges = [[0,1],[0,2]], coins = [8,4,4], k = 0)
    >>> 16
    Explanation:
    Coins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.
    """


Prompt:
def maxProfit(prices: List[int], profits: List[int]) -> int:
    """
    Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].
    We have to pick three items with the following condition:

    prices[i] < prices[j] < prices[k] where i < j < k.

    If we pick items with indices i, j and k satisfying the above condition, the profit would be profits[i] + profits[j] + profits[k].
    Return the maximum profit we can get, and -1 if it's not possible to pick three items with the given condition.

    Example 1:

    >>> maxProfit(prices = [10,2,3,4], profits = [100,2,7,10])
    >>> 19
    Explanation: We can't pick the item with index i=0 since there are no indices j and k such that the condition holds.
    So the only triplet we can pick, are the items with indices 1, 2 and 3 and it's a valid pick since prices[1] < prices[2] < prices[3].
    The answer would be sum of their profits which is 2 + 7 + 10 = 19.
    Example 2:

    >>> maxProfit(prices = [1,2,3,4,5], profits = [1,5,3,4,6])
    >>> 15
    Explanation: We can select any triplet of items since for each triplet of indices i, j and k such that i < j < k, the condition holds.
    Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4.
    The answer would be sum of their profits which is 5 + 4 + 6 = 15.
    Example 3:

    >>> maxProfit(prices = [4,3,2,1], profits = [33,20,19,87])
    >>> -1
    Explanation: We can't select any triplet of indices such that the condition holds, so we return -1.
    """


Prompt:
def findChampion(grid: List[List[int]]) -> int:
    """
    There are n teams numbered from 0 to n - 1 in a tournament.
    Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.
    Team a will be the champion of the tournament if there is no team b that is stronger than team a.
    Return the team that will be the champion of the tournament.

    Example 1:

    >>> findChampion(grid = [[0,1],[0,0]])
    >>> 0
    Explanation: There are two teams in this tournament.
    grid[0][1] == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.

    Example 2:

    >>> findChampion(grid = [[0,0,1],[1,0,1],[0,0,0]])
    >>> 1
    Explanation: There are three teams in this tournament.
    grid[1][0] == 1 means that team 1 is stronger than team 0.
    grid[1][2] == 1 means that team 1 is stronger than team 2.
    So team 1 will be the champion.
    """


Prompt:
def findChampion(n: int, edges: List[List[int]]) -> int:
    """
    There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.
    You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.
    A directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.
    Team a will be the champion of the tournament if there is no team b that is stronger than team a.
    Return the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.
    Notes

    A cycle is a series of nodes a1, a2, ..., an, an+1 such that node a1 is the same node as node an+1, the nodes a1, a2, ..., an are distinct, and there is a directed edge from the node ai to node ai+1 for every i in the range [1, n].
    A DAG is a directed graph that does not have any cycle.

    Example 1:

    >>> findChampion(n = 3, edges = [[0,1],[1,2]])
    >>> 0
    Explanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.

    Example 2:

    >>> findChampion(n = 4, edges = [[0,2],[1,3],[1,2]])
    >>> -1
    Explanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.
    """


Prompt:
def maximumScoreAfterOperations(edges: List[List[int]], values: List[int]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node.
    You start with a score of 0. In one operation, you can:

    Pick any node i.
    Add values[i] to your score.
    Set values[i] to 0.

    A tree is healthy if the sum of values on the path from the root to any leaf node is different than zero.
    Return the maximum score you can obtain after performing these operations on the tree any number of times so that it remains healthy.

    Example 1:

    >>> maximumScoreAfterOperations(edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1])
    >>> 11
    Explanation: We can choose nodes 1, 2, 3, 4, and 5. The value of the root is non-zero. Hence, the sum of values on the path from the root to any leaf is different than zero. Therefore, the tree is healthy and the score is values[1] + values[2] + values[3] + values[4] + values[5] = 11.
    It can be shown that 11 is the maximum score obtainable after any number of operations on the tree.

    Example 2:

    >>> maximumScoreAfterOperations(edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5])
    >>> 40
    Explanation: We can choose nodes 0, 2, 3, and 4.
    - The sum of values on the path from 0 to 4 is equal to 10.
    - The sum of values on the path from 0 to 3 is equal to 10.
    - The sum of values on the path from 0 to 5 is equal to 3.
    - The sum of values on the path from 0 to 6 is equal to 5.
    Therefore, the tree is healthy and the score is values[0] + values[2] + values[3] + values[4] = 40.
    It can be shown that 40 is the maximum score obtainable after any number of operations on the tree.
    """


Prompt:
def maxBalancedSubsequenceSum(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    A subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:

    nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].

    A subsequence of nums having length 1 is considered balanced.
    Return an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.
    A subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.

    Example 1:

    >>> maxBalancedSubsequenceSum(nums = [3,3,5,6])
    >>> 14
    Explanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.
    nums[2] - nums[0] >= 2 - 0.
    nums[3] - nums[2] >= 3 - 2.
    Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
    The subsequence consisting of indices 1, 2, and 3 is also valid.
    It can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.
    Example 2:

    >>> maxBalancedSubsequenceSum(nums = [5,-1,-3,8])
    >>> 13
    Explanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.
    nums[3] - nums[0] >= 3 - 0.
    Hence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
    It can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.

    Example 3:

    >>> maxBalancedSubsequenceSum(nums = [-2,-1])
    >>> -1
    Explanation: In this example, the subsequence [-1] can be selected.
    It is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.
    """


Prompt:
def distributeCandies(n: int, limit: int) -> int:
    """
    You are given two positive integers n and limit.
    Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.

    Example 1:

    >>> distributeCandies(n = 5, limit = 2)
    >>> 3
    Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).

    Example 2:

    >>> distributeCandies(n = 3, limit = 3)
    >>> 10
    Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
    """


Prompt:
def distributeCandies(n: int, limit: int) -> int:
    """
    You are given two positive integers n and limit.
    Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.

    Example 1:

    >>> distributeCandies(n = 5, limit = 2)
    >>> 3
    Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).

    Example 2:

    >>> distributeCandies(n = 3, limit = 3)
    >>> 10
    Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
    """


Prompt:
def distributeCandies(n: int, limit: int) -> int:
    """
    You are given two positive integers n and limit.
    Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.

    Example 1:

    >>> distributeCandies(n = 5, limit = 2)
    >>> 3
    Explanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).

    Example 2:

    >>> distributeCandies(n = 3, limit = 3)
    >>> 10
    Explanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
    """


Prompt:
def stringCount(n: int) -> int:
    """
    You are given an integer n.
    A string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains "leet" as a substring.
    For example:

    The string "lteer" is good because we can rearrange it to form "leetr" .
    "letl" is not good because we cannot rearrange it to contain "leet" as a substring.

    Return the total number of good strings of length n.
    Since the answer may be large, return it modulo 109 + 7.
    A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> stringCount(n = 4)
    >>> 12
    Explanation: The 12 strings which can be rearranged to have "leet" as a substring are: "eelt", "eetl", "elet", "elte", "etel", "etle", "leet", "lete", "ltee", "teel", "tele", and "tlee".

    Example 2:

    >>> stringCount(n = 10)
    >>> 83943898
    Explanation: The number of strings with length 10 which can be rearranged to have "leet" as a substring is 526083947580. Hence the answer is 526083947580 % (109 + 7) = 83943898.
    """