Prompt:
from typing import Optional
class ListNode:
    def __init__(val=0, next=None):
        self.val = val
        self.next = next
def gameResult(head: Optional[ListNode]) -> str:
"""
You are given the head of a linked list of even length containing integers.
Each odd-indexed node contains an odd integer and each even-indexed node contains an even integer.
We call each even-indexed node and its next node a pair, e.g., the nodes with indices 0 and 1 are a pair, the nodes with indices 2 and 3 are a pair, and so on.
For every pair, we compare the values of the nodes in the pair:

If the odd-indexed node is higher, the "Odd" team gets a point.
If the even-indexed node is higher, the "Even" team gets a point.

Return the name of the team with the higher points, if the points are equal, return "Tie".

Example 1:

>>> gameResult(head = [2,1])
>>> "Even"
Explanation:  There is only one pair in this linked list and that is (2,1). Since 2 > 1, the Even team gets the point.
Hence, the answer would be "Even".

Example 2:

>>> gameResult(head = [2,5,4,7,20,5])
>>> "Odd"
Explanation:  There are 3 pairs in this linked list. Let's investigate each pair individually:
(2,5) -> Since 2 < 5, The Odd team gets the point.
(4,7) -> Since 4 < 7, The Odd team gets the point.
(20,5) -> Since 20 > 5, The Even team gets the point.
The Odd team earned 2 points while the Even team got 1 point and the Odd team has the higher points.
Hence, the answer would be "Odd".

Example 3:

>>> gameResult(head = [4,5,2,1])
>>> "Tie"
Explanation:  There are 2 pairs in this linked list. Let's investigate each pair individually:
(4,5) -> Since 4 < 5, the Odd team gets the point.
(2,1) -> Since 2 > 1, the Even team gets the point.
Both teams earned 1 point.
Hence, the answer would be "Tie".
"""


Prompt:
from typing import Optional
class ListNode:
    def __init__(val=0, next=None):
        self.val = val
        self.next = next
def frequenciesOfElements(head: Optional[ListNode]) -> Optional[ListNode]:
"""
Given the head of a linked list containing k distinct elements, return the head to a linked list of length k containing the frequency of each distinct element in the given linked list in any order.

Example 1:

>>> frequenciesOfElements(head = [1,1,2,1,2,3])
>>> [3,2,1]
Explanation:  There are 3 distinct elements in the list. The frequency of 1 is 3, the frequency of 2 is 2 and the frequency of 3 is 1. Hence, we return 3 -> 2 -> 1.
Note that 1 -> 2 -> 3, 1 -> 3 -> 2, 2 -> 1 -> 3, 2 -> 3 -> 1, and 3 -> 1 -> 2 are also valid answers.

Example 2:

>>> frequenciesOfElements(head = [1,1,2,2,2])
>>> [2,3]
Explanation:  There are 2 distinct elements in the list. The frequency of 1 is 2 and the frequency of 2 is 3. Hence, we return 2 -> 3.

Example 3:

>>> frequenciesOfElements(head = [6,5,4,3,2,1])
>>> [1,1,1,1,1,1]
Explanation:  There are 6 distinct elements in the list. The frequency of each of them is 1. Hence, we return 1 -> 1 -> 1 -> 1 -> 1 -> 1.
"""


Prompt:
from typing import List
def minOperations(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums, and an integer k.
    In one operation, you can remove one occurrence of the smallest element of nums.
    Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.

    Example 1:

    >>> minOperations(nums = [2,11,10,1,3], k = 10)
    >>> 3
    Explanation: After one operation, nums becomes equal to [2, 11, 10, 3].
    After two operations, nums becomes equal to [11, 10, 3].
    After three operations, nums becomes equal to [11, 10].
    At this stage, all the elements of nums are greater than or equal to 10 so we can stop.
    It can be shown that 3 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.

    Example 2:

    >>> minOperations(nums = [1,1,2,4,9], k = 1)
    >>> 0
    Explanation: All elements of the array are greater than or equal to 1 so we do not need to apply any operations on nums.
    Example 3:

    >>> minOperations(nums = [1,1,2,4,9], k = 9)
    >>> 4
    Explanation: only a single element of nums is greater than or equal to 9 so we need to apply the operations 4 times on nums.
    """


Prompt:
from typing import List
def minOperations(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums, and an integer k.
    You are allowed to perform some operations on nums, where in a single operation, you can:

    Select the two smallest integers x and y from nums.
    Remove x and y from nums.
    Insert (min(x, y) * 2 + max(x, y)) at any position in the array.

    Note that you can only apply the described operation if nums contains at least two elements.
    Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.

    Example 1:

    >>> minOperations(nums = [2,11,10,1,3], k = 10)
    >>> 2
    Explanation:

    In the first operation, we remove elements 1 and 2, then add 1 * 2 + 2 to nums. nums becomes equal to [4, 11, 10, 3].
    In the second operation, we remove elements 3 and 4, then add 3 * 2 + 4 to nums. nums becomes equal to [10, 11, 10].

    At this stage, all the elements of nums are greater than or equal to 10 so we can stop.
    It can be shown that 2 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.

    Example 2:

    >>> minOperations(nums = [1,1,2,4,9], k = 20)
    >>> 4
    Explanation:

    After one operation, nums becomes equal to [2, 4, 9, 3].
    After two operations, nums becomes equal to [7, 4, 9].
    After three operations, nums becomes equal to [15, 9].
    After four operations, nums becomes equal to [33].

    At this stage, all the elements of nums are greater than 20 so we can stop.
    It can be shown that 4 is the minimum number of operations needed so that all elements of the array are greater than or equal to 20.
    """


Prompt:
from typing import List
def countPairsOfConnectableServers(edges: List[List[int]], signalSpeed: int) -> List[int]:
    """
    You are given an unrooted weighted tree with n vertices representing servers numbered from 0 to n - 1, an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional edge between vertices ai and bi of weight weighti. You are also given an integer signalSpeed.
    Two servers a and b are connectable through a server c if:

    a < b, a != c and b != c.
    The distance from c to a is divisible by signalSpeed.
    The distance from c to b is divisible by signalSpeed.
    The path from c to b and the path from c to a do not share any edges.

    Return an integer array count of length n where count[i] is the number of server pairs that are connectable through the server i.

    Example 1:

    >>> countPairsOfConnectableServers(edges = [[0,1,1],[1,2,5],[2,3,13],[3,4,9],[4,5,2]], signalSpeed = 1)
    >>> [0,4,6,6,4,0]
    Explanation: Since signalSpeed is 1, count[c] is equal to the number of pairs of paths that start at c and do not share any edges.
    In the case of the given path graph, count[c] is equal to the number of servers to the left of c multiplied by the servers to the right of c.

    Example 2:

    >>> countPairsOfConnectableServers(edges = [[0,6,3],[6,5,3],[0,3,1],[3,2,7],[3,1,6],[3,4,2]], signalSpeed = 3)
    >>> [2,0,0,0,0,0,2]
    Explanation: Through server 0, there are 2 pairs of connectable servers: (4, 5) and (4, 6).
    Through server 6, there are 2 pairs of connectable servers: (4, 5) and (0, 5).
    It can be shown that no two servers are connectable through servers other than 0 and 6.
    """


Prompt:
from typing import List
def maximumValueSum(nums: List[int], k: int, edges: List[List[int]]) -> int:
    """
    There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 0-indexed 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree. You are also given a positive integer k, and a 0-indexed array of non-negative integers nums of length n, where nums[i] represents the value of the node numbered i.
    Alice wants the sum of values of tree nodes to be maximum, for which Alice can perform the following operation any number of times (including zero) on the tree:

    Choose any edge [u, v] connecting the nodes u and v, and update their values as follows:

    nums[u] = nums[u] XOR k
    nums[v] = nums[v] XOR k

    Return the maximum possible sum of the values Alice can achieve by performing the operation any number of times.

    Example 1:

    >>> maximumValueSum(nums = [1,2,1], k = 3, edges = [[0,1],[0,2]])
    >>> 6
    Explanation: Alice can achieve the maximum sum of 6 using a single operation:
    - Choose the edge [0,2]. nums[0] and nums[2] become: 1 XOR 3 = 2, and the array nums becomes: [1,2,1] -> [2,2,2].
    The total sum of values is 2 + 2 + 2 = 6.
    It can be shown that 6 is the maximum achievable sum of values.

    Example 2:

    >>> maximumValueSum(nums = [2,3], k = 7, edges = [[0,1]])
    >>> 9
    Explanation: Alice can achieve the maximum sum of 9 using a single operation:
    - Choose the edge [0,1]. nums[0] becomes: 2 XOR 7 = 5 and nums[1] become: 3 XOR 7 = 4, and the array nums becomes: [2,3] -> [5,4].
    The total sum of values is 5 + 4 = 9.
    It can be shown that 9 is the maximum achievable sum of values.

    Example 3:

    >>> maximumValueSum(nums = [7,7,7,7,7,7], k = 3, edges = [[0,1],[0,2],[0,3],[0,4],[0,5]])
    >>> 42
    Explanation: The maximum achievable sum is 42 which can be achieved by Alice performing no operations.
    """


Prompt:
from typing import List
def resultArray(nums: List[int]) -> List[int]:
    """
    You are given a 1-indexed array of distinct integers nums of length n.
    You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the ith operation:

    If the last element of arr1 is greater than the last element of arr2, append nums[i] to arr1. Otherwise, append nums[i] to arr2.

    The array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6].
    Return the array result.

    Example 1:

    >>> resultArray(nums = [2,1,3])
    >>> [2,3,1]
    Explanation: After the first 2 operations, arr1 = [2] and arr2 = [1].
    In the 3rd operation, as the last element of arr1 is greater than the last element of arr2 (2 > 1), append nums[3] to arr1.
    After 3 operations, arr1 = [2,3] and arr2 = [1].
    Hence, the array result formed by concatenation is [2,3,1].

    Example 2:

    >>> resultArray(nums = [5,4,3,8])
    >>> [5,3,4,8]
    Explanation: After the first 2 operations, arr1 = [5] and arr2 = [4].
    In the 3rd operation, as the last element of arr1 is greater than the last element of arr2 (5 > 4), append nums[3] to arr1, hence arr1 becomes [5,3].
    In the 4th operation, as the last element of arr2 is greater than the last element of arr1 (4 > 3), append nums[4] to arr2, hence arr2 becomes [4,8].
    After 4 operations, arr1 = [5,3] and arr2 = [4,8].
    Hence, the array result formed by concatenation is [5,3,4,8].
    """


Prompt:
from typing import List
def countSubmatrices(grid: List[List[int]], k: int) -> int:
    """
    You are given a 0-indexed integer matrix grid and an integer k.
    Return the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k.

    Example 1:

    >>> countSubmatrices(grid = [[7,6,3],[6,6,1]], k = 18)
    >>> 4
    Explanation: There are only 4 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 18.
    Example 2:

    >>> countSubmatrices(grid = [[7,2,9],[1,5,0],[2,6,6]], k = 20)
    >>> 6
    Explanation: There are only 6 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 20.
    """


Prompt:
from typing import List
def minimumOperationsToWriteY(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0, 1, or 2.
    We say that a cell belongs to the Letter Y if it belongs to one of the following:

    The diagonal starting at the top-left cell and ending at the center cell of the grid.
    The diagonal starting at the top-right cell and ending at the center cell of the grid.
    The vertical line starting at the center cell and ending at the bottom border of the grid.

    The Letter Y is written on the grid if and only if:

    All values at cells belonging to the Y are equal.
    All values at cells not belonging to the Y are equal.
    The values at cells belonging to the Y are different from the values at cells not belonging to the Y.

    Return the minimum number of operations needed to write the letter Y on the grid given that in one operation you can change the value at any cell to 0, 1, or 2.

    Example 1:

    >>> minimumOperationsToWriteY(grid = [[1,2,2],[1,1,0],[0,1,0]])
    >>> 3
    Explanation: We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 1 while those that do not belong to Y are equal to 0.
    It can be shown that 3 is the minimum number of operations needed to write Y on the grid.

    Example 2:

    >>> minimumOperationsToWriteY(grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]])
    >>> 12
    Explanation: We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 0 while those that do not belong to Y are equal to 2.
    It can be shown that 12 is the minimum number of operations needed to write Y on the grid.
    """


Prompt:
from typing import List
def resultArray(nums: List[int]) -> List[int]:
    """
    You are given a 1-indexed array of integers nums of length n.
    We define a function greaterCount such that greaterCount(arr, val) returns the number of elements in arr that are strictly greater than val.
    You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the ith operation:

    If greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i]), append nums[i] to arr1.
    If greaterCount(arr1, nums[i]) < greaterCount(arr2, nums[i]), append nums[i] to arr2.
    If greaterCount(arr1, nums[i]) == greaterCount(arr2, nums[i]), append nums[i] to the array with a lesser number of elements.
    If there is still a tie, append nums[i] to arr1.

    The array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6].
    Return the integer array result.

    Example 1:

    >>> resultArray(nums = [2,1,3,3])
    >>> [2,3,1,3]
    Explanation: After the first 2 operations, arr1 = [2] and arr2 = [1].
    In the 3rd operation, the number of elements greater than 3 is zero in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1.
    In the 4th operation, the number of elements greater than 3 is zero in both arrays. As the length of arr2 is lesser, hence, append nums[4] to arr2.
    After 4 operations, arr1 = [2,3] and arr2 = [1,3].
    Hence, the array result formed by concatenation is [2,3,1,3].

    Example 2:

    >>> resultArray(nums = [5,14,3,1,2])
    >>> [5,3,1,2,14]
    Explanation: After the first 2 operations, arr1 = [5] and arr2 = [14].
    In the 3rd operation, the number of elements greater than 3 is one in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1.
    In the 4th operation, the number of elements greater than 1 is greater in arr1 than arr2 (2 > 1). Hence, append nums[4] to arr1.
    In the 5th operation, the number of elements greater than 2 is greater in arr1 than arr2 (2 > 1). Hence, append nums[5] to arr1.
    After 5 operations, arr1 = [5,3,1,2] and arr2 = [14].
    Hence, the array result formed by concatenation is [5,3,1,2,14].

    Example 3:

    >>> resultArray(nums = [3,3,3,3])
    >>> [3,3,3,3]
    Explanation: At the end of 4 operations, arr1 = [3,3] and arr2 = [3,3].
    Hence, the array result formed by concatenation is [3,3,3,3].
    """


Prompt:
from typing import List
def maximumTripletValue(nums: List[int]) -> int:
    """
    Given an array nums, return the maximum value of a triplet (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k].
    The value of a triplet (i, j, k) is nums[i] - nums[j] + nums[k].

    Example 1:

    >>> maximumTripletValue(nums = [5,6,9])
    >>> 8
    Explanation:  We only have one choice for an increasing triplet and that is choosing all three elements. The value of this triplet would be 5 - 6 + 9 = 8.

    Example 2:

    >>> maximumTripletValue(nums = [1,5,3,6])
    >>> 4
    Explanation:  There are only two increasing triplets:
    (0, 1, 3): The value of this triplet is nums[0] - nums[1] + nums[3] = 1 - 5 + 6 = 2.
    (0, 2, 3): The value of this triplet is nums[0] - nums[2] + nums[3] = 1 - 3 + 6 = 4.
    Thus the answer would be 4.
    """


Prompt:
from typing import List
def minimumBoxes(apple: List[int], capacity: List[int]) -> int:
    """
    You are given an array apple of size n and an array capacity of size m.
    There are n packs where the ith pack contains apple[i] apples. There are m boxes as well, and the ith box has a capacity of capacity[i] apples.
    Return the minimum number of boxes you need to select to redistribute these n packs of apples into boxes.
    Note that, apples from the same pack can be distributed into different boxes.

    Example 1:

    >>> minimumBoxes(apple = [1,3,2], capacity = [4,3,1,5,2])
    >>> 2
    Explanation: We will use boxes with capacities 4 and 5.
    It is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples.

    Example 2:

    >>> minimumBoxes(apple = [5,5,5], capacity = [2,4,2,7])
    >>> 4
    Explanation: We will need to use all the boxes.
    """


Prompt:
from typing import List
def maximumHappinessSum(happiness: List[int], k: int) -> int:
    """
    You are given an array happiness of length n, and a positive integer k.
    There are n children standing in a queue, where the ith child has happiness value happiness[i]. You want to select k children from these n children in k turns.
    In each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive.
    Return the maximum sum of the happiness values of the selected children you can achieve by selecting k children.

    Example 1:

    >>> maximumHappinessSum(happiness = [1,2,3], k = 2)
    >>> 4
    Explanation: We can pick 2 children in the following way:
    - Pick the child with the happiness value == 3. The happiness value of the remaining children becomes [0,1].
    - Pick the child with the happiness value == 1. The happiness value of the remaining child becomes [0]. Note that the happiness value cannot become less than 0.
    The sum of the happiness values of the selected children is 3 + 1 = 4.

    Example 2:

    >>> maximumHappinessSum(happiness = [1,1,1,1], k = 2)
    >>> 1
    Explanation: We can pick 2 children in the following way:
    - Pick any child with the happiness value == 1. The happiness value of the remaining children becomes [0,0,0].
    - Pick the child with the happiness value == 0. The happiness value of the remaining child becomes [0,0].
    The sum of the happiness values of the selected children is 1 + 0 = 1.

    Example 3:

    >>> maximumHappinessSum(happiness = [2,3,4,5], k = 1)
    >>> 5
    Explanation: We can pick 1 child in the following way:
    - Pick the child with the happiness value == 5. The happiness value of the remaining children becomes [1,2,3].
    The sum of the happiness values of the selected children is 5.
    """


Prompt:
from typing import List
def shortestSubstrings(arr: List[str]) -> List[str]:
    """
    You are given an array arr of size n consisting of non-empty strings.
    Find a string array answer of size n such that:

    answer[i] is the shortest substring of arr[i] that does not occur as a substring in any other string in arr. If multiple such substrings exist, answer[i] should be the lexicographically smallest. And if no such substring exists, answer[i] should be an empty string.

    Return the array answer.

    Example 1:

    >>> shortestSubstrings(arr = ["cab","ad","bad","c"])
    >>> ["ab","","ba",""]
    Explanation: We have the following:
    - For the string "cab", the shortest substring that does not occur in any other string is either "ca" or "ab", we choose the lexicographically smaller substring, which is "ab".
    - For the string "ad", there is no substring that does not occur in any other string.
    - For the string "bad", the shortest substring that does not occur in any other string is "ba".
    - For the string "c", there is no substring that does not occur in any other string.

    Example 2:

    >>> shortestSubstrings(arr = ["abc","bcd","abcd"])
    >>> ["","","abcd"]
    Explanation: We have the following:
    - For the string "abc", there is no substring that does not occur in any other string.
    - For the string "bcd", there is no substring that does not occur in any other string.
    - For the string "abcd", the shortest substring that does not occur in any other string is "abcd".
    """


Prompt:
from typing import List
def maximumStrength(nums: List[int], k: int) -> int:
    """
    You are given an array of integers nums with length n, and a positive odd integer k.
    Select exactly k disjoint subarrays sub1, sub2, ..., subk from nums such that the last element of subi appears before the first element of sub{i+1} for all 1 <= i <= k-1. The goal is to maximize their combined strength.
    The strength of the selected subarrays is defined as:
    strength = k * sum(sub1)- (k - 1) * sum(sub2) + (k - 2) * sum(sub3) - ... - 2 * sum(sub{k-1}) + sum(subk)
    where sum(subi) is the sum of the elements in the i-th subarray.
    Return the maximum possible strength that can be obtained from selecting exactly k disjoint subarrays from nums.
    Note that the chosen subarrays don't need to cover the entire array.

    Example 1:
    >>> maximumStrength(nums = [1,2,3,-1,2], k = 3)
    >>> 22
    Explanation:
    The best possible way to select 3 subarrays is: nums[0..2], nums[3..3], and nums[4..4]. The strength is calculated as follows:
    strength = 3 * (1 + 2 + 3) - 2 * (-1) + 2 = 22

    Example 2:
    >>> maximumStrength(nums = [12,-2,-2,-2,-2], k = 5)
    >>> 64
    Explanation:
    The only possible way to select 5 disjoint subarrays is: nums[0..0], nums[1..1], nums[2..2], nums[3..3], and nums[4..4]. The strength is calculated as follows:
    strength = 5 * 12 - 4 * (-2) + 3 * (-2) - 2 * (-2) + (-2) = 64
    Example 3:
    >>> maximumStrength(nums = [-1,-2,-3], k = 1)
    >>> -1
    Explanation:
    The best possible way to select 1 subarray is: nums[0..0]. The strength is -1.
    """


Prompt:
from typing import List
def findPattern(board: List[List[int]], pattern: List[str]) -> List[int]:
    """
    You are given a 2D integer matrix board and a 2D character matrix pattern. Where 0 <= board[r][c] <= 9 and each element of pattern is either a digit or a lowercase English letter.
    Your task is to find a submatrix of board that matches pattern.
    An integer matrix part matches pattern if we can replace cells containing letters in pattern with some digits (each distinct letter with a unique digit) in such a way that the resulting matrix becomes identical to the integer matrix part. In other words,

    The matrices have identical dimensions.
    If pattern[r][c] is a digit, then part[r][c] must be the same digit.
    If pattern[r][c] is a letter x:

    For every pattern[i][j] == x, part[i][j] must be the same as part[r][c].
    For every pattern[i][j] != x, part[i][j] must be different than part[r][c].

    Return an array of length 2 containing the row number and column number of the upper-left corner of a submatrix of board which matches pattern. If there is more than one such submatrix, return the coordinates of the submatrix with the lowest row index, and in case there is still a tie, return the coordinates of the submatrix with the lowest column index. If there are no suitable answers, return [-1, -1].

    Example 1:

    1
    2
    2

    2
    2
    3

    2
    3
    3

    a
    b

    b
    b

    >>> findPattern(board = [[1,2,2],[2,2,3],[2,3,3]], pattern = ["ab","bb"])
    >>> [0,0]
    Explanation: If we consider this mapping: "a" -> 1 and "b" -> 2; the submatrix with the upper-left corner (0,0) is a match as outlined in the matrix above.
    Note that the submatrix with the upper-left corner (1,1) is also a match but since it comes after the other one, we return [0,0].

    Example 2:

    1
    1
    2

    3
    3
    4

    6
    6
    6

    a
    b

    6
    6

    >>> findPattern(board = [[1,1,2],[3,3,4],[6,6,6]], pattern = ["ab","66"])
    >>> [1,1]
    Explanation: If we consider this mapping: "a" -> 3 and "b" -> 4; the submatrix with the upper-left corner (1,1) is a match as outlined in the matrix above.
    Note that since the corresponding values of "a" and "b" must differ, the submatrix with the upper-left corner (1,0) is not a match. Hence, we return [1,1].

    Example 3:

    1
    2

    2
    1

    x
    x

    >>> findPattern(board = [[1,2],[2,1]], pattern = ["xx"])
    >>> [-1,-1]
    Explanation: Since the values of the matched submatrix must be the same, there is no match. Hence, we return [-1,-1].
    """


Prompt:
from typing import List
def sumOfEncryptedInt(nums: List[int]) -> int:
    """
    You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333.
    Return the sum of encrypted elements.

    Example 1:

    >>> sumOfEncryptedInt(nums = [1,2,3])
    >>> 6
    Explanation: The encrypted elements are [1,2,3]. The sum of encrypted elements is 1 + 2 + 3 == 6.

    Example 2:

    >>> sumOfEncryptedInt(nums = [10,21,31])
    >>> 66
    Explanation: The encrypted elements are [11,22,33]. The sum of encrypted elements is 11 + 22 + 33 == 66.
    """


Prompt:
from typing import List
def unmarkedSumArray(nums: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed array nums of size n consisting of positive integers.
    You are also given a 2D array queries of size m where queries[i] = [indexi, ki].
    Initially all elements of the array are unmarked.
    You need to apply m queries on the array in order, where on the ith query you do the following:

    Mark the element at index indexi if it is not already marked.
    Then mark ki unmarked elements in the array with the smallest values. If multiple such elements exist, mark the ones with the smallest indices. And if less than ki unmarked elements exist, then mark all of them.

    Return an array answer of size m where answer[i] is the sum of unmarked elements in the array after the ith query.

    Example 1:

    >>> unmarkedSumArray(nums = [1,2,2,1,2,3,1], queries = [[1,2],[3,3],[4,2]])
    >>> [8,3,0]
    Explanation:
    We do the following queries on the array:

    Mark the element at index 1, and 2 of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 2 + 2 + 3 + 1 = 8.
    Mark the element at index 3, since it is already marked we skip it. Then we mark 3 of the smallest unmarked elements with the smallest indices, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 3.
    Mark the element at index 4, since it is already marked we skip it. Then we mark 2 of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 0.

    Example 2:

    >>> unmarkedSumArray(nums = [1,4,2,3], queries = [[0,1]])
    >>> [7]
    Explanation:  We do one query which is mark the element at index 0 and mark the smallest element among unmarked elements. The marked elements will be nums = [1,4,2,3], and the sum of unmarked elements is 4 + 3 = 7.
    """


Prompt:
def minimizeStringValue(s: str) -> str:
    """
    You are given a string s. s[i] is either a lowercase English letter or '?'.
    For a string t having length m containing only lowercase English letters, we define the function cost(i) for an index i as the number of characters equal to t[i] that appeared before it, i.e. in the range [0, i - 1].
    The value of t is the sum of cost(i) for all indices i.
    For example, for the string t = "aab":

    cost(0) = 0
    cost(1) = 1
    cost(2) = 0
    Hence, the value of "aab" is 0 + 1 + 0 = 1.

    Your task is to replace all occurrences of '?' in s with any lowercase English letter so that the value of s is minimized.
    Return a string denoting the modified string with replaced occurrences of '?'. If there are multiple strings resulting in the minimum value, return the lexicographically smallest one.

    Example 1:

    >>> minimizeStringValue(s = "???")
    >>> "abc"
    Explanation:  In this example, we can replace the occurrences of '?' to make s equal to "abc".
    For "abc", cost(0) = 0, cost(1) = 0, and cost(2) = 0.
    The value of "abc" is 0.
    Some other modifications of s that have a value of 0 are "cba", "abz", and, "hey".
    Among all of them, we choose the lexicographically smallest.

    Example 2:

    >>> minimizeStringValue(s = "a?a?")
    >>> "abac"
    Explanation:  In this example, the occurrences of '?' can be replaced to make s equal to "abac".
    For "abac", cost(0) = 0, cost(1) = 0, cost(2) = 1, and cost(3) = 0.
    The value of "abac" is 1.
    """


Prompt:
from typing import List
def sumOfPower(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums of length n and a positive integer k.
    The power of an array of integers is defined as the number of subsequences with their sum equal to k.
    Return the sum of power of all subsequences of nums.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> sumOfPower(nums = [1,2,3], k = 3)
    >>> 6
    Explanation:
    There are 5 subsequences of nums with non-zero power:

    The subsequence [1,2,3] has 2 subsequences with sum == 3: [1,2,3] and [1,2,3].
    The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].
    The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].
    The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].
    The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].

    Hence the answer is 2 + 1 + 1 + 1 + 1 = 6.

    Example 2:

    >>> sumOfPower(nums = [2,3,3], k = 5)
    >>> 4
    Explanation:
    There are 3 subsequences of nums with non-zero power:

    The subsequence [2,3,3] has 2 subsequences with sum == 5: [2,3,3] and [2,3,3].
    The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].
    The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].

    Hence the answer is 2 + 1 + 1 = 4.

    Example 3:

    >>> sumOfPower(nums = [1,2,3], k = 7)
    >>> 0
    Explanation: There exists no subsequence with sum 7. Hence all subsequences of nums have power = 0.
    """


Prompt:
def isSubstringPresent(s: str) -> bool:
    """
    Given a string s, find any substring of length 2 which is also present in the reverse of s.
    Return true if such a substring exists, and false otherwise.

    Example 1:

    >>> isSubstringPresent(s = "leetcode")
    >>> true
    Explanation: Substring "ee" is of length 2 which is also present in reverse(s) == "edocteel".

    Example 2:

    >>> isSubstringPresent(s = "abcba")
    >>> true
    Explanation: All of the substrings of length 2 "ab", "bc", "cb", "ba" are also present in reverse(s) == "abcba".

    Example 3:

    >>> isSubstringPresent(s = "abcd")
    >>> false
    Explanation: There is no substring of length 2 in s, which is also present in the reverse of s.
    """


Prompt:
def countSubstrings(s: str, c: str) -> int:
    """
    You are given a string s and a character c. Return the total number of substrings of s that start and end with c.

    Example 1:

    >>> countSubstrings(s = "abada", c = "a")
    >>> 6
    Explanation: Substrings starting and ending with "a" are: "abada", "abada", "abada", "abada", "abada", "abada".

    Example 2:

    >>> countSubstrings(s = "zzz", c = "z")
    >>> 6
    Explanation: There are a total of 6 substrings in s and all start and end with "z".
    """


Prompt:
def minimumDeletions(word: str, k: int) -> int:
    """
    You are given a string word and an integer k.
    We consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the string.
    Here, freq(x) denotes the frequency of the character x in word, and |y| denotes the absolute value of y.
    Return the minimum number of characters you need to delete to make word k-special.

    Example 1:

    >>> minimumDeletions(word = "aabcaba", k = 0)
    >>> 3
    Explanation: We can make word 0-special by deleting 2 occurrences of "a" and 1 occurrence of "c". Therefore, word becomes equal to "baba" where freq('a') == freq('b') == 2.

    Example 2:

    >>> minimumDeletions(word = "dabdcbdcdcd", k = 2)
    >>> 2
    Explanation: We can make word 2-special by deleting 1 occurrence of "a" and 1 occurrence of "d". Therefore, word becomes equal to "bdcbdcdcd" where freq('b') == 2, freq('c') == 3, and freq('d') == 4.

    Example 3:

    >>> minimumDeletions(word = "aaabaaa", k = 2)
    >>> 1
    Explanation: We can make word 2-special by deleting 1 occurrence of "b". Therefore, word becomes equal to "aaaaaa" where each letter's frequency is now uniformly 6.
    """


Prompt:
from typing import List
def minimumMoves(nums: List[int], k: int, maxChanges: int) -> int:
    """
    You are given a binary array nums of length n, a positive integer k and a non-negative integer maxChanges.
    Alice plays a game, where the goal is for Alice to pick up k ones from nums using the minimum number of moves. When the game starts, Alice picks up any index aliceIndex in the range [0, n - 1] and stands there. If nums[aliceIndex] == 1 , Alice picks up the one and nums[aliceIndex] becomes 0(this does not count as a move). After this, Alice can make any number of moves (including zero) where in each move Alice must perform exactly one of the following actions:

    Select any index j != aliceIndex such that nums[j] == 0 and set nums[j] = 1. This action can be performed at most maxChanges times.
    Select any two adjacent indices x and y (|x - y| == 1) such that nums[x] == 1, nums[y] == 0, then swap their values (set nums[y] = 1 and nums[x] = 0). If y == aliceIndex, Alice picks up the one after this move and nums[y] becomes 0.

    Return the minimum number of moves required by Alice to pick exactly k ones.

    Example 1:

    >>> minimumMoves(nums = [1,1,0,0,0,1,1,0,0,1], k = 3, maxChanges = 1)
    >>> 3
    Explanation: Alice can pick up 3 ones in 3 moves, if Alice performs the following actions in each move when standing at aliceIndex == 1:

    At the start of the game Alice picks up the one and nums[1] becomes 0. nums becomes [1,0,0,0,0,1,1,0,0,1].
    Select j == 2 and perform an action of the first type. nums becomes [1,0,1,0,0,1,1,0,0,1]
    Select x == 2 and y == 1, and perform an action of the second type. nums becomes [1,1,0,0,0,1,1,0,0,1]. As y == aliceIndex, Alice picks up the one and nums becomes [1,0,0,0,0,1,1,0,0,1].
    Select x == 0 and y == 1, and perform an action of the second type. nums becomes [0,1,0,0,0,1,1,0,0,1]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0,0,1,1,0,0,1].

    Note that it may be possible for Alice to pick up 3 ones using some other sequence of 3 moves.

    Example 2:

    >>> minimumMoves(nums = [0,0,0,0], k = 2, maxChanges = 3)
    >>> 4
    Explanation: Alice can pick up 2 ones in 4 moves, if Alice performs the following actions in each move when standing at aliceIndex == 0:

    Select j == 1 and perform an action of the first type. nums becomes [0,1,0,0].
    Select x == 1 and y == 0, and perform an action of the second type. nums becomes [1,0,0,0]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0].
    Select j == 1 again and perform an action of the first type. nums becomes [0,1,0,0].
    Select x == 1 and y == 0 again, and perform an action of the second type. nums becomes [1,0,0,0]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0].
    """


Prompt:
def makeAntiPalindrome(s: str) -> str:
    """
    We call a string s of even length n an anti-palindrome if for each index 0 <= i < n, s[i] != s[n - i - 1].
    Given a string s, your task is to make s an anti-palindrome by doing any number of operations (including zero).
    In one operation, you can select two characters from s and swap them.
    Return the resulting string. If multiple strings meet the conditions, return the lexicographically smallest one. If it can't be made into an anti-palindrome, return "-1".

    Example 1:

    >>> makeAntiPalindrome(s = "abca")
    >>> "aabc"
    Explanation:
    "aabc" is an anti-palindrome string since s[0] != s[3] and s[1] != s[2]. Also, it is a rearrangement of "abca".

    Example 2:

    >>> makeAntiPalindrome(s = "abba")
    >>> "aabb"
    Explanation:
    "aabb" is an anti-palindrome string since s[0] != s[3] and s[1] != s[2]. Also, it is a rearrangement of "abba".

    Example 3:

    >>> makeAntiPalindrome(s = "cccd")
    >>> "-1"
    Explanation:
    You can see that no matter how you rearrange the characters of "cccd", either s[0] == s[3] or s[1] == s[2]. So it can not form an anti-palindrome string.
    """


Prompt:
def maximumLengthSubstring(s: str) -> int:
    """
    Given a string s, return the maximum length of a substring such that it contains at most two occurrences of each character.

    Example 1:

    >>> maximumLengthSubstring(s = "bcbbbcba")
    >>> 4
    Explanation:
    The following substring has a length of 4 and contains at most two occurrences of each character: "bcbbbcba".
    Example 2:

    >>> maximumLengthSubstring(s = "aaaa")
    >>> 2
    Explanation:
    The following substring has a length of 2 and contains at most two occurrences of each character: "aaaa".
    """


Prompt:
def minOperations(k: int) -> int:
    """
    You are given a positive integer k. Initially, you have an array nums = [1].
    You can perform any of the following operations on the array any number of times (possibly zero):

    Choose any element in the array and increase its value by 1.
    Duplicate any element in the array and add it to the end of the array.

    Return the minimum number of operations required to make the sum of elements of the final array greater than or equal to k.

    Example 1:

    >>> minOperations(k = 11)
    >>> 5
    Explanation:
    We can do the following operations on the array nums = [1]:

    Increase the element by 1 three times. The resulting array is nums = [4].
    Duplicate the element two times. The resulting array is nums = [4,4,4].

    The sum of the final array is 4 + 4 + 4 = 12 which is greater than or equal to k = 11.
    The total number of operations performed is 3 + 2 = 5.

    Example 2:

    >>> minOperations(k = 1)
    >>> 0
    Explanation:
    The sum of the original array is already greater than or equal to 1, so no operations are needed.
    """


Prompt:
from typing import List
def mostFrequentIDs(nums: List[int], freq: List[int]) -> List[int]:
    """
    The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, nums and freq, of equal length n. Each element in nums represents an ID, and the corresponding element in freq indicates how many times that ID should be added to or removed from the collection at each step.

    Addition of IDs: If freq[i] is positive, it means freq[i] IDs with the value nums[i] are added to the collection at step i.
    Removal of IDs: If freq[i] is negative, it means -freq[i] IDs with the value nums[i] are removed from the collection at step i.

    Return an array ans of length n, where ans[i] represents the count of the most frequent ID in the collection after the ith step. If the collection is empty at any step, ans[i] should be 0 for that step.

    Example 1:

    >>> mostFrequentIDs(nums = [2,3,2,1], freq = [3,2,-3,1])
    >>> [3,3,2,2]
    Explanation:
    After step 0, we have 3 IDs with the value of 2. So ans[0] = 3.
    After step 1, we have 3 IDs with the value of 2 and 2 IDs with the value of 3. So ans[1] = 3.
    After step 2, we have 2 IDs with the value of 3. So ans[2] = 2.
    After step 3, we have 2 IDs with the value of 3 and 1 ID with the value of 1. So ans[3] = 2.

    Example 2:

    >>> mostFrequentIDs(nums = [5,5,3], freq = [2,-2,1])
    >>> [2,0,1]
    Explanation:
    After step 0, we have 2 IDs with the value of 5. So ans[0] = 2.
    After step 1, there are no IDs. So ans[1] = 0.
    After step 2, we have 1 ID with the value of 3. So ans[2] = 1.
    """


Prompt:
from typing import List
def stringIndices(wordsContainer: List[str], wordsQuery: List[str]) -> List[int]:
    """
    You are given two arrays of strings wordsContainer and wordsQuery.
    For each wordsQuery[i], you need to find a string from wordsContainer that has the longest common suffix with wordsQuery[i]. If there are two or more strings in wordsContainer that share the longest common suffix, find the string that is the smallest in length. If there are two or more such strings that have the same smallest length, find the one that occurred earlier in wordsContainer.
    Return an array of integers ans, where ans[i] is the index of the string in wordsContainer that has the longest common suffix with wordsQuery[i].

    Example 1:

    >>> stringIndices(wordsContainer = ["abcd","bcd","xbcd"], wordsQuery = ["cd","bcd","xyz"])
    >>> [1,1,1]
    Explanation:
    Let's look at each wordsQuery[i] separately:

    For wordsQuery[0] = "cd", strings from wordsContainer that share the longest common suffix "cd" are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.
    For wordsQuery[1] = "bcd", strings from wordsContainer that share the longest common suffix "bcd" are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.
    For wordsQuery[2] = "xyz", there is no string from wordsContainer that shares a common suffix. Hence the longest common suffix is "", that is shared with strings at index 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.

    Example 2:

    >>> stringIndices(wordsContainer = ["abcdefgh","poiuygh","ghghgh"], wordsQuery = ["gh","acbfgh","acbfegh"])
    >>> [2,0,2]
    Explanation:
    Let's look at each wordsQuery[i] separately:

    For wordsQuery[0] = "gh", strings from wordsContainer that share the longest common suffix "gh" are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.
    For wordsQuery[1] = "acbfgh", only the string at index 0 shares the longest common suffix "fgh". Hence it is the answer, even though the string at index 2 is shorter.
    For wordsQuery[2] = "acbfegh", strings from wordsContainer that share the longest common suffix "gh" are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.
    """


Prompt:
from typing import List
def minimumSubarrayLength(nums: List[int], k: int) -> int:
    """
    You are given an array nums of non-negative integers and an integer k.
    An array is called special if the bitwise OR of all of its elements is at least k.
    Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.

    Example 1:

    >>> minimumSubarrayLength(nums = [1,2,3], k = 2)
    >>> 1
    Explanation:
    The subarray [3] has OR value of 3. Hence, we return 1.
    Note that [2] is also a special subarray.

    Example 2:

    >>> minimumSubarrayLength(nums = [2,1,8], k = 10)
    >>> 3
    Explanation:
    The subarray [2,1,8] has OR value of 11. Hence, we return 3.

    Example 3:

    >>> minimumSubarrayLength(nums = [1,2], k = 0)
    >>> 1
    Explanation:
    The subarray [1] has OR value of 1. Hence, we return 1.
    """


Prompt:
from typing import List
def minimumLevels(possible: List[int]) -> int:
    """
    You are given a binary array possible of length n.
    Alice and Bob are playing a game that consists of n levels. Some of the levels in the game are impossible to clear while others can always be cleared. In particular, if possible[i] == 0, then the ith level is impossible to clear for both the players. A player gains 1 point on clearing a level and loses 1 point if the player fails to clear it.
    At the start of the game, Alice will play some levels in the given order starting from the 0th level, after which Bob will play for the rest of the levels.
    Alice wants to know the minimum number of levels she should play to gain more points than Bob, if both players play optimally to maximize their points.
    Return the minimum number of levels Alice should play to gain more points. If this is not possible, return -1.
    Note that each player must play at least 1 level.

    Example 1:

    >>> minimumLevels(possible = [1,0,1,0])
    >>> 1
    Explanation:
    Let's look at all the levels that Alice can play up to:

    If Alice plays only level 0 and Bob plays the rest of the levels, Alice has 1 point, while Bob has -1 + 1 - 1 = -1 point.
    If Alice plays till level 1 and Bob plays the rest of the levels, Alice has 1 - 1 = 0 points, while Bob has 1 - 1 = 0 points.
    If Alice plays till level 2 and Bob plays the rest of the levels, Alice has 1 - 1 + 1 = 1 point, while Bob has -1 point.

    Alice must play a minimum of 1 level to gain more points.

    Example 2:

    >>> minimumLevels(possible = [1,1,1,1,1])
    >>> 3
    Explanation:
    Let's look at all the levels that Alice can play up to:

    If Alice plays only level 0 and Bob plays the rest of the levels, Alice has 1 point, while Bob has 4 points.
    If Alice plays till level 1 and Bob plays the rest of the levels, Alice has 2 points, while Bob has 3 points.
    If Alice plays till level 2 and Bob plays the rest of the levels, Alice has 3 points, while Bob has 2 points.
    If Alice plays till level 3 and Bob plays the rest of the levels, Alice has 4 points, while Bob has 1 point.

    Alice must play a minimum of 3 levels to gain more points.

    Example 3:

    >>> minimumLevels(possible = [0,0])
    >>> -1
    Explanation:
    The only possible way is for both players to play 1 level each. Alice plays level 0 and loses 1 point. Bob plays level 1 and loses 1 point. As both players have equal points, Alice can't gain more points than Bob.
    """


Prompt:
from typing import List
def minimumSubarrayLength(nums: List[int], k: int) -> int:
    """
    You are given an array nums of non-negative integers and an integer k.
    An array is called special if the bitwise OR of all of its elements is at least k.
    Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.

    Example 1:

    >>> minimumSubarrayLength(nums = [1,2,3], k = 2)
    >>> 1
    Explanation:
    The subarray [3] has OR value of 3. Hence, we return 1.

    Example 2:

    >>> minimumSubarrayLength(nums = [2,1,8], k = 10)
    >>> 3
    Explanation:
    The subarray [2,1,8] has OR value of 11. Hence, we return 3.

    Example 3:

    >>> minimumSubarrayLength(nums = [1,2], k = 0)
    >>> 1
    Explanation:
    The subarray [1] has OR value of 1. Hence, we return 1.
    """


Prompt:
from typing import List
def sumOfPowers(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums of length n, and a positive integer k.
    The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence.
    Return the sum of powers of all subsequences of nums which have length equal to k.
    Since the answer may be large, return it modulo 109 + 7.

    Example 1:

    >>> sumOfPowers(nums = [1,2,3,4], k = 3)
    >>> 4
    Explanation:
    There are 4 subsequences in nums which have length 3: [1,2,3], [1,3,4], [1,2,4], and [2,3,4]. The sum of powers is |2 - 3| + |3 - 4| + |2 - 1| + |3 - 4| = 4.

    Example 2:

    >>> sumOfPowers(nums = [2,2], k = 2)
    >>> 0
    Explanation:
    The only subsequence in nums which has length 2 is [2,2]. The sum of powers is |2 - 2| = 0.

    Example 3:

    >>> sumOfPowers(nums = [4,3,-1], k = 2)
    >>> 10
    Explanation:
    There are 3 subsequences in nums which have length 2: [4,3], [4,-1], and [3,-1]. The sum of powers is |4 - 3| + |4 - (-1)| + |3 - (-1)| = 10.
    """


Prompt:
def sumOfTheDigitsOfHarshadNumber(x: int) -> int:
    """
    An integer divisible by the sum of its digits is said to be a Harshad number. You are given an integer x. Return the sum of the digits of x if x is a Harshad number, otherwise, return -1.

    Example 1:

    >>> sumOfTheDigitsOfHarshadNumber(x = 18)
    >>> 9
    Explanation:
    The sum of digits of x is 9. 18 is divisible by 9. So 18 is a Harshad number and the answer is 9.

    Example 2:

    >>> sumOfTheDigitsOfHarshadNumber(x = 23)
    >>> -1
    Explanation:
    The sum of digits of x is 5. 23 is not divisible by 5. So 23 is not a Harshad number and the answer is -1.
    """


Prompt:
def maxBottlesDrunk(numBottles: int, numExchange: int) -> int:
    """
    You are given two integers numBottles and numExchange.
    numBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations:

    Drink any number of full water bottles turning them into empty bottles.
    Exchange numExchange empty bottles with one full water bottle. Then, increase numExchange by one.

    Note that you cannot exchange multiple batches of empty bottles for the same value of numExchange. For example, if numBottles == 3 and numExchange == 1, you cannot exchange 3 empty water bottles for 3 full bottles.
    Return the maximum number of water bottles you can drink.

    Example 1:

    >>> maxBottlesDrunk(numBottles = 13, numExchange = 6)
    >>> 15
    Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.

    Example 2:

    >>> maxBottlesDrunk(numBottles = 10, numExchange = 3)
    >>> 13
    Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.
    """


Prompt:
from typing import List
def countAlternatingSubarrays(nums: List[int]) -> int:
    """
    You are given a binary array nums.
    We call a subarray alternating if no two adjacent elements in the subarray have the same value.
    Return the number of alternating subarrays in nums.

    Example 1:

    >>> countAlternatingSubarrays(nums = [0,1,1,1])
    >>> 5
    Explanation:
    The following subarrays are alternating: [0], [1], [1], [1], and [0,1].

    Example 2:

    >>> countAlternatingSubarrays(nums = [1,0,1,0])
    >>> 10
    Explanation:
    Every subarray of the array is alternating. There are 10 possible subarrays that we can choose.
    """


Prompt:
from typing import List
def minimumDistance(points: List[List[int]]) -> int:
    """
    You are given an array points representing integer coordinates of some points on a 2D plane, where points[i] = [xi, yi].
    The distance between two points is defined as their Manhattan distance.
    Return the minimum possible value for maximum distance between any two points by removing exactly one point.

    Example 1:

    >>> minimumDistance(points = [[3,10],[5,15],[10,2],[4,4]])
    >>> 12
    Explanation:
    The maximum distance after removing each point is the following:

    After removing the 0th point the maximum distance is between points (5, 15) and (10, 2), which is |5 - 10| + |15 - 2| = 18.
    After removing the 1st point the maximum distance is between points (3, 10) and (10, 2), which is |3 - 10| + |10 - 2| = 15.
    After removing the 2nd point the maximum distance is between points (5, 15) and (4, 4), which is |5 - 4| + |15 - 4| = 12.
    After removing the 3rd point the maximum distance is between points (5, 15) and (10, 2), which is |5 - 10| + |15 - 2| = 18.

    12 is the minimum possible maximum distance between any two points after removing exactly one point.

    Example 2:

    >>> minimumDistance(points = [[1,1],[1,1],[1,1]])
    >>> 0
    Explanation:
    Removing any of the points results in the maximum distance between any two points of 0.
    """


Prompt:
def maxSubstringLength(s: str) -> int:
    """
    Given a string s, your task is to find the length of the longest self-contained substring of s.
    A substring t of a string s is called self-contained if t != s and for every character in t, it doesn't exist in the rest of s.
    Return the length of the longest self-contained substring of s if it exists, otherwise, return -1.

    Example 1:

    >>> maxSubstringLength(s = "abba")
    >>> 2
    Explanation:
    Let's check the substring "bb". You can see that no other "b" is outside of this substring. Hence the answer is 2.

    Example 2:

    >>> maxSubstringLength(s = "abab")
    >>> -1
    Explanation:
    Every substring we choose does not satisfy the described property (there is some character which is inside and outside of that substring). So the answer would be -1.

    Example 3:

    >>> maxSubstringLength(s = "abacd")
    >>> 4
    Explanation:
    Let's check the substring "abac". There is only one character outside of this substring and that is "d". There is no "d" inside the chosen substring, so it satisfies the condition and the answer is 4.
    """


Prompt:
from typing import List
def longestMonotonicSubarray(nums: List[int]) -> int:
    """
    You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing.

    Example 1:

    >>> longestMonotonicSubarray(nums = [1,4,3,3,2])
    >>> 2
    Explanation:
    The strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4].
    The strictly decreasing subarrays of nums are [1], [2], [3], [3], [4], [3,2], and [4,3].
    Hence, we return 2.

    Example 2:

    >>> longestMonotonicSubarray(nums = [3,3,3,3])
    >>> 1
    Explanation:
    The strictly increasing subarrays of nums are [3], [3], [3], and [3].
    The strictly decreasing subarrays of nums are [3], [3], [3], and [3].
    Hence, we return 1.

    Example 3:

    >>> longestMonotonicSubarray(nums = [3,2,1])
    >>> 3
    Explanation:
    The strictly increasing subarrays of nums are [3], [2], and [1].
    The strictly decreasing subarrays of nums are [3], [2], [1], [3,2], [2,1], and [3,2,1].
    Hence, we return 3.
    """


Prompt:
def getSmallestString(s: str, k: int) -> str:
    """
    You are given a string s and an integer k.
    Define a function distance(s1, s2) between two strings s1 and s2 of the same length n as:

    The sum of the minimum distance between s1[i] and s2[i] when the characters from 'a' to 'z' are placed in a cyclic order, for all i in the range [0, n - 1].

    For example, distance("ab", "cd") == 4, and distance("a", "z") == 1.
    You can change any letter of s to any other lowercase English letter, any number of times.
    Return a string denoting the lexicographically smallest string t you can get after some changes, such that distance(s, t) <= k.

    Example 1:

    >>> getSmallestString(s = "zbbz", k = 3)
    >>> "aaaz"
    Explanation:
    Change s to "aaaz". The distance between "zbbz" and "aaaz" is equal to k = 3.

    Example 2:

    >>> getSmallestString(s = "xaxcd", k = 4)
    >>> "aawcd"
    Explanation:
    The distance between "xaxcd" and "aawcd" is equal to k = 4.

    Example 3:

    >>> getSmallestString(s = "lol", k = 0)
    >>> "lol"
    Explanation:
    It's impossible to change any character as k = 0.
    """


Prompt:
from typing import List
def minOperationsToMakeMedianK(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1.
    Return the minimum number of operations needed to make the median of nums equal to k.
    The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.

    Example 1:

    >>> minOperationsToMakeMedianK(nums = [2,5,6,8,5], k = 4)
    >>> 2
    Explanation:
    We can subtract one from nums[1] and nums[4] to obtain [2, 4, 6, 8, 4]. The median of the resulting array is equal to k.

    Example 2:

    >>> minOperationsToMakeMedianK(nums = [2,5,6,8,5], k = 7)
    >>> 3
    Explanation:
    We can add one to nums[1] twice and add one to nums[2] once to obtain [2, 7, 7, 8, 5].

    Example 3:

    >>> minOperationsToMakeMedianK(nums = [1,2,3,4,5,6], k = 4)
    >>> 0
    Explanation:
    The median of the array is already equal to k.
    """


Prompt:
from typing import List
def minimumCost(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]:
    """
    There is an undirected weighted graph with n vertices labeled from 0 to n - 1.
    You are given the integer n and an array edges, where edges[i] = [ui, vi, wi] indicates that there is an edge between vertices ui and vi with a weight of wi.
    A walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that comes before it and the vertex that comes after it. It's important to note that a walk may visit the same edge or vertex more than once.
    The cost of a walk starting at node u and ending at node v is defined as the bitwise AND of the weights of the edges traversed during the walk. In other words, if the sequence of edge weights encountered during the walk is w0, w1, w2, ..., wk, then the cost is calculated as w0 & w1 & w2 & ... & wk, where & denotes the bitwise AND operator.
    You are also given a 2D array query, where query[i] = [si, ti]. For each query, you need to find the minimum cost of the walk starting at vertex si and ending at vertex ti. If there exists no such walk, the answer is -1.
    Return the array answer, where answer[i] denotes the minimum cost of a walk for query i.

    Example 1:

    >>> minimumCost(n = 5, edges = [[0,1,7],[1,3,7],[1,2,1]], query = [[0,3],[3,4]])
    >>> [1,-1]
    Explanation:

    To achieve the cost of 1 in the first query, we need to move on the following edges: 0->1 (weight 7), 1->2 (weight 1), 2->1 (weight 1), 1->3 (weight 7).
    In the second query, there is no walk between nodes 3 and 4, so the answer is -1.
    Example 2:

    >>> minimumCost(n = 3, edges = [[0,2,7],[0,1,15],[1,2,6],[1,2,1]], query = [[1,2]])
    >>> [0]
    Explanation:

    To achieve the cost of 0 in the first query, we need to move on the following edges: 1->2 (weight 1), 2->1 (weight 6), 1->2 (weight 1).
    """


Prompt:
from typing import List
def getPermutationIndex(perm: List[int]) -> int:
    """
    Given an array perm of length n which is a permutation of [1, 2, ..., n], return the index of perm in the lexicographically sorted array of all of the permutations of [1, 2, ..., n].
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> getPermutationIndex(perm = [1,2])
    >>> 0
    Explanation:
    There are only two permutations in the following order:
    [1,2], [2,1]

    And [1,2] is at index 0.

    Example 2:

    >>> getPermutationIndex(perm = [3,1,2])
    >>> 4
    Explanation:
    There are only six permutations in the following order:
    [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]

    And [3,1,2] is at index 4.
    """


Prompt:
def scoreOfString(s: str) -> int:
    """
    You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.
    Return the score of s.

    Example 1:

    >>> scoreOfString(s = "hello")
    >>> 13
    Explanation:
    The ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, the score of s would be |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13.

    Example 2:

    >>> scoreOfString(s = "zaz")
    >>> 50
    Explanation:
    The ASCII values of the characters in s are: 'z' = 122, 'a' = 97. So, the score of s would be |122 - 97| + |97 - 122| = 25 + 25 = 50.
    """


Prompt:
from typing import List
def minRectanglesToCoverPoints(points: List[List[int]], w: int) -> int:
    """
    You are given a 2D integer array points, where points[i] = [xi, yi]. You are also given an integer w. Your task is to cover all the given points with rectangles.
    Each rectangle has its lower end at some point (x1, 0) and its upper end at some point (x2, y2), where x1 <= x2, y2 >= 0, and the condition x2 - x1 <= w must be satisfied for each rectangle.
    A point is considered covered by a rectangle if it lies within or on the boundary of the rectangle.
    Return an integer denoting the minimum number of rectangles needed so that each point is covered by at least one rectangle.
    Note: A point may be covered by more than one rectangle.

    Example 1:

    >>> minRectanglesToCoverPoints(points = [[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]], w = 1)
    >>> 2
    Explanation:
    The image above shows one possible placement of rectangles to cover the points:

    A rectangle with a lower end at (1, 0) and its upper end at (2, 8)
    A rectangle with a lower end at (3, 0) and its upper end at (4, 8)

    Example 2:

    >>> minRectanglesToCoverPoints(points = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]], w = 2)
    >>> 3
    Explanation:
    The image above shows one possible placement of rectangles to cover the points:

    A rectangle with a lower end at (0, 0) and its upper end at (2, 2)
    A rectangle with a lower end at (3, 0) and its upper end at (5, 5)
    A rectangle with a lower end at (6, 0) and its upper end at (6, 6)

    Example 3:

    >>> minRectanglesToCoverPoints(points = [[2,3],[1,2]], w = 0)
    >>> 2
    Explanation:
    The image above shows one possible placement of rectangles to cover the points:

    A rectangle with a lower end at (1, 0) and its upper end at (1, 2)
    A rectangle with a lower end at (2, 0) and its upper end at (2, 3)
    """


Prompt:
from typing import List
def minimumTime(n: int, edges: List[List[int]], disappear: List[int]) -> List[int]:
    """
    There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [ui, vi, lengthi] describes an edge between node ui and node vi with a traversal time of lengthi units.
    Additionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the graph and you won't be able to visit it.
    Note that the graph might be disconnected and might contain multiple edges.
    Return the array answer, with answer[i] denoting the minimum units of time required to reach node i from node 0. If node i is unreachable from node 0 then answer[i] is -1.

    Example 1:

    >>> minimumTime(n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5])
    >>> [0,-1,4]
    Explanation:

    We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.

    For node 0, we don't need any time as it is our starting point.
    For node 1, we need at least 2 units of time to traverse edges[0]. Unfortunately, it disappears at that moment, so we won't be able to visit it.
    For node 2, we need at least 4 units of time to traverse edges[2].

    Example 2:

    >>> minimumTime(n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5])
    >>> [0,2,3]
    Explanation:

    We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.

    For node 0, we don't need any time as it is the starting point.
    For node 1, we need at least 2 units of time to traverse edges[0].
    For node 2, we need at least 3 units of time to traverse edges[0] and edges[1].

    Example 3:

    >>> minimumTime(n = 2, edges = [[0,1,1]], disappear = [1,1])
    >>> [0,-1]
    Explanation:
    Exactly when we reach node 1, it disappears.
    """


Prompt:
from typing import List
def numberOfSubarrays(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums.
    Return the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray.

    Example 1:

    >>> numberOfSubarrays(nums = [1,4,3,3,2])
    >>> 6
    Explanation:
    There are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:

    subarray [1,4,3,3,2], with its largest element 1. The first element is 1 and the last element is also 1.
    subarray [1,4,3,3,2], with its largest element 4. The first element is 4 and the last element is also 4.
    subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [1,4,3,3,2], with its largest element 2. The first element is 2 and the last element is also 2.
    subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.

    Hence, we return 6.

    Example 2:

    >>> numberOfSubarrays(nums = [3,3,3])
    >>> 6
    Explanation:
    There are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:

    subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.
    subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.

    Hence, we return 6.

    Example 3:

    >>> numberOfSubarrays(nums = [1])
    >>> 1
    Explanation:
    There is a single subarray of nums which is [1], with its largest element 1. The first element is 1 and the last element is also 1.
    Hence, we return 1.
    """


Prompt:
def findLatestTime(s: str) -> str:
    """
    You are given a string s representing a 12-hour format time where some of the digits (possibly none) are replaced with a "?".
    12-hour times are formatted as "HH:MM", where HH is between 00 and 11, and MM is between 00 and 59. The earliest 12-hour time is 00:00, and the latest is 11:59.
    You have to replace all the "?" characters in s with digits such that the time we obtain by the resulting string is a valid 12-hour format time and is the latest possible.
    Return the resulting string.

    Example 1:

    >>> findLatestTime(s = "1?:?4")
    >>> "11:54"
    Explanation: The latest 12-hour format time we can achieve by replacing "?" characters is "11:54".

    Example 2:

    >>> findLatestTime(s = "0?:5?")
    >>> "09:59"
    Explanation: The latest 12-hour format time we can achieve by replacing "?" characters is "09:59".
    """


Prompt:
from typing import List
def maximumPrimeDifference(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums.

    Example 1:

    >>> maximumPrimeDifference(nums = [4,2,9,5,3])
    >>> 3
    Explanation: nums[1], nums[3], and nums[4] are prime. So the answer is |4 - 1| = 3.

    Example 2:

    >>> maximumPrimeDifference(nums = [4,8,2,8])
    >>> 0
    Explanation: nums[2] is prime. Because there is just one prime number, the answer is |2 - 2| = 0.
    """


Prompt:
from typing import List
def findKthSmallest(coins: List[int], k: int) -> int:
    """
    You are given an integer array coins representing coins of different denominations and an integer k.
    You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations.
    Return the kth smallest amount that can be made using these coins.

    Example 1:

    >>> findKthSmallest(coins = [3,6,9], k = 3)
    >>> 9
    Explanation: The given coins can make the following amounts:
    Coin 3 produces multiples of 3: 3, 6, 9, 12, 15, etc.
    Coin 6 produces multiples of 6: 6, 12, 18, 24, etc.
    Coin 9 produces multiples of 9: 9, 18, 27, 36, etc.
    All of the coins combined produce: 3, 6, 9, 12, 15, etc.

    Example 2:

    >>> findKthSmallest(coins = [5,2], k = 7)
    >>> 12
    Explanation: The given coins can make the following amounts:
    Coin 5 produces multiples of 5: 5, 10, 15, 20, etc.
    Coin 2 produces multiples of 2: 2, 4, 6, 8, 10, 12, etc.
    All of the coins combined produce: 2, 4, 5, 6, 8, 10, 12, 14, 15, etc.
    """


Prompt:
from typing import List
def minimumValueSum(nums: List[int], andValues: List[int]) -> int:
    """
    You are given two arrays nums and andValues of length n and m respectively.
    The value of an array is equal to the last element of that array.
    You have to divide nums into m disjoint contiguous subarrays such that for the ith subarray [li, ri], the bitwise AND of the subarray elements is equal to andValues[i], in other words, nums[li] & nums[li + 1] & ... & nums[ri] == andValues[i] for all 1 <= i <= m, where & represents the bitwise AND operator.
    Return the minimum possible sum of the values of the m subarrays nums is divided into. If it is not possible to divide nums into m subarrays satisfying these conditions, return -1.

    Example 1:

    >>> minimumValueSum(nums = [1,4,3,3,2], andValues = [0,3,3,2])
    >>> 12
    Explanation:
    The only possible way to divide nums is:

    [1,4] as 1 & 4 == 0.
    [3] as the bitwise AND of a single element subarray is that element itself.
    [3] as the bitwise AND of a single element subarray is that element itself.
    [2] as the bitwise AND of a single element subarray is that element itself.

    The sum of the values for these subarrays is 4 + 3 + 3 + 2 = 12.

    Example 2:

    >>> minimumValueSum(nums = [2,3,5,7,7,7,5], andValues = [0,7,5])
    >>> 17
    Explanation:
    There are three ways to divide nums:

    [[2,3,5],[7,7,7],[5]] with the sum of the values 5 + 7 + 5 == 17.
    [[2,3,5,7],[7,7],[5]] with the sum of the values 7 + 7 + 5 == 19.
    [[2,3,5,7,7],[7],[5]] with the sum of the values 7 + 7 + 5 == 19.

    The minimum possible sum of the values is 17.

    Example 3:

    >>> minimumValueSum(nums = [1,2,3,4], andValues = [2])
    >>> -1
    Explanation:
    The bitwise AND of the entire array nums is 0. As there is no possible way to divide nums into a single subarray to have the bitwise AND of elements 2, return -1.
    """


Prompt:
def maxPotholes(road: str, budget: int) -> int:
    """
    You are given a string road, consisting only of characters "x" and ".", where each "x" denotes a pothole and each "." denotes a smooth road, and an integer budget.
    In one repair operation, you can repair n consecutive potholes for a price of n + 1.
    Return the maximum number of potholes that can be fixed such that the sum of the prices of all of the fixes doesn't go over the given budget.

    Example 1:

    >>> maxPotholes(road = "..", budget = 5)
    >>> 0
    Explanation:
    There are no potholes to be fixed.

    Example 2:

    >>> maxPotholes(road = "..xxxxx", budget = 4)
    >>> 3
    Explanation:
    We fix the first three potholes (they are consecutive). The budget needed for this task is 3 + 1 = 4.

    Example 3:

    >>> maxPotholes(road = "x.x.xxx...x", budget = 14)
    >>> 6
    Explanation:
    We can fix all the potholes. The total cost would be (1 + 1) + (1 + 1) + (3 + 1) + (1 + 1) = 10 which is within our budget of 14.
    """


Prompt:
def numberOfSpecialChars(word: str) -> int:
    """
    You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word.
    Return the number of special letters in word.

    Example 1:

    >>> numberOfSpecialChars(word = "aaAbcBC")
    >>> 3
    Explanation:
    The special characters in word are 'a', 'b', and 'c'.

    Example 2:

    >>> numberOfSpecialChars(word = "abc")
    >>> 0
    Explanation:
    No character in word appears in uppercase.

    Example 3:

    >>> numberOfSpecialChars(word = "abBCab")
    >>> 1
    Explanation:
    The only special character in word is 'b'.
    """


Prompt:
def numberOfSpecialChars(word: str) -> int:
    """
    You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c.
    Return the number of special letters in word.

    Example 1:

    >>> numberOfSpecialChars(word = "aaAbcBC")
    >>> 3
    Explanation:
    The special characters are 'a', 'b', and 'c'.

    Example 2:

    >>> numberOfSpecialChars(word = "abc")
    >>> 0
    Explanation:
    There are no special characters in word.

    Example 3:

    >>> numberOfSpecialChars(word = "AbBCab")
    >>> 0
    Explanation:
    There are no special characters in word.
    """


Prompt:
from typing import List
def minimumOperations(grid: List[List[int]]) -> int:
    """
    You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is:

    Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).
    Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).

    Return the minimum number of operations needed.

    Example 1:

    >>> minimumOperations(grid = [[1,0,2],[1,0,2]])
    >>> 0
    Explanation:

    All the cells in the matrix already satisfy the properties.

    Example 2:

    >>> minimumOperations(grid = [[1,1,1],[0,0,0]])
    >>> 3
    Explanation:

    The matrix becomes [[1,0,1],[1,0,1]] which satisfies the properties, by doing these 3 operations:

    Change grid[1][0] to 1.
    Change grid[0][1] to 0.
    Change grid[1][2] to 1.

    Example 3:

    >>> minimumOperations(grid = [[1],[2],[3]])
    >>> 2
    Explanation:

    There is a single column. We can change the value to 1 in each cell using 2 operations.
    """


Prompt:
from typing import List
def findAnswer(n: int, edges: List[List[int]]) -> List[bool]:
    """
    You are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D array edges, where edges[i] = [ai, bi, wi] indicates that there is an edge between nodes ai and bi with weight wi.
    Consider all the shortest paths from node 0 to node n - 1 in the graph. You need to find a boolean array answer where answer[i] is true if the edge edges[i] is part of at least one shortest path. Otherwise, answer[i] is false.
    Return the array answer.
    Note that the graph may not be connected.

    Example 1:

    >>> findAnswer(n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]])
    >>> [true,true,true,false,true,true,true,false]
    Explanation:
    The following are all the shortest paths between nodes 0 and 5:

    The path 0 -> 1 -> 5: The sum of weights is 4 + 1 = 5.
    The path 0 -> 2 -> 3 -> 5: The sum of weights is 1 + 1 + 3 = 5.
    The path 0 -> 2 -> 3 -> 1 -> 5: The sum of weights is 1 + 1 + 2 + 1 = 5.

    Example 2:

    >>> findAnswer(n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]])
    >>> [true,false,false,true]
    Explanation:
    There is one shortest path between nodes 0 and 3, which is the path 0 -> 2 -> 3 with the sum of weights 1 + 2 = 3.
    """


Prompt:
def maxNumber(n: int) -> int:
    """
    Given an integer n, return the maximum integer x such that x <= n, and the bitwise AND of all the numbers in the range [x, n] is 0.

    Example 1:

    >>> maxNumber(n = 7)
    >>> 3
    Explanation:
    The bitwise AND of [6, 7] is 6.
    The bitwise AND of [5, 6, 7] is 4.
    The bitwise AND of [4, 5, 6, 7] is 4.
    The bitwise AND of [3, 4, 5, 6, 7] is 0.

    Example 2:

    >>> maxNumber(n = 9)
    >>> 7
    Explanation:
    The bitwise AND of [7, 8, 9] is 0.

    Example 3:

    >>> maxNumber(n = 17)
    >>> 15
    Explanation:
    The bitwise AND of [15, 16, 17] is 0.
    """


Prompt:
from typing import List
def canMakeSquare(grid: List[List[str]]) -> bool:
    """
    You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' represents the black color.
    Your task is to change the color of at most one cell so that the matrix has a 2 x 2 square where all cells are of the same color.
    Return true if it is possible to create a 2 x 2 square of the same color, otherwise, return false.

    Example 1:

    >>> canMakeSquare(grid = [["B","W","B"],["B","W","W"],["B","W","B"]])
    >>> true
    Explanation:
    It can be done by changing the color of the grid[0][2].

    Example 2:

    >>> canMakeSquare(grid = [["B","W","B"],["W","B","W"],["B","W","B"]])
    >>> false
    Explanation:
    It cannot be done by changing at most one cell.

    Example 3:

    >>> canMakeSquare(grid = [["B","W","B"],["B","W","W"],["B","W","W"]])
    >>> true
    Explanation:
    The grid already contains a 2 x 2 square of the same color.
    """


Prompt:
from typing import List
def numberOfRightTriangles(grid: List[List[int]]) -> int:
    """
    You are given a 2D boolean matrix grid.
    A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each other.
    Return an integer that is the number of right triangles that can be made with 3 elements of grid such that all of them have a value of 1.

    Example 1:

    0
    1
    0

    0
    1
    1

    0
    1
    0

    0
    1
    0

    0
    1
    1

    0
    1
    0

    0
    1
    0

    0
    1
    1

    0
    1
    0

    >>> numberOfRightTriangles(grid = [[0,1,0],[0,1,1],[0,1,0]])
    >>> 2
    Explanation:
    There are two right triangles with elements of the value 1. Notice that the blue ones do not form a right triangle because the 3 elements are in the same column.

    Example 2:

    1
    0
    0
    0

    0
    1
    0
    1

    1
    0
    0
    0

    >>> numberOfRightTriangles(grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]])
    >>> 0
    Explanation:
    There are no right triangles with elements of the value 1.  Notice that the blue ones do not form a right triangle.

    Example 3:

    1
    0
    1

    1
    0
    0

    1
    0
    0

    1
    0
    1

    1
    0
    0

    1
    0
    0

    >>> numberOfRightTriangles(grid = [[1,0,1],[1,0,0],[1,0,0]])
    >>> 2
    Explanation:
    There are two right triangles with elements of the value 1.
    """


Prompt:
def numberOfStableArrays(zero: int, one: int, limit: int) -> int:
    """
    You are given 3 positive integers zero, one, and limit.
    A binary array arr is called stable if:

    The number of occurrences of 0 in arr is exactly zero.
    The number of occurrences of 1 in arr is exactly one.
    Each subarray of arr with a size greater than limit must contain both 0 and 1.

    Return the total number of stable binary arrays.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfStableArrays(zero = 1, one = 1, limit = 2)
    >>> 2
    Explanation:
    The two possible stable binary arrays are [1,0] and [0,1], as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.

    Example 2:

    >>> numberOfStableArrays(zero = 1, one = 2, limit = 1)
    >>> 1
    Explanation:
    The only possible stable binary array is [1,0,1].
    Note that the binary arrays [1,1,0] and [0,1,1] have subarrays of length 2 with identical elements, hence, they are not stable.

    Example 3:

    >>> numberOfStableArrays(zero = 3, one = 3, limit = 2)
    >>> 14
    Explanation:
    All the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].
    """


Prompt:
def numberOfStableArrays(zero: int, one: int, limit: int) -> int:
    """
    You are given 3 positive integers zero, one, and limit.
    A binary array arr is called stable if:

    The number of occurrences of 0 in arr is exactly zero.
    The number of occurrences of 1 in arr is exactly one.
    Each subarray of arr with a size greater than limit must contain both 0 and 1.

    Return the total number of stable binary arrays.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfStableArrays(zero = 1, one = 1, limit = 2)
    >>> 2
    Explanation:
    The two possible stable binary arrays are [1,0] and [0,1].

    Example 2:

    >>> numberOfStableArrays(zero = 1, one = 2, limit = 1)
    >>> 1
    Explanation:
    The only possible stable binary array is [1,0,1].

    Example 3:

    >>> numberOfStableArrays(zero = 3, one = 3, limit = 2)
    >>> 14
    Explanation:
    All the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].
    """


Prompt:
from typing import List
def addedInteger(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two arrays of equal length, nums1 and nums2.
    Each element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x.
    As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.
    Return the integer x.

    Example 1:

    >>> addedInteger(nums1 = [2,6,4], nums2 = [9,7,5])
    >>> 3
    Explanation:
    The integer added to each element of nums1 is 3.

    Example 2:

    >>> addedInteger(nums1 = [10], nums2 = [5])
    >>> -5
    Explanation:
    The integer added to each element of nums1 is -5.

    Example 3:

    >>> addedInteger(nums1 = [1,1,1,1], nums2 = [1,1,1,1])
    >>> 0
    Explanation:
    The integer added to each element of nums1 is 0.
    """


Prompt:
from typing import List
def minimumAddedInteger(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two integer arrays nums1 and nums2.
    From nums1 two elements have been removed, and all other elements have been increased (or decreased in the case of negative) by an integer, represented by the variable x.
    As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.
    Return the minimum possible integer x that achieves this equivalence.

    Example 1:

    >>> minimumAddedInteger(nums1 = [4,20,16,12,8], nums2 = [14,18,10])
    >>> -2
    Explanation:
    After removing elements at indices [0,4] and adding -2, nums1 becomes [18,14,10].

    Example 2:

    >>> minimumAddedInteger(nums1 = [3,5,5,3], nums2 = [7,7])
    >>> 2
    Explanation:
    After removing elements at indices [0,3] and adding 2, nums1 becomes [7,7].
    """


Prompt:
def minEnd(n: int, x: int) -> int:
    """
    You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x.
    Return the minimum possible value of nums[n - 1].

    Example 1:

    >>> minEnd(n = 3, x = 4)
    >>> 6
    Explanation:
    nums can be [4,5,6] and its last element is 6.

    Example 2:

    >>> minEnd(n = 2, x = 7)
    >>> 15
    Explanation:
    nums can be [7,15] and its last element is 15.
    """


Prompt:
from typing import List
def medianOfUniquenessArray(nums: List[int]) -> int:
    """
    You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j < nums.length.
    Here, distinct(nums[i..j]) denotes the number of distinct elements in the subarray that starts at index i and ends at index j.
    Return the median of the uniqueness array of nums.
    Note that the median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the smaller of the two values is taken.

    Example 1:

    >>> medianOfUniquenessArray(nums = [1,2,3])
    >>> 1
    Explanation:
    The uniqueness array of nums is [distinct(nums[0..0]), distinct(nums[1..1]), distinct(nums[2..2]), distinct(nums[0..1]), distinct(nums[1..2]), distinct(nums[0..2])] which is equal to [1, 1, 1, 2, 2, 3]. The uniqueness array has a median of 1. Therefore, the answer is 1.

    Example 2:

    >>> medianOfUniquenessArray(nums = [3,4,3,4,5])
    >>> 2
    Explanation:
    The uniqueness array of nums is [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]. The uniqueness array has a median of 2. Therefore, the answer is 2.

    Example 3:

    >>> medianOfUniquenessArray(nums = [4,3,5,4])
    >>> 2
    Explanation:
    The uniqueness array of nums is [1, 1, 1, 1, 2, 2, 2, 3, 3, 3]. The uniqueness array has a median of 2. Therefore, the answer is 2.
    """


Prompt:
def minOperations(initial: str, target: str) -> int:
    """
    Given two strings initial and target, your task is to modify initial by performing a series of operations to make it equal to target.
    In one operation, you can add or remove one character only at the beginning or the end of the string initial.
    Return the minimum number of operations required to transform initial into target.

    Example 1:

    >>> minOperations(initial = "abcde", target = "cdef")
    >>> 3
    Explanation:
    Remove 'a' and 'b' from the beginning of initial, then add 'f' to the end.

    Example 2:

    >>> minOperations(initial = "axxy", target = "yabx")
    >>> 6
    Explanation:

    Operation
    Resulting String

    Add 'y' to the beginning
    "yaxxy"

    Remove from end
    "yaxx"

    Remove from end
    "yax"

    Remove from end
    "ya"

    Add 'b' to the end
    "yab"

    Add 'x' to the end
    "yabx"

    Example 3:

    >>> minOperations(initial = "xyz", target = "xyz")
    >>> 0
    Explanation:
    No operations are needed as the strings are already equal.
    """


Prompt:
def isValid(word: str) -> bool:
    """
    A word is considered valid if:

    It contains a minimum of 3 characters.
    It contains only digits (0-9), and English letters (uppercase and lowercase).
    It includes at least one vowel.
    It includes at least one consonant.

    You are given a string word.
    Return true if word is valid, otherwise, return false.
    Notes:

    'a', 'e', 'i', 'o', 'u', and their uppercases are vowels.
    A consonant is an English letter that is not a vowel.

    Example 1:

    >>> isValid(word = "234Adas")
    >>> true
    Explanation:
    This word satisfies the conditions.

    Example 2:

    >>> isValid(word = "b3")
    >>> false
    Explanation:
    The length of this word is fewer than 3, and does not have a vowel.

    Example 3:

    >>> isValid(word = "a3$e")
    >>> false
    Explanation:
    This word contains a '$' character and does not have a consonant.
    """


Prompt:
def minimumOperationsToMakeKPeriodic(word: str, k: int) -> int:
    """
    You are given a string word of size n, and an integer k such that k divides n.
    In one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of length k starting at j. That is, replace the substring word[i..i + k - 1] with the substring word[j..j + k - 1].
    Return the minimum number of operations required to make word k-periodic.
    We say that word is k-periodic if there is some string s of length k such that word can be obtained by concatenating s an arbitrary number of times. For example, if word == “ababab”, then word is 2-periodic for s = "ab".

    Example 1:

    >>> minimumOperationsToMakeKPeriodic(word = "leetcodeleet", k = 4)
    >>> 1
    Explanation:
    We can obtain a 4-periodic string by picking i = 4 and j = 0. After this operation, word becomes equal to "leetleetleet".

    Example 2:

    >>> minimumOperationsToMakeKPeriodic(word = "leetcoleet", k = 2)
    >>> 3
    Explanation:
    We can obtain a 2-periodic string by applying the operations in the table below.

    i
    j
    word

    0
    2
    etetcoleet

    4
    0
    etetetleet

    6
    0
    etetetetet
    """


Prompt:
def minAnagramLength(s: str) -> int:
    """
    You are given a string s, which is known to be a concatenation of anagrams of some string t.
    Return the minimum possible length of the string t.
    An anagram is formed by rearranging the letters of a string. For example, "aab", "aba", and, "baa" are anagrams of "aab".

    Example 1:

    >>> minAnagramLength(s = "abba")
    >>> 2
    Explanation:
    One possible string t could be "ba".

    Example 2:

    >>> minAnagramLength(s = "cdef")
    >>> 4
    Explanation:
    One possible string t could be "cdef", notice that t can be equal to s.

    Example 2:

    >>> minAnagramLength(s = "abcbcacabbaccba")
    >>> 3
    """


Prompt:
from typing import List
def minCostToEqualizeArray(nums: List[int], cost1: int, cost2: int) -> int:
    """
    You are given an integer array nums and two integers cost1 and cost2. You are allowed to perform either of the following operations any number of times:

    Choose an index i from nums and increase nums[i] by 1 for a cost of cost1.
    Choose two different indices i, j, from nums and increase nums[i] and nums[j] by 1 for a cost of cost2.

    Return the minimum cost required to make all elements in the array equal.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> minCostToEqualizeArray(nums = [4,1], cost1 = 5, cost2 = 2)
    >>> 15
    Explanation:
    The following operations can be performed to make the values equal:

    Increase nums[1] by 1 for a cost of 5. nums becomes [4,2].
    Increase nums[1] by 1 for a cost of 5. nums becomes [4,3].
    Increase nums[1] by 1 for a cost of 5. nums becomes [4,4].

    The total cost is 15.

    Example 2:

    >>> minCostToEqualizeArray(nums = [2,3,3,3,5], cost1 = 2, cost2 = 1)
    >>> 6
    Explanation:
    The following operations can be performed to make the values equal:

    Increase nums[0] and nums[1] by 1 for a cost of 1. nums becomes [3,4,3,3,5].
    Increase nums[0] and nums[2] by 1 for a cost of 1. nums becomes [4,4,4,3,5].
    Increase nums[0] and nums[3] by 1 for a cost of 1. nums becomes [5,4,4,4,5].
    Increase nums[1] and nums[2] by 1 for a cost of 1. nums becomes [5,5,5,4,5].
    Increase nums[3] by 1 for a cost of 2. nums becomes [5,5,5,5,5].

    The total cost is 6.

    Example 3:

    >>> minCostToEqualizeArray(nums = [3,5,3], cost1 = 1, cost2 = 3)
    >>> 4
    Explanation:
    The following operations can be performed to make the values equal:

    Increase nums[0] by 1 for a cost of 1. nums becomes [4,5,3].
    Increase nums[0] by 1 for a cost of 1. nums becomes [5,5,3].
    Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,4].
    Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,5].

    The total cost is 4.
    """


Prompt:
from typing import List
def maxHammingDistances(nums: List[int], m: int) -> List[int]:
    """
    Given an array nums and an integer m, with each element nums[i] satisfying 0 <= nums[i] < 2m, return an array answer. The answer array should be of the same length as nums, where each element answer[i] represents the maximum Hamming distance between nums[i] and any other element nums[j] in the array.
    The Hamming distance between two binary integers is defined as the number of positions at which the corresponding bits differ (add leading zeroes if needed).

    Example 1:

    >>> maxHammingDistances(nums = [9,12,9,11], m = 4)
    >>> [2,3,2,3]
    Explanation:
    The binary representation of nums = [1001,1100,1001,1011].
    The maximum hamming distances for each index are:

    nums[0]: 1001 and 1100 have a distance of 2.
    nums[1]: 1100 and 1011 have a distance of 3.
    nums[2]: 1001 and 1100 have a distance of 2.
    nums[3]: 1011 and 1100 have a distance of 3.

    Example 2:

    >>> maxHammingDistances(nums = [3,4,6,10], m = 4)
    >>> [3,3,2,3]
    Explanation:
    The binary representation of nums = [0011,0100,0110,1010].
    The maximum hamming distances for each index are:

    nums[0]: 0011 and 0100 have a distance of 3.
    nums[1]: 0100 and 0011 have a distance of 3.
    nums[2]: 0110 and 1010 have a distance of 2.
    nums[3]: 1010 and 0100 have a distance of 3.
    """


Prompt:
from typing import List
def satisfiesConditions(grid: List[List[int]]) -> bool:
    """
    You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is:

    Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).
    Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).

    Return true if all the cells satisfy these conditions, otherwise, return false.

    Example 1:

    >>> satisfiesConditions(grid = [[1,0,2],[1,0,2]])
    >>> true
    Explanation:

    All the cells in the grid satisfy the conditions.

    Example 2:

    >>> satisfiesConditions(grid = [[1,1,1],[0,0,0]])
    >>> false
    Explanation:

    All cells in the first row are equal.

    Example 3:

    >>> satisfiesConditions(grid = [[1],[2],[3]])
    >>> false
    Explanation:

    Cells in the first column have different values.
    """


Prompt:
from typing import List
def maxPointsInsideSquare(points: List[List[int]], s: str) -> int:
    """
    You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i.
    A valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and does not contain two points with the same tag.
    Return the maximum number of points contained in a valid square.
    Note:

    A point is considered to be inside the square if it lies on or within the square's boundaries.
    The side length of the square can be zero.

    Example 1:

    >>> maxPointsInsideSquare(points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = "abdca")
    >>> 2
    Explanation:
    The square of side length 4 covers two points points[0] and points[1].

    Example 2:

    >>> maxPointsInsideSquare(points = [[1,1],[-2,-2],[-2,2]], s = "abb")
    >>> 1
    Explanation:
    The square of side length 2 covers one point, which is points[0].

    Example 3:

    >>> maxPointsInsideSquare(points = [[1,1],[-1,-1],[2,-2]], s = "ccd")
    >>> 0
    Explanation:
    It's impossible to make any valid squares centered at the origin such that it covers only one point among points[0] and points[1].
    """


Prompt:
def minimumSubstringsInPartition(s: str) -> int:
    """
    Given a string s, you need to partition it into one or more balanced substrings. For example, if s == "ababcc" then ("abab", "c", "c"), ("ab", "abc", "c"), and ("ababcc") are all valid partitions, but ("a", "bab", "cc"), ("aba", "bc", "c"), and ("ab", "abcc") are not. The unbalanced substrings are bolded.
    Return the minimum number of substrings that you can partition s into.
    Note: A balanced string is a string where each character in the string occurs the same number of times.

    Example 1:

    >>> minimumSubstringsInPartition(s = "fabccddg")
    >>> 3
    Explanation:
    We can partition the string s into 3 substrings in one of the following ways: ("fab, "ccdd", "g"), or ("fabc", "cd", "dg").

    Example 2:

    >>> minimumSubstringsInPartition(s = "abababaccddb")
    >>> 2
    Explanation:
    We can partition the string s into 2 substrings like so: ("abab", "abaccddb").
    """


Prompt:
def findPermutationDifference(s: str, t: str) -> int:
    """
    You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s.
    The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character in s and the index of the occurrence of the same character in t.
    Return the permutation difference between s and t.

    Example 1:

    >>> findPermutationDifference(s = "abc", t = "bac")
    >>> 2
    Explanation:
    For s = "abc" and t = "bac", the permutation difference of s and t is equal to the sum of:

    The absolute difference between the index of the occurrence of "a" in s and the index of the occurrence of "a" in t.
    The absolute difference between the index of the occurrence of "b" in s and the index of the occurrence of "b" in t.
    The absolute difference between the index of the occurrence of "c" in s and the index of the occurrence of "c" in t.

    That is, the permutation difference between s and t is equal to |0 - 1| + |1 - 0| + |2 - 2| = 2.

    Example 2:

    >>> findPermutationDifference(s = "abcde", t = "edbac")
    >>> 12
    Explanation: The permutation difference between s and t is equal to |0 - 3| + |1 - 2| + |2 - 4| + |3 - 1| + |4 - 0| = 12.
    """