Prompt:
def canSortArray(nums: List[int]) -> bool:
    """
    You are given a 0-indexed array of positive integers nums.
    In one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).
    Return true if you can sort the array in ascending order, else return false.

    Example 1:

    >>> canSortArray(nums = [8,4,2,30,15])
    >>> true
    Explanation: Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation "10", "100", and "1000" respectively. The numbers 15 and 30 have four set bits each with binary representation "1111" and "11110".
    We can sort the array using 4 operations:
    - Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].
    - Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].
    - Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].
    - Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].
    The array has become sorted, hence we return true.
    Note that there may be other sequences of operations which also sort the array.

    Example 2:

    >>> canSortArray(nums = [1,2,3,4,5])
    >>> true
    Explanation: The array is already sorted, hence we return true.

    Example 3:

    >>> canSortArray(nums = [3,16,8,4,2])
    >>> false
    Explanation: It can be shown that it is not possible to sort the input array using any number of operations.
    """


Prompt:
def minimumArrayLength(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums containing positive integers.
    Your task is to minimize the length of nums by performing the following operations any number of times (including zero):

    Select two distinct indices i and j from nums, such that nums[i] > 0 and nums[j] > 0.
    Insert the result of nums[i] % nums[j] at the end of nums.
    Delete the elements at indices i and j from nums.

    Return an integer denoting the minimum length of nums after performing the operation any number of times.

    Example 1:

    >>> minimumArrayLength(nums = [1,4,3,1])
    >>> 1
    Explanation: One way to minimize the length of the array is as follows:
    Operation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1.
    nums becomes [1,1,3].
    Operation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2.
    nums becomes [1,1].
    Operation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0.
    nums becomes [0].
    The length of nums cannot be reduced further. Hence, the answer is 1.
    It can be shown that 1 is the minimum achievable length.
    Example 2:

    >>> minimumArrayLength(nums = [5,5,5,10,5])
    >>> 2
    Explanation: One way to minimize the length of the array is as follows:
    Operation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3.
    nums becomes [5,5,5,5].
    Operation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3.
    nums becomes [5,5,0].
    Operation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1.
    nums becomes [0,0].
    The length of nums cannot be reduced further. Hence, the answer is 2.
    It can be shown that 2 is the minimum achievable length.
    Example 3:

    >>> minimumArrayLength(nums = [2,3,4])
    >>> 1
    Explanation: One way to minimize the length of the array is as follows:
    Operation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2.
    nums becomes [2,3].
    Operation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0.
    nums becomes [1].
    The length of nums cannot be reduced further. Hence, the answer is 1.
    It can be shown that 1 is the minimum achievable length.
    """


Prompt:
def minimumCost(nums: List[int], k: int, dist: int) -> int:
    """
    You are given a 0-indexed array of integers nums of length n, and two positive integers k and dist.
    The cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.
    You need to divide nums into k disjoint contiguous subarrays, such that the difference between the starting index of the second subarray and the starting index of the kth subarray should be less than or equal to dist. In other words, if you divide nums into the subarrays nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)], then ik-1 - i1 <= dist.
    Return the minimum possible sum of the cost of these subarrays.

    Example 1:

    >>> minimumCost(nums = [1,3,2,6,4,2], k = 3, dist = 3)
    >>> 5
    Explanation: The best possible way to divide nums into 3 subarrays is: [1,3], [2,6,4], and [2]. This choice is valid because ik-1 - i1 is 5 - 2 = 3 which is equal to dist. The total cost is nums[0] + nums[2] + nums[5] which is 1 + 2 + 2 = 5.
    It can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 5.

    Example 2:

    >>> minimumCost(nums = [10,1,2,2,2,1], k = 4, dist = 3)
    >>> 15
    Explanation: The best possible way to divide nums into 4 subarrays is: [10], [1], [2], and [2,2,1]. This choice is valid because ik-1 - i1 is 3 - 1 = 2 which is less than dist. The total cost is nums[0] + nums[1] + nums[2] + nums[3] which is 10 + 1 + 2 + 2 = 15.
    The division [10], [1], [2,2,2], and [1] is not valid, because the difference between ik-1 and i1 is 5 - 1 = 4, which is greater than dist.
    It can be shown that there is no possible way to divide nums into 4 subarrays at a cost lower than 15.

    Example 3:

    >>> minimumCost(nums = [10,8,18,9], k = 3, dist = 1)
    >>> 36
    Explanation: The best possible way to divide nums into 4 subarrays is: [10], [8], and [18,9]. This choice is valid because ik-1 - i1 is 2 - 1 = 1 which is equal to dist.The total cost is nums[0] + nums[1] + nums[2] which is 10 + 8 + 18 = 36.
    The division [10], [8,18], and [9] is not valid, because the difference between ik-1 and i1 is 3 - 1 = 2, which is greater than dist.
    It can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 36.
    """


Prompt:
def minimumPushes(word: str) -> int:
    """
    You are given a string word containing distinct lowercase English letters.
    Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with ["a","b","c"], we need to push the key one time to type "a", two times to type "b", and three times to type "c" .
    It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.
    Return the minimum number of pushes needed to type word after remapping the keys.
    An example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.

    Example 1:

    >>> minimumPushes(word = "abcde")
    >>> 5
    Explanation: The remapped keypad given in the image provides the minimum cost.
    "a" -> one push on key 2
    "b" -> one push on key 3
    "c" -> one push on key 4
    "d" -> one push on key 5
    "e" -> one push on key 6
    Total cost is 1 + 1 + 1 + 1 + 1 = 5.
    It can be shown that no other mapping can provide a lower cost.

    Example 2:

    >>> minimumPushes(word = "xycdefghij")
    >>> 12
    Explanation: The remapped keypad given in the image provides the minimum cost.
    "x" -> one push on key 2
    "y" -> two pushes on key 2
    "c" -> one push on key 3
    "d" -> two pushes on key 3
    "e" -> one push on key 4
    "f" -> one push on key 5
    "g" -> one push on key 6
    "h" -> one push on key 7
    "i" -> one push on key 8
    "j" -> one push on key 9
    Total cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.
    It can be shown that no other mapping can provide a lower cost.
    """


Prompt:
def countOfPairs(n: int, x: int, y: int) -> List[int]:
    """
    You are given three positive integers n, x, and y.
    In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.
    For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.
    Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.
    Note that x and y can be equal.

    Example 1:

    >>> countOfPairs(n = 3, x = 1, y = 3)
    >>> [6,0,0]
    Explanation: Let's look at each pair of houses:
    - For the pair (1, 2), we can go from house 1 to house 2 directly.
    - For the pair (2, 1), we can go from house 2 to house 1 directly.
    - For the pair (1, 3), we can go from house 1 to house 3 directly.
    - For the pair (3, 1), we can go from house 3 to house 1 directly.
    - For the pair (2, 3), we can go from house 2 to house 3 directly.
    - For the pair (3, 2), we can go from house 3 to house 2 directly.

    Example 2:

    >>> countOfPairs(n = 5, x = 2, y = 4)
    >>> [10,8,2,0,0]
    Explanation: For each distance k the pairs are:
    - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).
    - For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).
    - For k == 3, the pairs are (1, 5), and (5, 1).
    - For k == 4 and k == 5, there are no pairs.

    Example 3:

    >>> countOfPairs(n = 4, x = 1, y = 1)
    >>> [6,4,2,0]
    Explanation: For each distance k the pairs are:
    - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).
    - For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).
    - For k == 3, the pairs are (1, 4), and (4, 1).
    - For k == 4, there are no pairs.
    """


Prompt:
def minimumPushes(word: str) -> int:
    """
    You are given a string word containing lowercase English letters.
    Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with ["a","b","c"], we need to push the key one time to type "a", two times to type "b", and three times to type "c" .
    It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.
    Return the minimum number of pushes needed to type word after remapping the keys.
    An example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.

    Example 1:

    >>> minimumPushes(word = "abcde")
    >>> 5
    Explanation: The remapped keypad given in the image provides the minimum cost.
    "a" -> one push on key 2
    "b" -> one push on key 3
    "c" -> one push on key 4
    "d" -> one push on key 5
    "e" -> one push on key 6
    Total cost is 1 + 1 + 1 + 1 + 1 = 5.
    It can be shown that no other mapping can provide a lower cost.

    Example 2:

    >>> minimumPushes(word = "xyzxyzxyzxyz")
    >>> 12
    Explanation: The remapped keypad given in the image provides the minimum cost.
    "x" -> one push on key 2
    "y" -> one push on key 3
    "z" -> one push on key 4
    Total cost is 1 * 4 + 1 * 4 + 1 * 4 = 12
    It can be shown that no other mapping can provide a lower cost.
    Note that the key 9 is not mapped to any letter: it is not necessary to map letters to every key, but to map all the letters.

    Example 3:

    >>> minimumPushes(word = "aabbccddeeffgghhiiiiii")
    >>> 24
    Explanation: The remapped keypad given in the image provides the minimum cost.
    "a" -> one push on key 2
    "b" -> one push on key 3
    "c" -> one push on key 4
    "d" -> one push on key 5
    "e" -> one push on key 6
    "f" -> one push on key 7
    "g" -> one push on key 8
    "h" -> two pushes on key 9
    "i" -> one push on key 9
    Total cost is 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24.
    It can be shown that no other mapping can provide a lower cost.
    """


Prompt:
def countOfPairs(n: int, x: int, y: int) -> List[int]:
    """
    You are given three positive integers n, x, and y.
    In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.
    For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.
    Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.
    Note that x and y can be equal.

    Example 1:

    >>> countOfPairs(n = 3, x = 1, y = 3)
    >>> [6,0,0]
    Explanation: Let's look at each pair of houses:
    - For the pair (1, 2), we can go from house 1 to house 2 directly.
    - For the pair (2, 1), we can go from house 2 to house 1 directly.
    - For the pair (1, 3), we can go from house 1 to house 3 directly.
    - For the pair (3, 1), we can go from house 3 to house 1 directly.
    - For the pair (2, 3), we can go from house 2 to house 3 directly.
    - For the pair (3, 2), we can go from house 3 to house 2 directly.

    Example 2:

    >>> countOfPairs(n = 5, x = 2, y = 4)
    >>> [10,8,2,0,0]
    Explanation: For each distance k the pairs are:
    - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).
    - For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).
    - For k == 3, the pairs are (1, 5), and (5, 1).
    - For k == 4 and k == 5, there are no pairs.

    Example 3:

    >>> countOfPairs(n = 4, x = 1, y = 1)
    >>> [6,4,2,0]
    Explanation: For each distance k the pairs are:
    - For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).
    - For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).
    - For k == 3, the pairs are (1, 4), and (4, 1).
    - For k == 4, there are no pairs.
    """


Prompt:
def maximumProcessableQueries(nums: List[int], queries: List[int]) -> int:
    """
    You are given a 0-indexed array nums and a 0-indexed array queries.
    You can do the following operation at the beginning at most once:

    Replace nums with a subsequence of nums.

    We start processing queries in the given order; for each query, we do the following:

    If the first and the last element of nums is less than queries[i], the processing of queries ends.
    Otherwise, we choose either the first or the last element of nums if it is greater than or equal to queries[i], and we remove the chosen element from nums.

    Return the maximum number of queries that can be processed by doing the operation optimally.

    Example 1:

    >>> maximumProcessableQueries(nums = [1,2,3,4,5], queries = [1,2,3,4,6])
    >>> 4
    Explanation: We don't do any operation and process the queries as follows:
    1- We choose and remove nums[0] since 1 <= 1, then nums becomes [2,3,4,5].
    2- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,4,5].
    3- We choose and remove nums[0] since 3 <= 3, then nums becomes [4,5].
    4- We choose and remove nums[0] since 4 <= 4, then nums becomes [5].
    5- We can not choose any elements from nums since they are not greater than or equal to 5.
    Hence, the answer is 4.
    It can be shown that we can't process more than 4 queries.

    Example 2:

    >>> maximumProcessableQueries(nums = [2,3,2], queries = [2,2,3])
    >>> 3
    Explanation: We don't do any operation and process the queries as follows:
    1- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,2].
    2- We choose and remove nums[1] since 2 <= 2, then nums becomes [3].
    3- We choose and remove nums[0] since 3 <= 3, then nums becomes [].
    Hence, the answer is 3.
    It can be shown that we can't process more than 3 queries.

    Example 3:

    >>> maximumProcessableQueries(nums = [3,4,3], queries = [4,3,2])
    >>> 2
    Explanation: First we replace nums with the subsequence of nums [4,3].
    Then we can process the queries as follows:
    1- We choose and remove nums[0] since 4 <= 4, then nums becomes [3].
    2- We choose and remove nums[0] since 3 <= 3, then nums becomes [].
    3- We can not process any more queries since nums is empty.
    Hence, the answer is 2.
    It can be shown that we can't process more than 2 queries.
    """


Prompt:
def countKeyChanges(s: str) -> int:
    """
    You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any.
    Return the number of times the user had to change the key.
    Note: Modifiers like shift or caps lock won't be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.

    Example 1:

    >>> countKeyChanges(s = "aAbBcC")
    >>> 2
    Explanation:
    From s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.
    From s[1] = 'A' to s[2] = 'b', there is a change of key.
    From s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.
    From s[3] = 'B' to s[4] = 'c', there is a change of key.
    From s[4] = 'c' to s[5] = 'C', there is no change of key as caps lock or shift is not counted.

    Example 2:

    >>> countKeyChanges(s = "AaAaAaaA")
    >>> 0
    Explanation: There is no change of key since only the letters 'a' and 'A' are pressed which does not require change of key.
    """


Prompt:
def maximumLength(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums.
    You need to select a subset of nums which satisfies the following condition:

    You can place the selected elements in a 0-indexed array such that it follows the pattern: [x, x2, x4, ..., xk/2, xk, xk/2, ..., x4, x2, x] (Note that k can be be any non-negative power of 2). For example, [2, 4, 16, 4, 2] and [3, 9, 3] follow the pattern while [2, 4, 8, 4, 2] does not.

    Return the maximum number of elements in a subset that satisfies these conditions.

    Example 1:

    >>> maximumLength(nums = [5,4,1,2,2])
    >>> 3
    Explanation: We can select the subset {4,2,2}, which can be placed in the array as [2,4,2] which follows the pattern and 22 == 4. Hence the answer is 3.

    Example 2:

    >>> maximumLength(nums = [1,3,2,4])
    >>> 1
    Explanation: We can select the subset {1}, which can be placed in the array as [1] which follows the pattern. Hence the answer is 1. Note that we could have also selected the subsets {2}, {3}, or {4}, there may be multiple subsets which provide the same answer.
    """


Prompt:
def flowerGame(n: int, m: int) -> int:
    """
    Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are x flowers in the clockwise direction between Alice and Bob, and y flowers in the anti-clockwise direction between them.
    The game proceeds as follows:

    Alice takes the first turn.
    In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side.
    At the end of the turn, if there are no flowers left at all, the current player captures their opponent and wins the game.

    Given two integers, n and m, the task is to compute the number of possible pairs (x, y) that satisfy the conditions:

    Alice must win the game according to the described rules.
    The number of flowers x in the clockwise direction must be in the range [1,n].
    The number of flowers y in the anti-clockwise direction must be in the range [1,m].

    Return the number of possible pairs (x, y) that satisfy the conditions mentioned in the statement.

    Example 1:

    >>> flowerGame(n = 3, m = 2)
    >>> 3
    Explanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).

    Example 2:

    >>> flowerGame(n = 1, m = 1)
    >>> 0
    Explanation: No pairs satisfy the conditions described in the statement.
    """


Prompt:
def minOrAfterOperations(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.
    In one operation, you can pick any index i of nums such that 0 <= i < nums.length - 1 and replace nums[i] and nums[i + 1] with a single occurrence of nums[i] & nums[i + 1], where & represents the bitwise AND operator.
    Return the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.

    Example 1:

    >>> minOrAfterOperations(nums = [3,5,3,2,7], k = 2)
    >>> 3
    Explanation: Let's do the following operations:
    1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [1,3,2,7].
    2. Replace nums[2] and nums[3] with (nums[2] & nums[3]) so that nums becomes equal to [1,3,2].
    The bitwise-or of the final array is 3.
    It can be shown that 3 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.
    Example 2:

    >>> minOrAfterOperations(nums = [7,3,15,14,2,8], k = 4)
    >>> 2
    Explanation: Let's do the following operations:
    1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,15,14,2,8].
    2. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,14,2,8].
    3. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [2,2,8].
    4. Replace nums[1] and nums[2] with (nums[1] & nums[2]) so that nums becomes equal to [2,0].
    The bitwise-or of the final array is 2.
    It can be shown that 2 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.

    Example 3:

    >>> minOrAfterOperations(nums = [10,7,10,3,9,14,9,4], k = 1)
    >>> 15
    Explanation: Without applying any operations, the bitwise-or of nums is 15.
    It can be shown that 15 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.
    """


Prompt:
def triangleType(nums: List[int]) -> str:
    """
    You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.

    A triangle is called equilateral if it has all sides of equal length.
    A triangle is called isosceles if it has exactly two sides of equal length.
    A triangle is called scalene if all its sides are of different lengths.

    Return a string representing the type of triangle that can be formed or "none" if it cannot form a triangle.

    Example 1:

    >>> triangleType(nums = [3,3,3])
    >>> "equilateral"
    Explanation: Since all the sides are of equal length, therefore, it will form an equilateral triangle.

    Example 2:

    >>> triangleType(nums = [3,4,5])
    >>> "scalene"
    Explanation:
    nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
    nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
    nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
    Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
    As all the sides are of different lengths, it will form a scalene triangle.
    """


Prompt:
def numberOfPairs(points: List[List[int]]) -> int:
    """
    You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D plane, where points[i] = [xi, yi].
    Count the number of pairs of points (A, B), where

    A is on the upper left side of B, and
    there are no other points in the rectangle (or line) they make (including the border).

    Return the count.

    Example 1:

    >>> numberOfPairs(points = [[1,1],[2,2],[3,3]])
    >>> 0
    Explanation:

    There is no way to choose A and B so A is on the upper left side of B.

    Example 2:

    >>> numberOfPairs(points = [[6,2],[4,4],[2,6]])
    >>> 2
    Explanation:

    The left one is the pair (points[1], points[0]), where points[1] is on the upper left side of points[0] and the rectangle is empty.
    The middle one is the pair (points[2], points[1]), same as the left one it is a valid pair.
    The right one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0], but points[1] is inside the rectangle so it's not a valid pair.

    Example 3:

    >>> numberOfPairs(points = [[3,1],[1,3],[1,1]])
    >>> 2
    Explanation:

    The left one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0] and there are no other points on the line they form. Note that it is a valid state when the two points form a line.
    The middle one is the pair (points[1], points[2]), it is a valid pair same as the left one.
    The right one is the pair (points[1], points[0]), it is not a valid pair as points[2] is on the border of the rectangle.
    """


Prompt:
def maximumSubarraySum(nums: List[int], k: int) -> int:
    """
    You are given an array nums of length n and a positive integer k.
    A subarray of nums is called good if the absolute difference between its first and last element is exactly k, in other words, the subarray nums[i..j] is good if |nums[i] - nums[j]| == k.
    Return the maximum sum of a good subarray of nums. If there are no good subarrays, return 0.

    Example 1:

    >>> maximumSubarraySum(nums = [1,2,3,4,5,6], k = 1)
    >>> 11
    Explanation: The absolute difference between the first and last element must be 1 for a good subarray. All the good subarrays are: [1,2], [2,3], [3,4], [4,5], and [5,6]. The maximum subarray sum is 11 for the subarray [5,6].

    Example 2:

    >>> maximumSubarraySum(nums = [-1,3,2,4,5], k = 3)
    >>> 11
    Explanation: The absolute difference between the first and last element must be 3 for a good subarray. All the good subarrays are: [-1,3,2], and [2,4,5]. The maximum subarray sum is 11 for the subarray [2,4,5].

    Example 3:

    >>> maximumSubarraySum(nums = [-1,-2,-3,-4], k = 2)
    >>> -6
    Explanation: The absolute difference between the first and last element must be 2 for a good subarray. All the good subarrays are: [-1,-2,-3], and [-2,-3,-4]. The maximum subarray sum is -6 for the subarray [-1,-2,-3].
    """


Prompt:
def numberOfPairs(points: List[List[int]]) -> int:
    """
    You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
    We define the right direction as positive x-axis (increasing x-coordinate) and the left direction as negative x-axis (decreasing x-coordinate). Similarly, we define the up direction as positive y-axis (increasing y-coordinate) and the down direction as negative y-axis (decreasing y-coordinate)
    You have to place n people, including Alice and Bob, at these points such that there is exactly one person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the upper left corner and Bob's position as the lower right corner of the fence (Note that the fence might not enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either inside the fence or on the fence, Alice will be sad.
    Return the number of pairs of points where you can place Alice and Bob, such that Alice does not become sad on building the fence.
    Note that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners (1, 1), (1, 3), (3, 1), and (3, 3), because:

    With Alice at (3, 3) and Bob at (1, 1), Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence.
    With Alice at (1, 3) and Bob at (1, 1), Bob's position is not the lower right corner of the fence.

    Example 1:

    >>> numberOfPairs(points = [[1,1],[2,2],[3,3]])
    >>> 0
    Explanation: There is no way to place Alice and Bob such that Alice can build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. Hence we return 0.

    Example 2:

    >>> numberOfPairs(points = [[6,2],[4,4],[2,6]])
    >>> 2
    Explanation: There are two ways to place Alice and Bob such that Alice will not be sad:
    - Place Alice at (4, 4) and Bob at (6, 2).
    - Place Alice at (2, 6) and Bob at (4, 4).
    You cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence.

    Example 3:

    >>> numberOfPairs(points = [[3,1],[1,3],[1,1]])
    >>> 2
    Explanation: There are two ways to place Alice and Bob such that Alice will not be sad:
    - Place Alice at (1, 1) and Bob at (3, 1).
    - Place Alice at (1, 3) and Bob at (1, 1).
    You cannot place Alice at (1, 3) and Bob at (3, 1) because the person at (1, 1) will be on the fence.
    Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.
    """


Prompt:
def returnToBoundaryCount(nums: List[int]) -> int:
    """
    An ant is on a boundary. It sometimes goes left and sometimes right.
    You are given an array of non-zero integers nums. The ant starts reading nums from the first element of it to its end. At each step, it moves according to the value of the current element:

    If nums[i] < 0, it moves left by -nums[i] units.
    If nums[i] > 0, it moves right by nums[i] units.

    Return the number of times the ant returns to the boundary.
    Notes:

    There is an infinite space on both sides of the boundary.
    We check whether the ant is on the boundary only after it has moved |nums[i]| units. In other words, if the ant crosses the boundary during its movement, it does not count.

    Example 1:

    >>> returnToBoundaryCount(nums = [2,3,-5])
    >>> 1
    Explanation: After the first step, the ant is 2 steps to the right of the boundary.
    After the second step, the ant is 5 steps to the right of the boundary.
    After the third step, the ant is on the boundary.
    So the answer is 1.

    Example 2:

    >>> returnToBoundaryCount(nums = [3,2,-3,-4])
    >>> 0
    Explanation: After the first step, the ant is 3 steps to the right of the boundary.
    After the second step, the ant is 5 steps to the right of the boundary.
    After the third step, the ant is 2 steps to the right of the boundary.
    After the fourth step, the ant is 2 steps to the left of the boundary.
    The ant never returned to the boundary, so the answer is 0.
    """


Prompt:
def minimumTimeToInitialState(word: str, k: int) -> int:
    """
    You are given a 0-indexed string word and an integer k.
    At every second, you must perform the following operations:

    Remove the first k characters of word.
    Add any k characters to the end of word.

    Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.
    Return the minimum time greater than zero required for word to revert to its initial state.

    Example 1:

    >>> minimumTimeToInitialState(word = "abacaba", k = 3)
    >>> 2
    Explanation: At the 1st second, we remove characters "aba" from the prefix of word, and add characters "bac" to the end of word. Thus, word becomes equal to "cababac".
    At the 2nd second, we remove characters "cab" from the prefix of word, and add "aba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
    It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.

    Example 2:

    >>> minimumTimeToInitialState(word = "abacaba", k = 4)
    >>> 1
    Explanation: At the 1st second, we remove characters "abac" from the prefix of word, and add characters "caba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
    It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.

    Example 3:

    >>> minimumTimeToInitialState(word = "abcbabcd", k = 2)
    >>> 4
    Explanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.
    After 4 seconds, word becomes equal to "abcbabcd" and reverts to its initial state.
    It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.
    """


Prompt:
def resultGrid(image: List[List[int]], threshold: int) -> List[List[int]]:
    """
    You are given m x n grid image which represents a grayscale image, where image[i][j] represents a pixel with intensity in the range [0..255]. You are also given a non-negative integer threshold.
    Two pixels are adjacent if they share an edge.
    A region is a 3 x 3 subgrid where the absolute difference in intensity between any two adjacent pixels is less than or equal to threshold.
    All pixels in a region belong to that region, note that a pixel can belong to multiple regions.
    You need to calculate a m x n grid result, where result[i][j] is the average intensity of the regions to which image[i][j] belongs, rounded down to the nearest integer. If image[i][j] belongs to multiple regions, result[i][j] is the average of the rounded-down average intensities of these regions, rounded down to the nearest integer. If image[i][j] does not belong to any region, result[i][j] is equal to image[i][j].
    Return the grid result.

    Example 1:

    >>> resultGrid(image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3)
    >>> [[9,9,9,9],[9,9,9,9],[9,9,9,9]]
    Explanation:

    There are two regions as illustrated above. The average intensity of the first region is 9, while the average intensity of the second region is 9.67 which is rounded down to 9. The average intensity of both of the regions is (9 + 9) / 2 = 9. As all the pixels belong to either region 1, region 2, or both of them, the intensity of every pixel in the result is 9.
    Please note that the rounded-down values are used when calculating the average of multiple regions, hence the calculation is done using 9 as the average intensity of region 2, not 9.67.

    Example 2:

    >>> resultGrid(image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12)
    >>> [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]
    Explanation:

    There are two regions as illustrated above. The average intensity of the first region is 25, while the average intensity of the second region is 30. The average intensity of both of the regions is (25 + 30) / 2 = 27.5 which is rounded down to 27.
    All the pixels in row 0 of the image belong to region 1, hence all the pixels in row 0 in the result are 25. Similarly, all the pixels in row 3 in the result are 30. The pixels in rows 1 and 2 of the image belong to region 1 and region 2, hence their assigned value is 27 in the result.

    Example 3:

    >>> resultGrid(image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1)
    >>> [[5,6,7],[8,9,10],[11,12,13]]
    Explanation:
    There is only one 3 x 3 subgrid, while it does not have the condition on difference of adjacent pixels, for example, the difference between image[0][0] and image[1][0] is |5 - 8| = 3 > threshold = 1. None of them belong to any valid regions, so the result should be the same as image.
    """


Prompt:
def minimumTimeToInitialState(word: str, k: int) -> int:
    """
    You are given a 0-indexed string word and an integer k.
    At every second, you must perform the following operations:

    Remove the first k characters of word.
    Add any k characters to the end of word.

    Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.
    Return the minimum time greater than zero required for word to revert to its initial state.

    Example 1:

    >>> minimumTimeToInitialState(word = "abacaba", k = 3)
    >>> 2
    Explanation: At the 1st second, we remove characters "aba" from the prefix of word, and add characters "bac" to the end of word. Thus, word becomes equal to "cababac".
    At the 2nd second, we remove characters "cab" from the prefix of word, and add "aba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
    It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.

    Example 2:

    >>> minimumTimeToInitialState(word = "abacaba", k = 4)
    >>> 1
    Explanation: At the 1st second, we remove characters "abac" from the prefix of word, and add characters "caba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
    It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.

    Example 3:

    >>> minimumTimeToInitialState(word = "abcbabcd", k = 2)
    >>> 4
    Explanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.
    After 4 seconds, word becomes equal to "abcbabcd" and reverts to its initial state.
    It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.
    """


Prompt:
def numberCount(a: int, b: int) -> int:
    """
    Given two positive integers a and b, return the count of numbers having unique digits in the range [a, b] (inclusive).

    Example 1:

    >>> numberCount(a = 1, b = 20)
    >>> 19
    Explanation: All the numbers in the range [1, 20] have unique digits except 11. Hence, the answer is 19.

    Example 2:

    >>> numberCount(a = 9, b = 19)
    >>> 10
    Explanation: All the numbers in the range [9, 19] have unique digits except 11. Hence, the answer is 10.

    Example 3:

    >>> numberCount(a = 80, b = 120)
    >>> 27
    Explanation: There are 41 numbers in the range [80, 120], 27 of which have unique digits.
    """


Prompt:
def modifiedMatrix(matrix: List[List[int]]) -> List[List[int]]:
    """
    Given a 0-indexed m x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column.
    Return the matrix answer.

    Example 1:

    >>> modifiedMatrix(matrix = [[1,2,-1],[4,-1,6],[7,8,9]])
    >>> [[1,2,9],[4,8,6],[7,8,9]]
    Explanation: The diagram above shows the elements that are changed (in blue).
    - We replace the value in the cell [1][1] with the maximum value in the column 1, that is 8.
    - We replace the value in the cell [0][2] with the maximum value in the column 2, that is 9.

    Example 2:

    >>> modifiedMatrix(matrix = [[3,-1],[5,2]])
    >>> [[3,2],[5,2]]
    Explanation: The diagram above shows the elements that are changed (in blue).
    """


Prompt:
def countMatchingSubarrays(nums: List[int], pattern: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.
    A subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:

    nums[i + k + 1] > nums[i + k] if pattern[k] == 1.
    nums[i + k + 1] == nums[i + k] if pattern[k] == 0.
    nums[i + k + 1] < nums[i + k] if pattern[k] == -1.

    Return the count of subarrays in nums that match the pattern.

    Example 1:

    >>> countMatchingSubarrays(nums = [1,2,3,4,5,6], pattern = [1,1])
    >>> 4
    Explanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.
    Hence, there are 4 subarrays in nums that match the pattern.

    Example 2:

    >>> countMatchingSubarrays(nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1])
    >>> 2
    Explanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.
    Hence, there are 2 subarrays in nums that match the pattern.
    """


Prompt:
def maxPalindromesAfterOperations(words: List[str]) -> int:
    """
    You are given a 0-indexed string array words having length n and containing 0-indexed strings.
    You are allowed to perform the following operation any number of times (including zero):

    Choose integers i, j, x, and y such that 0 <= i, j < n, 0 <= x < words[i].length, 0 <= y < words[j].length, and swap the characters words[i][x] and words[j][y].

    Return an integer denoting the maximum number of palindromes words can contain, after performing some operations.
    Note: i and j may be equal during an operation.

    Example 1:

    >>> maxPalindromesAfterOperations(words = ["abbb","ba","aa"])
    >>> 3
    Explanation: In this example, one way to get the maximum number of palindromes is:
    Choose i = 0, j = 1, x = 0, y = 0, so we swap words[0][0] and words[1][0]. words becomes ["bbbb","aa","aa"].
    All strings in words are now palindromes.
    Hence, the maximum number of palindromes achievable is 3.
    Example 2:

    >>> maxPalindromesAfterOperations(words = ["abc","ab"])
    >>> 2
    Explanation: In this example, one way to get the maximum number of palindromes is:
    Choose i = 0, j = 1, x = 1, y = 0, so we swap words[0][1] and words[1][0]. words becomes ["aac","bb"].
    Choose i = 0, j = 0, x = 1, y = 2, so we swap words[0][1] and words[0][2]. words becomes ["aca","bb"].
    Both strings are now palindromes.
    Hence, the maximum number of palindromes achievable is 2.

    Example 3:

    >>> maxPalindromesAfterOperations(words = ["cd","ef","a"])
    >>> 1
    Explanation: In this example, there is no need to perform any operation.
    There is one palindrome in words "a".
    It can be shown that it is not possible to get more than one palindrome after any number of operations.
    Hence, the answer is 1.
    """


Prompt:
def countMatchingSubarrays(nums: List[int], pattern: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.
    A subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:

    nums[i + k + 1] > nums[i + k] if pattern[k] == 1.
    nums[i + k + 1] == nums[i + k] if pattern[k] == 0.
    nums[i + k + 1] < nums[i + k] if pattern[k] == -1.

    Return the count of subarrays in nums that match the pattern.

    Example 1:

    >>> countMatchingSubarrays(nums = [1,2,3,4,5,6], pattern = [1,1])
    >>> 4
    Explanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.
    Hence, there are 4 subarrays in nums that match the pattern.

    Example 2:

    >>> countMatchingSubarrays(nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1])
    >>> 2
    Explanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.
    Hence, there are 2 subarrays in nums that match the pattern.
    """


Prompt:
def maxOperations(nums: List[int]) -> int:
    """
    You are given an array of integers nums. Consider the following operation:

    Delete the first two elements nums and define the score of the operation as the sum of these two elements.

    You can perform this operation until nums contains fewer than two elements. Additionally, the same score must be achieved in all operations.
    Return the maximum number of operations you can perform.

    Example 1:

    >>> maxOperations(nums = [3,2,1,4,5])
    >>> 2
    Explanation:

    We can perform the first operation with the score 3 + 2 = 5. After this operation, nums = [1,4,5].
    We can perform the second operation as its score is 4 + 1 = 5, the same as the previous operation. After this operation, nums = [5].
    As there are fewer than two elements, we can't perform more operations.

    Example 2:

    >>> maxOperations(nums = [1,5,3,3,4,1,3,2,2,3])
    >>> 2
    Explanation:

    We can perform the first operation with the score 1 + 5 = 6. After this operation, nums = [3,3,4,1,3,2,2,3].
    We can perform the second operation as its score is 3 + 3 = 6, the same as the previous operation. After this operation, nums = [4,1,3,2,2,3].
    We cannot perform the next operation as its score is 4 + 1 = 5, which is different from the previous scores.

    Example 3:

    >>> maxOperations(nums = [5,3])
    >>> 1
    """


Prompt:
def lastNonEmptyString(s: str) -> str:
    """
    You are given a string s.
    Consider performing the following operation until s becomes empty:

    For every alphabet character from 'a' to 'z', remove the first occurrence of that character in s (if it exists).

    For example, let initially s = "aabcbbca". We do the following operations:

    Remove the underlined characters s = "aabcbbca". The resulting string is s = "abbca".
    Remove the underlined characters s = "abbca". The resulting string is s = "ba".
    Remove the underlined characters s = "ba". The resulting string is s = "".

    Return the value of the string s right before applying the last operation. In the example above, answer is "ba".

    Example 1:

    >>> lastNonEmptyString(s = "aabcbbca")
    >>> "ba"
    Explanation: Explained in the statement.

    Example 2:

    >>> lastNonEmptyString(s = "abcd")
    >>> "abcd"
    Explanation: We do the following operation:
    - Remove the underlined characters s = "abcd". The resulting string is s = "".
    The string just before the last operation is "abcd".
    """


Prompt:
def maxOperations(nums: List[int]) -> int:
    """
    Given an array of integers called nums, you can perform any of the following operation while nums contains at least 2 elements:

    Choose the first two elements of nums and delete them.
    Choose the last two elements of nums and delete them.
    Choose the first and the last elements of nums and delete them.

    The score of the operation is the sum of the deleted elements.
    Your task is to find the maximum number of operations that can be performed, such that all operations have the same score.
    Return the maximum number of operations possible that satisfy the condition mentioned above.

    Example 1:

    >>> maxOperations(nums = [3,2,1,2,3,4])
    >>> 3
    Explanation: We perform the following operations:
    - Delete the first two elements, with score 3 + 2 = 5, nums = [1,2,3,4].
    - Delete the first and the last elements, with score 1 + 4 = 5, nums = [2,3].
    - Delete the first and the last elements, with score 2 + 3 = 5, nums = [].
    We are unable to perform any more operations as nums is empty.

    Example 2:

    >>> maxOperations(nums = [3,2,6,1,4])
    >>> 2
    Explanation: We perform the following operations:
    - Delete the first two elements, with score 3 + 2 = 5, nums = [6,1,4].
    - Delete the last two elements, with score 1 + 4 = 5, nums = [6].
    It can be proven that we can perform at most 2 operations.
    """


Prompt:
def maxSelectedElements(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums consisting of positive integers.
    Initially, you can increase the value of any element in the array by at most 1.
    After that, you need to select one or more elements from the final array such that those elements are consecutive when sorted in increasing order. For example, the elements [3, 4, 5] are consecutive while [3, 4, 6] and [1, 1, 2, 3] are not.
    Return the maximum number of elements that you can select.

    Example 1:

    >>> maxSelectedElements(nums = [2,1,5,1,1])
    >>> 3
    Explanation: We can increase the elements at indices 0 and 3. The resulting array is nums = [3,1,5,2,1].
    We select the elements [3,1,5,2,1] and we sort them to obtain [1,2,3], which are consecutive.
    It can be shown that we cannot select more than 3 consecutive elements.
    Example 2:

    >>> maxSelectedElements(nums = [1,4,7,10])
    >>> 1
    Explanation: The maximum consecutive elements that we can select is 1.
    """


Prompt:
def countPrefixSuffixPairs(words: List[str]) -> int:
    """
    You are given a 0-indexed string array words.
    Let's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:

    isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.

    For example, isPrefixAndSuffix("aba", "ababa") is true because "aba" is a prefix of "ababa" and also a suffix, but isPrefixAndSuffix("abc", "abcd") is false.
    Return an integer denoting the number of index pairs (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) is true.

    Example 1:

    >>> countPrefixSuffixPairs(words = ["a","aba","ababa","aa"])
    >>> 4
    Explanation: In this example, the counted index pairs are:
    i = 0 and j = 1 because isPrefixAndSuffix("a", "aba") is true.
    i = 0 and j = 2 because isPrefixAndSuffix("a", "ababa") is true.
    i = 0 and j = 3 because isPrefixAndSuffix("a", "aa") is true.
    i = 1 and j = 2 because isPrefixAndSuffix("aba", "ababa") is true.
    Therefore, the answer is 4.
    Example 2:

    >>> countPrefixSuffixPairs(words = ["pa","papa","ma","mama"])
    >>> 2
    Explanation: In this example, the counted index pairs are:
    i = 0 and j = 1 because isPrefixAndSuffix("pa", "papa") is true.
    i = 2 and j = 3 because isPrefixAndSuffix("ma", "mama") is true.
    Therefore, the answer is 2.
    Example 3:

    >>> countPrefixSuffixPairs(words = ["abab","ab"])
    >>> 0
    Explanation: In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix("abab", "ab") is false.
    Therefore, the answer is 0.
    """


Prompt:
def longestCommonPrefix(arr1: List[int], arr2: List[int]) -> int:
    """
    You are given two arrays with positive integers arr1 and arr2.
    A prefix of a positive integer is an integer formed by one or more of its digits, starting from its leftmost digit. For example, 123 is a prefix of the integer 12345, while 234 is not.
    A common prefix of two integers a and b is an integer c, such that c is a prefix of both a and b. For example, 5655359 and 56554 have common prefixes 565 and 5655 while 1223 and 43456 do not have a common prefix.
    You need to find the length of the longest common prefix between all pairs of integers (x, y) such that x belongs to arr1 and y belongs to arr2.
    Return the length of the longest common prefix among all pairs. If no common prefix exists among them, return 0.

    Example 1:

    >>> longestCommonPrefix(arr1 = [1,10,100], arr2 = [1000])
    >>> 3
    Explanation: There are 3 pairs (arr1[i], arr2[j]):
    - The longest common prefix of (1, 1000) is 1.
    - The longest common prefix of (10, 1000) is 10.
    - The longest common prefix of (100, 1000) is 100.
    The longest common prefix is 100 with a length of 3.

    Example 2:

    >>> longestCommonPrefix(arr1 = [1,2,3], arr2 = [4,4,4])
    >>> 0
    Explanation: There exists no common prefix for any pair (arr1[i], arr2[j]), hence we return 0.
    Note that common prefixes between elements of the same array do not count.
    """


Prompt:
def mostFrequentPrime(mat: List[List[int]]) -> int:
    """
    You are given a m x n 0-indexed 2D matrix mat. From every cell, you can create numbers in the following way:

    There could be at most 8 paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east.
    Select a path from them and append digits in this path to the number being formed by traveling in this direction.
    Note that numbers are generated at every step, for example, if the digits along the path are 1, 9, 1, then there will be three numbers generated along the way: 1, 19, 191.

    Return the most frequent prime number greater than 10 out of all the numbers created by traversing the matrix or -1 if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the largest among them.
    Note: It is invalid to change the direction during the move.

    Example 1:

    >>> mostFrequentPrime(mat = [[1,1],[9,9],[1,1]])
    >>> 19
    Explanation:
    From cell (0,0) there are 3 possible directions and the numbers greater than 10 which can be created in those directions are:
    East: [11], South-East: [19], South: [19,191].
    Numbers greater than 10 created from the cell (0,1) in all possible directions are: [19,191,19,11].
    Numbers greater than 10 created from the cell (1,0) in all possible directions are: [99,91,91,91,91].
    Numbers greater than 10 created from the cell (1,1) in all possible directions are: [91,91,99,91,91].
    Numbers greater than 10 created from the cell (2,0) in all possible directions are: [11,19,191,19].
    Numbers greater than 10 created from the cell (2,1) in all possible directions are: [11,19,19,191].
    The most frequent prime number among all the created numbers is 19.
    Example 2:

    >>> mostFrequentPrime(mat = [[7]])
    >>> -1
    Explanation: The only number which can be formed is 7. It is a prime number however it is not greater than 10, so return -1.
    Example 3:

    >>> mostFrequentPrime(mat = [[9,7,8],[4,6,5],[2,8,6]])
    >>> 97
    Explanation:
    Numbers greater than 10 created from the cell (0,0) in all possible directions are: [97,978,96,966,94,942].
    Numbers greater than 10 created from the cell (0,1) in all possible directions are: [78,75,76,768,74,79].
    Numbers greater than 10 created from the cell (0,2) in all possible directions are: [85,856,86,862,87,879].
    Numbers greater than 10 created from the cell (1,0) in all possible directions are: [46,465,48,42,49,47].
    Numbers greater than 10 created from the cell (1,1) in all possible directions are: [65,66,68,62,64,69,67,68].
    Numbers greater than 10 created from the cell (1,2) in all possible directions are: [56,58,56,564,57,58].
    Numbers greater than 10 created from the cell (2,0) in all possible directions are: [28,286,24,249,26,268].
    Numbers greater than 10 created from the cell (2,1) in all possible directions are: [86,82,84,86,867,85].
    Numbers greater than 10 created from the cell (2,2) in all possible directions are: [68,682,66,669,65,658].
    The most frequent prime number among all the created numbers is 97.
    """


Prompt:
def countPrefixSuffixPairs(words: List[str]) -> int:
    """
    You are given a 0-indexed string array words.
    Let's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:

    isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.

    For example, isPrefixAndSuffix("aba", "ababa") is true because "aba" is a prefix of "ababa" and also a suffix, but isPrefixAndSuffix("abc", "abcd") is false.
    Return an integer denoting the number of index pairs (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) is true.

    Example 1:

    >>> countPrefixSuffixPairs(words = ["a","aba","ababa","aa"])
    >>> 4
    Explanation: In this example, the counted index pairs are:
    i = 0 and j = 1 because isPrefixAndSuffix("a", "aba") is true.
    i = 0 and j = 2 because isPrefixAndSuffix("a", "ababa") is true.
    i = 0 and j = 3 because isPrefixAndSuffix("a", "aa") is true.
    i = 1 and j = 2 because isPrefixAndSuffix("aba", "ababa") is true.
    Therefore, the answer is 4.
    Example 2:

    >>> countPrefixSuffixPairs(words = ["pa","papa","ma","mama"])
    >>> 2
    Explanation: In this example, the counted index pairs are:
    i = 0 and j = 1 because isPrefixAndSuffix("pa", "papa") is true.
    i = 2 and j = 3 because isPrefixAndSuffix("ma", "mama") is true.
    Therefore, the answer is 2.
    Example 3:

    >>> countPrefixSuffixPairs(words = ["abab","ab"])
    >>> 0
    Explanation: In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix("abab", "ab") is false.
    Therefore, the answer is 0.
    """


Prompt:
def isPossibleToSplit(nums: List[int]) -> bool:
    """
    You are given an integer array nums of even length. You have to split the array into two parts nums1 and nums2 such that:

    nums1.length == nums2.length == nums.length / 2.
    nums1 should contain distinct elements.
    nums2 should also contain distinct elements.

    Return true if it is possible to split the array, and false otherwise.

    Example 1:

    >>> isPossibleToSplit(nums = [1,1,2,2,3,4])
    >>> true
    Explanation: One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].

    Example 2:

    >>> isPossibleToSplit(nums = [1,1,1,1])
    >>> false
    Explanation: The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.
    """


Prompt:
def largestSquareArea(bottomLeft: List[List[int]], topRight: List[List[int]]) -> int:
    """
    There exist n rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays bottomLeft and topRight where bottomLeft[i] = [a_i, b_i] and topRight[i] = [c_i, d_i] represent the bottom-left and top-right coordinates of the ith rectangle, respectively.
    You need to find the maximum area of a square that can fit inside the intersecting region of at least two rectangles. Return 0 if such a square does not exist.

    Example 1:

    >>> largestSquareArea(bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]])
    >>> 1
    Explanation:
    A square with side length 1 can fit inside either the intersecting region of rectangles 0 and 1 or the intersecting region of rectangles 1 and 2. Hence the maximum area is 1. It can be shown that a square with a greater side length can not fit inside any intersecting region of two rectangles.
    Example 2:

    >>> largestSquareArea(bottomLeft = [[1,1],[1,3],[1,5]], topRight = [[5,5],[5,7],[5,9]])
    >>> 4
    Explanation:
    A square with side length 2 can fit inside either the intersecting region of rectangles 0 and 1 or the intersecting region of rectangles 1 and 2. Hence the maximum area is 2 * 2 = 4. It can be shown that a square with a greater side length can not fit inside any intersecting region of two rectangles.
    Example 3:

    >>> largestSquareArea(bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]])
    >>> 1
    Explanation:
    A square with side length 1 can fit inside the intersecting region of any two rectangles. Also, no larger square can, so the maximum area is 1. Note that the region can be formed by the intersection of more than 2 rectangles.
    Example 4:

    >>> largestSquareArea(bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]])
    >>> 0
    Explanation:
    No pair of rectangles intersect, hence, the answer is 0.
    """


Prompt:
def earliestSecondToMarkIndices(nums: List[int], changeIndices: List[int]) -> int:
    """
    You are given two 1-indexed integer arrays, nums and, changeIndices, having lengths n and m, respectively.
    Initially, all indices in nums are unmarked. Your task is to mark all indices in nums.
    In each second, s, in order from 1 to m (inclusive), you can perform one of the following operations:

    Choose an index i in the range [1, n] and decrement nums[i] by 1.
    If nums[changeIndices[s]] is equal to 0, mark the index changeIndices[s].
    Do nothing.

    Return an integer denoting the earliest second in the range [1, m] when all indices in nums can be marked by choosing operations optimally, or -1 if it is impossible.

    Example 1:

    >>> earliestSecondToMarkIndices(nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1])
    >>> 8
    Explanation: In this example, we have 8 seconds. The following operations can be performed to mark all indices:
    Second 1: Choose index 1 and decrement nums[1] by one. nums becomes [1,2,0].
    Second 2: Choose index 1 and decrement nums[1] by one. nums becomes [0,2,0].
    Second 3: Choose index 2 and decrement nums[2] by one. nums becomes [0,1,0].
    Second 4: Choose index 2 and decrement nums[2] by one. nums becomes [0,0,0].
    Second 5: Mark the index changeIndices[5], which is marking index 3, since nums[3] is equal to 0.
    Second 6: Mark the index changeIndices[6], which is marking index 2, since nums[2] is equal to 0.
    Second 7: Do nothing.
    Second 8: Mark the index changeIndices[8], which is marking index 1, since nums[1] is equal to 0.
    Now all indices have been marked.
    It can be shown that it is not possible to mark all indices earlier than the 8th second.
    Hence, the answer is 8.

    Example 2:

    >>> earliestSecondToMarkIndices(nums = [1,3], changeIndices = [1,1,1,2,1,1,1])
    >>> 6
    Explanation: In this example, we have 7 seconds. The following operations can be performed to mark all indices:
    Second 1: Choose index 2 and decrement nums[2] by one. nums becomes [1,2].
    Second 2: Choose index 2 and decrement nums[2] by one. nums becomes [1,1].
    Second 3: Choose index 2 and decrement nums[2] by one. nums becomes [1,0].
    Second 4: Mark the index changeIndices[4], which is marking index 2, since nums[2] is equal to 0.
    Second 5: Choose index 1 and decrement nums[1] by one. nums becomes [0,0].
    Second 6: Mark the index changeIndices[6], which is marking index 1, since nums[1] is equal to 0.
    Now all indices have been marked.
    It can be shown that it is not possible to mark all indices earlier than the 6th second.
    Hence, the answer is 6.

    Example 3:

    >>> earliestSecondToMarkIndices(nums = [0,1], changeIndices = [2,2,2])
    >>> -1
    Explanation: In this example, it is impossible to mark all indices because index 1 isn't in changeIndices.
    Hence, the answer is -1.
    """


Prompt:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    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:

    >>> __init__(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:

    >>> __init__(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:

    >>> __init__(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:
# class ListNode:
#     def __init__(val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    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:

    >>> __init__(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:

    >>> __init__(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:

    >>> __init__(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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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.
    """