Prompt:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List
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:
from typing import List, Set
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:
from typing import List
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.
    """


Prompt:
from typing import List
def maxSpending(values: List[List[int]]) -> int:
    """
    You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the jth item in the ith shop has a value of values[i][j]. Additionally, the items in the ith shop are sorted in non-increasing order of value. That is, values[i][j] >= values[i][j + 1] for all 0 <= j < n - 1.
    On each day, you would like to buy a single item from one of the shops. Specifically, On the dth day you can:

    Pick any shop i.
    Buy the rightmost available item j for the price of values[i][j] * d. That is, find the greatest index j such that item j was never bought before, and buy it for the price of values[i][j] * d.

    Note that all items are pairwise different. For example, if you have bought item 0 from shop 1, you can still buy item 0 from any other shop.
    Return the maximum amount of money that can be spent on buying all  m * n products.

    Example 1:

    >>> maxSpending(values = [[8,5,2],[6,4,1],[9,7,3]])
    >>> 285
    Explanation: On the first day, we buy product 2 from shop 1 for a price of values[1][2] * 1 = 1.
    On the second day, we buy product 2 from shop 0 for a price of values[0][2] * 2 = 4.
    On the third day, we buy product 2 from shop 2 for a price of values[2][2] * 3 = 9.
    On the fourth day, we buy product 1 from shop 1 for a price of values[1][1] * 4 = 16.
    On the fifth day, we buy product 1 from shop 0 for a price of values[0][1] * 5 = 25.
    On the sixth day, we buy product 0 from shop 1 for a price of values[1][0] * 6 = 36.
    On the seventh day, we buy product 1 from shop 2 for a price of values[2][1] * 7 = 49.
    On the eighth day, we buy product 0 from shop 0 for a price of values[0][0] * 8 = 64.
    On the ninth day, we buy product 0 from shop 2 for a price of values[2][0] * 9 = 81.
    Hence, our total spending is equal to 285.
    It can be shown that 285 is the maximum amount of money that can be spent buying all m * n products.

    Example 2:

    >>> maxSpending(values = [[10,8,6,4,2],[9,7,5,3,2]])
    >>> 386
    Explanation: On the first day, we buy product 4 from shop 0 for a price of values[0][4] * 1 = 2.
    On the second day, we buy product 4 from shop 1 for a price of values[1][4] * 2 = 4.
    On the third day, we buy product 3 from shop 1 for a price of values[1][3] * 3 = 9.
    On the fourth day, we buy product 3 from shop 0 for a price of values[0][3] * 4 = 16.
    On the fifth day, we buy product 2 from shop 1 for a price of values[1][2] * 5 = 25.
    On the sixth day, we buy product 2 from shop 0 for a price of values[0][2] * 6 = 36.
    On the seventh day, we buy product 1 from shop 1 for a price of values[1][1] * 7 = 49.
    On the eighth day, we buy product 1 from shop 0 for a price of values[0][1] * 8 = 64
    On the ninth day, we buy product 0 from shop 1 for a price of values[1][0] * 9 = 81.
    On the tenth day, we buy product 0 from shop 0 for a price of values[0][0] * 10 = 100.
    Hence, our total spending is equal to 386.
    It can be shown that 386 is the maximum amount of money that can be spent buying all m * n products.
    """


Prompt:
from typing import List
def maximumStrongPairXor(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:

    |x - y| <= min(x, y)

    You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.
    Return the maximum XOR value out of all possible strong pairs in the array nums.
    Note that you can pick the same integer twice to form a pair.

    Example 1:

    >>> maximumStrongPairXor(nums = [1,2,3,4,5])
    >>> 7
    Explanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).
    The maximum XOR possible from these pairs is 3 XOR 4 = 7.

    Example 2:

    >>> maximumStrongPairXor(nums = [10,100])
    >>> 0
    Explanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).
    The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.

    Example 3:

    >>> maximumStrongPairXor(nums = [5,6,25,30])
    >>> 7
    Explanation: There are 6 strong pairs in the array nums: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30).
    The maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.
    """


Prompt:
from typing import List
def findHighAccessEmployees(access_times: List[List[str]]) -> List[str]:
    """
    You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All entries in access_times are within the same day.
    The access time is represented as four digits using a 24-hour time format, for example, "0800" or "2250".
    An employee is said to be high-access if he has accessed the system three or more times within a one-hour period.
    Times with exactly one hour of difference are not considered part of the same one-hour period. For example, "0815" and "0915" are not part of the same one-hour period.
    Access times at the start and end of the day are not counted within the same one-hour period. For example, "0005" and "2350" are not part of the same one-hour period.
    Return a list that contains the names of high-access employees with any order you want.

    Example 1:

    >>> findHighAccessEmployees(access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]])
    >>> ["a"]
    Explanation: "a" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.
    But "b" does not have more than two access times at all.
    So the answer is ["a"].
    Example 2:

    >>> findHighAccessEmployees(access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]])
    >>> ["c","d"]
    Explanation: "c" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.
    "d" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.
    However, "e" has just one access time, so it can not be in the answer and the final answer is ["c","d"].
    Example 3:

    >>> findHighAccessEmployees(access_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]])
    >>> ["ab","cd"]
    Explanation: "ab" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.
    "cd" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.
    So the answer is ["ab","cd"].
    """


Prompt:
from typing import List
def minOperations(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays, nums1 and nums2, both having length n.
    You are allowed to perform a series of operations (possibly none).
    In an operation, you select an index i in the range [0, n - 1] and swap the values of nums1[i] and nums2[i].
    Your task is to find the minimum number of operations required to satisfy the following conditions:

    nums1[n - 1] is equal to the maximum value among all elements of nums1, i.e., nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]).
    nums2[n - 1] is equal to the maximum value among all elements of nums2, i.e., nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]).

    Return an integer denoting the minimum number of operations needed to meet both conditions, or -1 if it is impossible to satisfy both conditions.

    Example 1:

    >>> minOperations(nums1 = [1,2,7], nums2 = [4,5,3])
    >>> 1
    Explanation: In this example, an operation can be performed using index i = 2.
    When nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7].
    Both conditions are now satisfied.
    It can be shown that the minimum number of operations needed to be performed is 1.
    So, the answer is 1.

    Example 2:

    >>> minOperations(nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4])
    >>> 2
    Explanation: In this example, the following operations can be performed:
    First operation using index i = 4.
    When nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9].
    Another operation using index i = 3.
    When nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9].
    Both conditions are now satisfied.
    It can be shown that the minimum number of operations needed to be performed is 2.
    So, the answer is 2.

    Example 3:

    >>> minOperations(nums1 = [1,5,4], nums2 = [2,5,3])
    >>> -1
    Explanation: In this example, it is not possible to satisfy both conditions.
    So, the answer is -1.
    """


Prompt:
from typing import List
def maximumStrongPairXor(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:

    |x - y| <= min(x, y)

    You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.
    Return the maximum XOR value out of all possible strong pairs in the array nums.
    Note that you can pick the same integer twice to form a pair.

    Example 1:

    >>> maximumStrongPairXor(nums = [1,2,3,4,5])
    >>> 7
    Explanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).
    The maximum XOR possible from these pairs is 3 XOR 4 = 7.

    Example 2:

    >>> maximumStrongPairXor(nums = [10,100])
    >>> 0
    Explanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).
    The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.

    Example 3:

    >>> maximumStrongPairXor(nums = [500,520,2500,3000])
    >>> 1020
    Explanation: There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000).
    The maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.
    """


Prompt:
def findMinimumOperations(s1: str, s2: str, s3: str) -> int:
    """
    You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings and delete its rightmost character. Note that you cannot completely empty a string.
    Return the minimum number of operations required to make the strings equal. If it is impossible to make them equal, return -1.

    Example 1:

    >>> findMinimumOperations(s1 = "abc", s2 = "abb", s3 = "ab")
    >>> 2
    Explanation: Deleting the rightmost character from both s1 and s2 will result in three equal strings.

    Example 2:

    >>> findMinimumOperations(s1 = "dac", s2 = "bac", s3 = "cac")
    >>> -1
    Explanation: Since the first letters of s1 and s2 differ, they cannot be made equal.
    """


Prompt:
def minimumSteps(s: str) -> int:
    """
    There are n balls on a table, each ball has a color black or white.
    You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.
    In each step, you can choose two adjacent balls and swap them.
    Return the minimum number of steps to group all the black balls to the right and all the white balls to the left.

    Example 1:

    >>> minimumSteps(s = "101")
    >>> 1
    Explanation: We can group all the black balls to the right in the following way:
    - Swap s[0] and s[1], s = "011".
    Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.
    Example 2:

    >>> minimumSteps(s = "100")
    >>> 2
    Explanation: We can group all the black balls to the right in the following way:
    - Swap s[0] and s[1], s = "010".
    - Swap s[1] and s[2], s = "001".
    It can be proven that the minimum number of steps needed is 2.

    Example 3:

    >>> minimumSteps(s = "0111")
    >>> 0
    Explanation: All the black balls are already grouped to the right.
    """


Prompt:
def maximumXorProduct(a: int, b: int, n: int) -> int:
    """
    Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2n.
    Since the answer may be too large, return it modulo 109 + 7.
    Note that XOR is the bitwise XOR operation.

    Example 1:

    >>> maximumXorProduct(a = 12, b = 5, n = 4)
    >>> 98
    Explanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.
    It can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.

    Example 2:

    >>> maximumXorProduct(a = 6, b = 7 , n = 5)
    >>> 930
    Explanation: For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.
    It can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.
    Example 3:

    >>> maximumXorProduct(a = 1, b = 6, n = 3)
    >>> 12
    Explanation: For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.
    It can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.
    """


Prompt:
from typing import List
def leftmostBuildingQueries(heights: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.
    If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].
    You are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.
    Return an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.

    Example 1:

    >>> leftmostBuildingQueries(heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]])
    >>> [2,5,-1,5,2]
    Explanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2].
    In the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5].
    In the third query, Alice cannot meet Bob since Alice cannot move to any other building.
    In the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].
    In the fifth query, Alice and Bob are already in the same building.
    For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
    For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.

    Example 2:

    >>> leftmostBuildingQueries(heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]])
    >>> [7,6,-1,4,6]
    Explanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].
    In the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].
    In the third query, Alice cannot meet Bob since Bob cannot move to any other building.
    In the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].
    In the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].
    For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
    For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
    """


Prompt:
from typing import List
def maxGcdSum(nums: List[int], k: int) -> int:
    """
    You are given an array of integers nums and an integer k.
    The gcd-sum of an array a is calculated as follows:

    Let s be the sum of all the elements of a.
    Let g be the greatest common divisor of all the elements of a.
    The gcd-sum of a is equal to s * g.

    Return the maximum gcd-sum of a subarray of nums with at least k elements.

    Example 1:

    >>> maxGcdSum(nums = [2,1,4,4,4,2], k = 2)
    >>> 48
    Explanation: We take the subarray [4,4,4], the gcd-sum of this array is 4 * (4 + 4 + 4) = 48.
    It can be shown that we can not select any other subarray with a gcd-sum greater than 48.
    Example 2:

    >>> maxGcdSum(nums = [7,3,9,4], k = 1)
    >>> 81
    Explanation: We take the subarray [9], the gcd-sum of this array is 9 * 9 = 81.
    It can be shown that we can not select any other subarray with a gcd-sum greater than 81.
    """


Prompt:
from typing import List
def findWordsContaining(words: List[str], x: str) -> List[int]:
    """
    You are given a 0-indexed array of strings words and a character x.
    Return an array of indices representing the words that contain the character x.
    Note that the returned array may be in any order.

    Example 1:

    >>> findWordsContaining(words = ["leet","code"], x = "e")
    >>> [0,1]
    Explanation: "e" occurs in both words: "leet", and "code". Hence, we return indices 0 and 1.

    Example 2:

    >>> findWordsContaining(words = ["abc","bcd","aaaa","cbc"], x = "a")
    >>> [0,2]
    Explanation: "a" occurs in "abc", and "aaaa". Hence, we return indices 0 and 2.

    Example 3:

    >>> findWordsContaining(words = ["abc","bcd","aaaa","cbc"], x = "z")
    >>> []
    Explanation: "z" does not occur in any of the words. Hence, we return an empty array.
    """


Prompt:
from typing import List
def maximizeSquareHoleArea(n: int, m: int, hBars: List[int], vBars: List[int]) -> int:
    """
    You are given the two integers, n and m and two integer arrays, hBars and vBars. The grid has n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.
    You can remove some of the bars in hBars from horizontal bars and some of the bars in vBars from vertical bars. Note that other bars are fixed and cannot be removed.
    Return an integer denoting the maximum area of a square-shaped hole in the grid, after removing some bars (possibly none).

    Example 1:

    >>> maximizeSquareHoleArea(n = 2, m = 1, hBars = [2,3], vBars = [2])
    >>> 4
    Explanation:
    The left image shows the initial grid formed by the bars. The horizontal bars are [1,2,3,4], and the vertical bars are [1,2,3].
    One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.

    Example 2:

    >>> maximizeSquareHoleArea(n = 1, m = 1, hBars = [2], vBars = [2])
    >>> 4
    Explanation:
    To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.

    Example 3:

    >>> maximizeSquareHoleArea(n = 2, m = 3, hBars = [2,3], vBars = [2,4])
    >>> 4
    Explanation:
    One way to get the maximum square-shaped hole is by removing horizontal bar 3, and vertical bar 4.
    """


Prompt:
from typing import List
def minimumCoins(prices: List[int]) -> int:
    """
    You are given an 0-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the (i + 1)th fruit.
    The fruit market has the following reward for each fruit:

    If you purchase the (i + 1)th fruit at prices[i] coins, you can get any number of the next i fruits for free.

    Note that even if you can take fruit j for free, you can still purchase it for prices[j - 1] coins to receive its reward.
    Return the minimum number of coins needed to acquire all the fruits.

    Example 1:

    >>> minimumCoins(prices = [3,1,2])
    >>> 4
    Explanation:

    Purchase the 1st fruit with prices[0] = 3 coins, you are allowed to take the 2nd fruit for free.
    Purchase the 2nd fruit with prices[1] = 1 coin, you are allowed to take the 3rd fruit for free.
    Take the 3rd fruit for free.

    Note that even though you could take the 2nd fruit for free as a reward of buying 1st fruit, you purchase it to receive its reward, which is more optimal.

    Example 2:

    >>> minimumCoins(prices = [1,10,1,1])
    >>> 2
    Explanation:

    Purchase the 1st fruit with prices[0] = 1 coin, you are allowed to take the 2nd fruit for free.
    Take the 2nd fruit for free.
    Purchase the 3rd fruit for prices[2] = 1 coin, you are allowed to take the 4th fruit for free.
    Take the 4th fruit for free.

    Example 3:

    >>> minimumCoins(prices = [26,18,6,12,49,7,45,45])
    >>> 39
    Explanation:

    Purchase the 1st fruit with prices[0] = 26 coin, you are allowed to take the 2nd fruit for free.
    Take the 2nd fruit for free.
    Purchase the 3rd fruit for prices[2] = 6 coin, you are allowed to take the 4th, 5th and 6th (the next three) fruits for free.
    Take the 4th fruit for free.
    Take the 5th fruit for free.
    Purchase the 6th fruit with prices[5] = 7 coin, you are allowed to take the 8th and 9th fruit for free.
    Take the 7th fruit for free.
    Take the 8th fruit for free.

    Note that even though you could take the 6th fruit for free as a reward of buying 3rd fruit, you purchase it to receive its reward, which is more optimal.
    """


Prompt:
from typing import List
def findMaximumLength(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    You can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you select subarray [3,5] the array will convert to [1,8,6].
    Return the maximum length of a non-decreasing array that can be made after applying operations.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> findMaximumLength(nums = [5,2,2])
    >>> 1
    Explanation: This array with length 3 is not non-decreasing.
    We have two ways to make the array length two.
    First, choosing subarray [2,2] converts the array to [5,4].
    Second, choosing subarray [5,2] converts the array to [7,2].
    In these two ways the array is not non-decreasing.
    And if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing.
    So the answer is 1.

    Example 2:

    >>> findMaximumLength(nums = [1,2,3,4])
    >>> 4
    Explanation: The array is non-decreasing. So the answer is 4.

    Example 3:

    >>> findMaximumLength(nums = [4,3,2,6])
    >>> 3
    Explanation: Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.
    Because the given array is not non-decreasing, the maximum possible answer is 3.
    """


Prompt:
from typing import List
def areSimilar(mat: List[List[int]], k: int) -> bool:
    """
    You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed.
    The following proccess happens k times:

    Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left.

    Odd-indexed rows (1, 3, 5, ...) are cyclically shifted to the right.

    Return true if the final modified matrix after k steps is identical to the original matrix, and false otherwise.

    Example 1:

    >>> areSimilar(mat = [[1,2,3],[4,5,6],[7,8,9]], k = 4)
    >>> false
    Explanation:
    In each step left shift is applied to rows 0 and 2 (even indices), and right shift to row 1 (odd index).

    Example 2:

    >>> areSimilar(mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2)
    >>> true
    Explanation:

    Example 3:

    >>> areSimilar(mat = [[2,2],[2,2]], k = 3)
    >>> true
    Explanation:
    As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same.
    """


Prompt:
def beautifulSubstrings(s: str, k: int) -> int:
    """
    You are given a string s and a positive integer k.
    Let vowels and consonants be the number of vowels and consonants in a string.
    A string is beautiful if:

    vowels == consonants.
    (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.

    Return the number of non-empty beautiful substrings in the given string s.
    A substring is a contiguous sequence of characters in a string.
    Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
    Consonant letters in English are every letter except vowels.

    Example 1:

    >>> beautifulSubstrings(s = "baeyh", k = 2)
    >>> 2
    Explanation: There are 2 beautiful substrings in the given string.
    - Substring "baeyh", vowels = 2 (["a",e"]), consonants = 2 (["y","h"]).
    You can see that string "aeyh" is beautiful as vowels == consonants and vowels * consonants % k == 0.
    - Substring "baeyh", vowels = 2 (["a",e"]), consonants = 2 (["b","y"]).
    You can see that string "baey" is beautiful as vowels == consonants and vowels * consonants % k == 0.
    It can be shown that there are only 2 beautiful substrings in the given string.

    Example 2:

    >>> beautifulSubstrings(s = "abba", k = 1)
    >>> 3
    Explanation: There are 3 beautiful substrings in the given string.
    - Substring "abba", vowels = 1 (["a"]), consonants = 1 (["b"]).
    - Substring "abba", vowels = 1 (["a"]), consonants = 1 (["b"]).
    - Substring "abba", vowels = 2 (["a","a"]), consonants = 2 (["b","b"]).
    It can be shown that there are only 3 beautiful substrings in the given string.

    Example 3:

    >>> beautifulSubstrings(s = "bcdf", k = 1)
    >>> 0
    Explanation: There are no beautiful substrings in the given string.
    """


Prompt:
from typing import List
def lexicographicallySmallestArray(nums: List[int], limit: int) -> List[int]:
    """
    You are given a 0-indexed array of positive integers nums and a positive integer limit.
    In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.
    Return the lexicographically smallest array that can be obtained by performing the operation any number of times.
    An array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is less than the corresponding element in b. For example, the array [2,10,3] is lexicographically smaller than the array [10,2,3] because they differ at index 0 and 2 < 10.

    Example 1:

    >>> lexicographicallySmallestArray(nums = [1,5,3,9,8], limit = 2)
    >>> [1,3,5,8,9]
    Explanation: Apply the operation 2 times:
    - Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]
    - Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]
    We cannot obtain a lexicographically smaller array by applying any more operations.
    Note that it may be possible to get the same result by doing different operations.

    Example 2:

    >>> lexicographicallySmallestArray(nums = [1,7,6,18,2,1], limit = 3)
    >>> [1,6,7,18,1,2]
    Explanation: Apply the operation 3 times:
    - Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]
    - Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]
    - Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]
    We cannot obtain a lexicographically smaller array by applying any more operations.

    Example 3:

    >>> lexicographicallySmallestArray(nums = [1,7,28,19,10], limit = 3)
    >>> [1,7,28,19,10]
    Explanation: [1,7,28,19,10] is the lexicographically smallest array we can obtain because we cannot apply the operation on any two indices.
    """


Prompt:
def beautifulSubstrings(s: str, k: int) -> int:
    """
    You are given a string s and a positive integer k.
    Let vowels and consonants be the number of vowels and consonants in a string.
    A string is beautiful if:

    vowels == consonants.
    (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.

    Return the number of non-empty beautiful substrings in the given string s.
    A substring is a contiguous sequence of characters in a string.
    Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
    Consonant letters in English are every letter except vowels.

    Example 1:

    >>> beautifulSubstrings(s = "baeyh", k = 2)
    >>> 2
    Explanation: There are 2 beautiful substrings in the given string.
    - Substring "baeyh", vowels = 2 (["a",e"]), consonants = 2 (["y","h"]).
    You can see that string "aeyh" is beautiful as vowels == consonants and vowels * consonants % k == 0.
    - Substring "baeyh", vowels = 2 (["a",e"]), consonants = 2 (["b","y"]).
    You can see that string "baey" is beautiful as vowels == consonants and vowels * consonants % k == 0.
    It can be shown that there are only 2 beautiful substrings in the given string.

    Example 2:

    >>> beautifulSubstrings(s = "abba", k = 1)
    >>> 3
    Explanation: There are 3 beautiful substrings in the given string.
    - Substring "abba", vowels = 1 (["a"]), consonants = 1 (["b"]).
    - Substring "abba", vowels = 1 (["a"]), consonants = 1 (["b"]).
    - Substring "abba", vowels = 2 (["a","a"]), consonants = 2 (["b","b"]).
    It can be shown that there are only 3 beautiful substrings in the given string.

    Example 3:

    >>> beautifulSubstrings(s = "bcdf", k = 1)
    >>> 0
    Explanation: There are no beautiful substrings in the given string.
    """


Prompt:
def countDivisibleSubstrings(word: str) -> int:
    """
    Each character of the English alphabet has been mapped to a digit as shown below.

    A string is divisible if the sum of the mapped values of its characters is divisible by its length.
    Given a string s, return the number of divisible substrings of s.
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    Substring
    Mapped
    Sum
    Length
    Divisible?

    a
    1
    1
    1
    Yes

    s
    7
    7
    1
    Yes

    d
    2
    2
    1
    Yes

    f
    3
    3
    1
    Yes

    as
    1, 7
    8
    2
    Yes

    sd
    7, 2
    9
    2
    No

    df
    2, 3
    5
    2
    No

    asd
    1, 7, 2
    10
    3
    No

    sdf
    7, 2, 3
    12
    3
    Yes

    asdf
    1, 7, 2, 3
    13
    4
    No

    >>> countDivisibleSubstrings(word = "asdf")
    >>> 6
    Explanation: The table above contains the details about every substring of word, and we can see that 6 of them are divisible.

    Example 2:

    >>> countDivisibleSubstrings(word = "bdh")
    >>> 4
    Explanation: The 4 divisible substrings are: "b", "d", "h", "bdh".
    It can be shown that there are no other substrings of word that are divisible.

    Example 3:

    >>> countDivisibleSubstrings(word = "abcd")
    >>> 6
    Explanation: The 6 divisible substrings are: "a", "b", "c", "d", "ab", "cd".
    It can be shown that there are no other substrings of word that are divisible.
    """


Prompt:
from typing import List
def findPeaks(mountain: List[int]) -> List[int]:
    """
    You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.
    Return an array that consists of indices of peaks in the given array in any order.
    Notes:

    A peak is defined as an element that is strictly greater than its neighboring elements.
    The first and last elements of the array are not a peak.

    Example 1:

    >>> findPeaks(mountain = [2,4,4])
    >>> []
    Explanation: mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.
    mountain[1] also can not be a peak because it is not strictly greater than mountain[2].
    So the answer is [].

    Example 2:

    >>> findPeaks(mountain = [1,4,3,8,5])
    >>> [1,3]
    Explanation: mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.
    mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].
    But mountain [1] and mountain[3] are strictly greater than their neighboring elements.
    So the answer is [1,3].
    """


Prompt:
from typing import List
def minimumAddedCoins(coins: List[int], target: int) -> int:
    """
    You are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.
    An integer x is obtainable if there exists a subsequence of coins that sums to x.
    Return the minimum number of coins of any value that need to be added to the array so that every integer in the range [1, target] is obtainable.
    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:

    >>> minimumAddedCoins(coins = [1,4,10], target = 19)
    >>> 2
    Explanation: We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].
    It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.

    Example 2:

    >>> minimumAddedCoins(coins = [1,4,10,5,7,19], target = 19)
    >>> 1
    Explanation: We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].
    It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.

    Example 3:

    >>> minimumAddedCoins(coins = [1,1,1], target = 20)
    >>> 3
    Explanation: We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].
    It can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.
    """


Prompt:
def countCompleteSubstrings(word: str, k: int) -> int:
    """
    You are given a string word and an integer k.
    A substring s of word is complete if:

    Each character in s occurs exactly k times.
    The difference between two adjacent characters is at most 2. That is, for any two adjacent characters c1 and c2 in s, the absolute difference in their positions in the alphabet is at most 2.

    Return the number of complete substrings of word.
    A substring is a non-empty contiguous sequence of characters in a string.

    Example 1:

    >>> countCompleteSubstrings(word = "igigee", k = 2)
    >>> 3
    Explanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.

    Example 2:

    >>> countCompleteSubstrings(word = "aaabbbccc", k = 3)
    >>> 6
    Explanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.
    """


Prompt:
from typing import List
def sameEndSubstringCount(s: str, queries: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed string s, and a 2D array of integers queries, where queries[i] = [li, ri] indicates a substring of s starting from the index li and ending at the index ri (both inclusive), i.e. s[li..ri].
    Return an array ans where ans[i] is the number of same-end substrings of queries[i].
    A 0-indexed string t of length n is called same-end if it has the same character at both of its ends, i.e., t[0] == t[n - 1].
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    >>> sameEndSubstringCount(s = "abcaab", queries = [[0,0],[1,4],[2,5],[0,5]])
    >>> [1,5,5,10]
    Explanation: Here is the same-end substrings of each query:
    1st query: s[0..0] is "a" which has 1 same-end substring: "a".
    2nd query: s[1..4] is "bcaa" which has 5 same-end substrings: "bcaa", "bcaa", "bcaa", "bcaa", "bcaa".
    3rd query: s[2..5] is "caab" which has 5 same-end substrings: "caab", "caab", "caab", "caab", "caab".
    4th query: s[0..5] is "abcaab" which has 10 same-end substrings: "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab".

    Example 2:

    >>> sameEndSubstringCount(s = "abcd", queries = [[0,3]])
    >>> [4]
    Explanation: The only query is s[0..3] which is "abcd". It has 4 same-end substrings: "abcd", "abcd", "abcd", "abcd".
    """


Prompt:
from typing import List
def findIntersectionValues(nums1: List[int], nums2: List[int]) -> List[int]:
    """
    You are given two integer arrays nums1 and nums2 of sizes n and m, respectively. Calculate the following values:

    answer1 : the number of indices i such that nums1[i] exists in nums2.
    answer2 : the number of indices i such that nums2[i] exists in nums1.

    Return [answer1,answer2].

    Example 1:

    >>> findIntersectionValues(nums1 = [2,3,2], nums2 = [1,2])
    >>> [2,1]
    Explanation:

    Example 2:

    >>> findIntersectionValues(nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6])
    >>> [3,4]
    Explanation:
    The elements at indices 1, 2, and 3 in nums1 exist in nums2 as well. So answer1 is 3.
    The elements at indices 0, 1, 3, and 4 in nums2 exist in nums1. So answer2 is 4.

    Example 3:

    >>> findIntersectionValues(nums1 = [3,4,2,3], nums2 = [1,5])
    >>> [0,0]
    Explanation:
    No numbers are common between nums1 and nums2, so answer is [0,0].
    """


Prompt:
def removeAlmostEqualCharacters(word: str) -> int:
    """
    You are given a 0-indexed string word.
    In one operation, you can pick any index i of word and change word[i] to any lowercase English letter.
    Return the minimum number of operations needed to remove all adjacent almost-equal characters from word.
    Two characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.

    Example 1:

    >>> removeAlmostEqualCharacters(word = "aaaaa")
    >>> 2
    Explanation: We can change word into "acaca" which does not have any adjacent almost-equal characters.
    It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.

    Example 2:

    >>> removeAlmostEqualCharacters(word = "abddez")
    >>> 2
    Explanation: We can change word into "ybdoez" which does not have any adjacent almost-equal characters.
    It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
    Example 3:

    >>> removeAlmostEqualCharacters(word = "zyxyxyz")
    >>> 3
    Explanation: We can change word into "zaxaxaz" which does not have any adjacent almost-equal characters.
    It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.
    """


Prompt:
from typing import List
def maxSubarrayLength(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    The frequency of an element x is the number of times it occurs in an array.
    An array is called good if the frequency of each element in this array is less than or equal to k.
    Return the length of the longest good subarray of nums.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> maxSubarrayLength(nums = [1,2,3,1,2,3,1,2], k = 2)
    >>> 6
    Explanation: The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good.
    It can be shown that there are no good subarrays with length more than 6.

    Example 2:

    >>> maxSubarrayLength(nums = [1,2,1,2,1,2,1,2], k = 1)
    >>> 2
    Explanation: The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good.
    It can be shown that there are no good subarrays with length more than 2.

    Example 3:

    >>> maxSubarrayLength(nums = [5,5,5,5,5,5,5], k = 4)
    >>> 4
    Explanation: The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray.
    It can be shown that there are no good subarrays with length more than 4.
    """


Prompt:
from typing import List
def numberOfSets(n: int, maxDistance: int, roads: List[List[int]]) -> int:
    """
    There is a company with n branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.
    The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most maxDistance from each other.
    The distance between two branches is the minimum total traveled length needed to reach one branch from another.
    You are given integers n, maxDistance, and a 0-indexed 2D array roads, where roads[i] = [ui, vi, wi] represents the undirected road between branches ui and vi with length wi.
    Return the number of possible sets of closing branches, so that any branch has a distance of at most maxDistance from any other.
    Note that, after closing a branch, the company will no longer have access to any roads connected to it.
    Note that, multiple roads are allowed.

    Example 1:

    >>> numberOfSets(n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]])
    >>> 5
    Explanation: The possible sets of closing branches are:
    - The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.
    - The set [0,1], after closing, the active branch is [2].
    - The set [1,2], after closing, the active branch is [0].
    - The set [0,2], after closing, the active branch is [1].
    - The set [0,1,2], after closing, there are no active branches.
    It can be proven, that there are only 5 possible sets of closing branches.

    Example 2:

    >>> numberOfSets(n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]])
    >>> 7
    Explanation: The possible sets of closing branches are:
    - The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.
    - The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.
    - The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.
    - The set [0,1], after closing, the active branch is [2].
    - The set [1,2], after closing, the active branch is [0].
    - The set [0,2], after closing, the active branch is [1].
    - The set [0,1,2], after closing, there are no active branches.
    It can be proven, that there are only 7 possible sets of closing branches.

    Example 3:

    >>> numberOfSets(n = 1, maxDistance = 10, roads = [])
    >>> 2
    Explanation: The possible sets of closing branches are:
    - The set [], after closing, the active branch is [0].
    - The set [0], after closing, there are no active branches.
    It can be proven, that there are only 2 possible sets of closing branches.
    """


Prompt:
from typing import List
def countTestedDevices(batteryPercentages: List[int]) -> int:
    """
    You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.
    Your task is to test each device i in order from 0 to n - 1, by performing the following test operations:

    If batteryPercentages[i] is greater than 0:

    Increment the count of tested devices.
    Decrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1).
    Move to the next device.

    Otherwise, move to the next device without performing any test.

    Return an integer denoting the number of devices that will be tested after performing the test operations in order.

    Example 1:

    >>> countTestedDevices(batteryPercentages = [1,1,2,1,3])
    >>> 3
    Explanation: Performing the test operations in order starting from device 0:
    At device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].
    At device 1, batteryPercentages[1] == 0, so we move to the next device without testing.
    At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].
    At device 3, batteryPercentages[3] == 0, so we move to the next device without testing.
    At device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.
    So, the answer is 3.

    Example 2:

    >>> countTestedDevices(batteryPercentages = [0,1,2])
    >>> 2
    Explanation: Performing the test operations in order starting from device 0:
    At device 0, batteryPercentages[0] == 0, so we move to the next device without testing.
    At device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].
    At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.
    So, the answer is 2.
    """


Prompt:
from typing import List
def countSubarrays(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and a positive integer k.
    Return the number of subarrays where the maximum element of nums appears at least k times in that subarray.
    A subarray is a contiguous sequence of elements within an array.

    Example 1:

    >>> countSubarrays(nums = [1,3,2,3,3], k = 2)
    >>> 6
    Explanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].

    Example 2:

    >>> countSubarrays(nums = [1,4,2,1], k = 3)
    >>> 0
    Explanation: No subarray contains the element 4 at least 3 times.
    """


Prompt:
from typing import Any, List
def divisibleTripletCount(nums: List[int], d: int) -> int:
    """
    Given a 0-indexed integer array nums and an integer d, return the number of triplets (i, j, k) such that i < j < k and (nums[i] + nums[j] + nums[k]) % d == 0.

    Example 1:

    >>> divisibleTripletCount(nums = [3,3,4,7,8], d = 5)
    >>> 3
    Explanation: The triplets which are divisible by 5 are: (0, 1, 2), (0, 2, 4), (1, 2, 4).
    It can be shown that no other triplet is divisible by 5. Hence, the answer is 3.

    Example 2:

    >>> divisibleTripletCount(nums = [3,3,3,3], d = 3)
    >>> 4
    Explanation: Any triplet chosen here has a sum of 9, which is divisible by 3. Hence, the answer is the total number of triplets which is 4.

    Example 3:

    >>> divisibleTripletCount(nums = [3,3,3,3], d = 6)
    >>> 0
    Explanation: Any triplet chosen here has a sum of 9, which is not divisible by 6. Hence, the answer is 0.
    """


Prompt:
from typing import List
def findMissingAndRepeatedValues(grid: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appears twice and b which is missing. The task is to find the repeating and missing numbers a and b.
    Return a 0-indexed integer array ans of size 2 where ans[0] equals to a and ans[1] equals to b.

    Example 1:

    >>> findMissingAndRepeatedValues(grid = [[1,3],[2,2]])
    >>> [2,4]
    Explanation: Number 2 is repeated and number 4 is missing so the answer is [2,4].

    Example 2:

    >>> findMissingAndRepeatedValues(grid = [[9,1,7],[8,9,2],[3,4,6]])
    >>> [9,5]
    Explanation: Number 9 is repeated and number 5 is missing so the answer is [9,5].
    """


Prompt:
from typing import List
def divideArray(nums: List[int], k: int) -> List[List[int]]:
    """
    You are given an integer array nums of size n where n is a multiple of 3 and a positive integer k.
    Divide the array nums into n / 3 arrays of size 3 satisfying the following condition:

    The difference between any two elements in one array is less than or equal to k.

    Return a 2D array containing the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return any of them.

    Example 1:

    >>> divideArray(nums = [1,3,4,8,7,9,3,5,1], k = 2)
    >>> [[1,1,3],[3,4,5],[7,8,9]]
    Explanation:
    The difference between any two elements in each array is less than or equal to 2.

    Example 2:

    >>> divideArray(nums = [2,4,2,2,5,2], k = 2)
    >>> []
    Explanation:
    Different ways to divide nums into 2 arrays of size 3 are:

    [[2,2,2],[2,4,5]] (and its permutations)
    [[2,2,4],[2,2,5]] (and its permutations)

    Because there are four 2s there will be an array with the elements 2 and 5 no matter how we divide it. since 5 - 2 = 3 > k, the condition is not satisfied and so there is no valid division.

    Example 3:

    >>> divideArray(nums = [4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11], k = 14)
    >>> [[2,2,12],[4,8,5],[5,9,7],[7,8,5],[5,9,10],[11,12,2]]
    Explanation:
    The difference between any two elements in each array is less than or equal to 14.
    """


Prompt:
from typing import List
def minimumCost(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums having length n.
    You are allowed to perform a special move any number of times (including zero) on nums. In one special move you perform the following steps in order:

    Choose an index i in the range [0, n - 1], and a positive integer x.
    Add |nums[i] - x| to the total cost.
    Change the value of nums[i] to x.

    A palindromic number is a positive integer that remains the same when its digits are reversed. For example, 121, 2552 and 65756 are palindromic numbers whereas 24, 46, 235 are not palindromic numbers.
    An array is considered equalindromic if all the elements in the array are equal to an integer y, where y is a palindromic number less than 109.
    Return an integer denoting the minimum possible total cost to make nums equalindromic by performing any number of special moves.

    Example 1:

    >>> minimumCost(nums = [1,2,3,4,5])
    >>> 6
    Explanation: We can make the array equalindromic by changing all elements to 3 which is a palindromic number. The cost of changing the array to [3,3,3,3,3] using 4 special moves is given by |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6.
    It can be shown that changing all elements to any palindromic number other than 3 cannot be achieved at a lower cost.

    Example 2:

    >>> minimumCost(nums = [10,12,13,14,15])
    >>> 11
    Explanation: We can make the array equalindromic by changing all elements to 11 which is a palindromic number. The cost of changing the array to [11,11,11,11,11] using 5 special moves is given by |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11.
    It can be shown that changing all elements to any palindromic number other than 11 cannot be achieved at a lower cost.

    Example 3:

    >>> minimumCost(nums = [22,33,22,33,22])
    >>> 22
    Explanation: We can make the array equalindromic by changing all elements to 22 which is a palindromic number. The cost of changing the array to [22,22,22,22,22] using 2 special moves is given by |33 - 22| + |33 - 22| = 22.
    It can be shown that changing all elements to any palindromic number other than 22 cannot be achieved at a lower cost.
    """


Prompt:
from typing import List
def maxFrequencyScore(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.
    You can perform the following operation on the array at most k times:

    Choose any index i from the array and increase or decrease nums[i] by 1.

    The score of the final array is the frequency of the most frequent element in the array.
    Return the maximum score you can achieve.
    The frequency of an element is the number of occurences of that element in the array.

    Example 1:

    >>> maxFrequencyScore(nums = [1,2,6,4], k = 3)
    >>> 3
    Explanation: We can do the following operations on the array:
    - Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4].
    - Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3].
    - Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2].
    The element 2 is the most frequent in the final array so our score is 3.
    It can be shown that we cannot achieve a better score.

    Example 2:

    >>> maxFrequencyScore(nums = [1,4,4,2,4], k = 0)
    >>> 3
    Explanation: We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3.
    """


Prompt:
from typing import List
def minimumCoins(prices: List[int]) -> int:
    """
    You are at a fruit market with different types of exotic fruits on display.
    You are given a 1-indexed array prices, where prices[i] denotes the number of coins needed to purchase the ith fruit.
    The fruit market has the following offer:

    If you purchase the ith fruit at prices[i] coins, you can get the next i fruits for free.

    Note that even if you can take fruit j for free, you can still purchase it for prices[j] coins to receive a new offer.
    Return the minimum number of coins needed to acquire all the fruits.

    Example 1:

    >>> minimumCoins(prices = [3,1,2])
    >>> 4
    Explanation: You can acquire the fruits as follows:
    - Purchase the 1st fruit with 3 coins, and you are allowed to take the 2nd fruit for free.
    - Purchase the 2nd fruit with 1 coin, and you are allowed to take the 3rd fruit for free.
    - Take the 3rd fruit for free.
    Note that even though you were allowed to take the 2nd fruit for free, you purchased it because it is more optimal.
    It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.

    Example 2:

    >>> minimumCoins(prices = [1,10,1,1])
    >>> 2
    Explanation: You can acquire the fruits as follows:
    - Purchase the 1st fruit with 1 coin, and you are allowed to take the 2nd fruit for free.
    - Take the 2nd fruit for free.
    - Purchase the 3rd fruit for 1 coin, and you are allowed to take the 4th fruit for free.
    - Take the 4th fruit for free.
    It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.
    """


Prompt:
from typing import List
def incremovableSubarrayCount(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of positive integers nums.
    A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.
    Return the total number of incremovable subarrays of nums.
    Note that an empty array is considered strictly increasing.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> incremovableSubarrayCount(nums = [1,2,3,4])
    >>> 10
    Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.

    Example 2:

    >>> incremovableSubarrayCount(nums = [6,5,7,8])
    >>> 7
    Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
    It can be shown that there are only 7 incremovable subarrays in nums.

    Example 3:

    >>> incremovableSubarrayCount(nums = [8,7,6,6])
    >>> 3
    Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
    """


Prompt:
from typing import List
def largestPerimeter(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums of length n.
    A polygon is a closed plane figure that has at least 3 sides. The longest side of a polygon is smaller than the sum of its other sides.
    Conversely, if you have k (k >= 3) positive real numbers a1, a2, a3, ..., ak where a1 <= a2 <= a3 <= ... <= ak and a1 + a2 + a3 + ... + ak-1 > ak, then there always exists a polygon with k sides whose lengths are a1, a2, a3, ..., ak.
    The perimeter of a polygon is the sum of lengths of its sides.
    Return the largest possible perimeter of a polygon whose sides can be formed from nums, or -1 if it is not possible to create a polygon.

    Example 1:

    >>> largestPerimeter(nums = [5,5,5])
    >>> 15
    Explanation: The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.

    Example 2:

    >>> largestPerimeter(nums = [1,12,1,2,5,50,3])
    >>> 12
    Explanation: The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12.
    We cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them.
    It can be shown that the largest possible perimeter is 12.

    Example 3:

    >>> largestPerimeter(nums = [5,5,50])
    >>> -1
    Explanation: There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 > 5 + 5.
    """


Prompt:
from typing import List
def incremovableSubarrayCount(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of positive integers nums.
    A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.
    Return the total number of incremovable subarrays of nums.
    Note that an empty array is considered strictly increasing.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> incremovableSubarrayCount(nums = [1,2,3,4])
    >>> 10
    Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.

    Example 2:

    >>> incremovableSubarrayCount(nums = [6,5,7,8])
    >>> 7
    Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
    It can be shown that there are only 7 incremovable subarrays in nums.

    Example 3:

    >>> incremovableSubarrayCount(nums = [8,7,6,6])
    >>> 3
    Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
    """


Prompt:
from typing import List
def placedCoins(edges: List[List[int]], cost: List[int]) -> List[int]:
    """
    You are given 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 cost of length n, where cost[i] is the cost assigned to the ith node.
    You need to place some coins on every node of the tree. The number of coins to be placed at node i can be calculated as:

    If size of the subtree of node i is less than 3, place 1 coin.
    Otherwise, place an amount of coins equal to the maximum product of cost values assigned to 3 distinct nodes in the subtree of node i. If this product is negative, place 0 coins.

    Return an array coin of size n such that coin[i] is the number of coins placed at node i.

    Example 1:

    >>> placedCoins(edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6])
    >>> [120,1,1,1,1,1]
    Explanation: For node 0 place 6 * 5 * 4 = 120 coins. All other nodes are leaves with subtree of size 1, place 1 coin on each of them.

    Example 2:

    >>> placedCoins(edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2])
    >>> [280,140,32,1,1,1,1,1,1]
    Explanation: The coins placed on each node are:
    - Place 8 * 7 * 5 = 280 coins on node 0.
    - Place 7 * 5 * 4 = 140 coins on node 1.
    - Place 8 * 2 * 2 = 32 coins on node 2.
    - All other nodes are leaves with subtree of size 1, place 1 coin on each of them.

    Example 3:

    >>> placedCoins(edges = [[0,1],[0,2]], cost = [1,2,-2])
    >>> [0,1,1]
    Explanation: Node 1 and 2 are leaves with subtree of size 1, place 1 coin on each of them. For node 0 the only possible product of cost is 2 * 1 * -2 = -4. Hence place 0 coins on node 0.
    """


Prompt:
from typing import List
def numberGame(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:

    Every round, first Alice will remove the minimum element from nums, and then Bob does the same.
    Now, first Bob will append the removed element in the array arr, and then Alice does the same.
    The game continues until nums becomes empty.

    Return the resulting array arr.

    Example 1:

    >>> numberGame(nums = [5,4,2,3])
    >>> [3,2,5,4]
    Explanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].
    At the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].

    Example 2:

    >>> numberGame(nums = [2,5])
    >>> [5,2]
    Explanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].
    """


Prompt:
from typing import List
def maximizeSquareArea(m: int, n: int, hFences: List[int], vFences: List[int]) -> int:
    """
    There is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.
    Horizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).
    Return the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.
    Since the answer may be large, return it modulo 109 + 7.
    Note: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.

    Example 1:

    >>> maximizeSquareArea(m = 4, n = 3, hFences = [2,3], vFences = [2])
    >>> 4
    Explanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.

    Example 2:

    >>> maximizeSquareArea(m = 6, n = 7, hFences = [2], vFences = [4])
    >>> -1
    Explanation: It can be proved that there is no way to create a square field by removing fences.
    """


Prompt:
from typing import List
def minimumCost(source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:
    """
    You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].
    You start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y.
    Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.
    Note that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].

    Example 1:

    >>> minimumCost(source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20])
    >>> 28
    Explanation: To convert the string "abcd" to string "acbe":
    - Change value at index 1 from 'b' to 'c' at a cost of 5.
    - Change value at index 2 from 'c' to 'e' at a cost of 1.
    - Change value at index 2 from 'e' to 'b' at a cost of 2.
    - Change value at index 3 from 'd' to 'e' at a cost of 20.
    The total cost incurred is 5 + 1 + 2 + 20 = 28.
    It can be shown that this is the minimum possible cost.

    Example 2:

    >>> minimumCost(source = "aaaa", target = "bbbb", original = ["a","c"], changed = ["c","b"], cost = [1,2])
    >>> 12
    Explanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.

    Example 3:

    >>> minimumCost(source = "abcd", target = "abce", original = ["a"], changed = ["e"], cost = [10000])
    >>> -1
    Explanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.
    """