Prompt:
from typing import List
def minimumCost(source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:
    """
    You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters. You are also given two 0-indexed string arrays original and changed, and an integer array cost, where cost[i] represents the cost of converting the string original[i] to the string changed[i].
    You start with the string source. In one operation, you can pick a substring x from the string, and change it to y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:

    The substrings picked in the operations are source[a..b] and source[c..d] with either b < c or d < a. In other words, the indices picked in both operations are disjoint.
    The substrings picked in the operations are source[a..b] and source[c..d] with a == c and b == d. In other words, the indices picked in both operations are identical.

    Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.
    Note that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].

    Example 1:

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

    Example 2:

    >>> minimumCost(source = "abcdefgh", target = "acdeeghh", original = ["bcd","fgh","thh"], changed = ["cde","thh","ghh"], cost = [1,3,5])
    >>> 9
    Explanation: To convert "abcdefgh" to "acdeeghh", do the following operations:
    - Change substring source[1..3] from "bcd" to "cde" at a cost of 1.
    - Change substring source[5..7] from "fgh" to "thh" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.
    - Change substring source[5..7] from "thh" to "ghh" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.
    The total cost incurred is 1 + 3 + 5 = 9.
    It can be shown that this is the minimum possible cost.

    Example 3:

    >>> minimumCost(source = "abcdefgh", target = "addddddd", original = ["bcd","defgh"], changed = ["ddd","ddddd"], cost = [100,1578])
    >>> -1
    Explanation: It is impossible to convert "abcdefgh" to "addddddd".
    If you select substring source[1..3] as the first operation to change "abcdefgh" to "adddefgh", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.
    If you select substring source[3..7] as the first operation to change "abcdefgh" to "abcddddd", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.
    """


Prompt:
def mostExpensiveItem(primeOne: int, primeTwo: int) -> int:
    """
    You are given two distinct prime numbers primeOne and primeTwo.
    Alice and Bob are visiting a market. The market has an infinite number of items, for any positive integer x there exists an item whose price is x. Alice wants to buy some items from the market to gift to Bob. She has an infinite number of coins in the denomination primeOne and primeTwo. She wants to know the most expensive item she can not buy to gift to Bob.
    Return the price of the most expensive item which Alice can not gift to Bob.

    Example 1:

    >>> mostExpensiveItem(primeOne = 2, primeTwo = 5)
    >>> 3
    Explanation: The prices of items which cannot be bought are [1,3]. It can be shown that all items with a price greater than 3 can be bought using a combination of coins of denominations 2 and 5.

    Example 2:

    >>> mostExpensiveItem(primeOne = 5, primeTwo = 7)
    >>> 23
    Explanation: The prices of items which cannot be bought are [1,2,3,4,6,8,9,11,13,16,18,23]. It can be shown that all items with a price greater than 23 can be bought.
    """


Prompt:
from typing import List
def hasTrailingZeros(nums: List[int]) -> bool:
    """
    You are given an array of positive integers nums.
    You have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.
    For example, the binary representation of 5, which is "101", does not have any trailing zeros, whereas the binary representation of 4, which is "100", has two trailing zeros.
    Return true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.

    Example 1:

    >>> hasTrailingZeros(nums = [1,2,3,4,5])
    >>> true
    Explanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation "110" with one trailing zero.

    Example 2:

    >>> hasTrailingZeros(nums = [2,4,8,16])
    >>> true
    Explanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation "110" with one trailing zero.
    Other possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).

    Example 3:

    >>> hasTrailingZeros(nums = [1,3,5,7,9])
    >>> false
    Explanation: There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.
    """


Prompt:
def maximumLength(s: str) -> int:
    """
    You are given a string s that consists of lowercase English letters.
    A string is called special if it is made up of only a single character. For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are special.
    Return the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    >>> maximumLength(s = "aaaa")
    >>> 2
    Explanation: The longest special substring which occurs thrice is "aa": substrings "aaaa", "aaaa", and "aaaa".
    It can be shown that the maximum length achievable is 2.

    Example 2:

    >>> maximumLength(s = "abcdef")
    >>> -1
    Explanation: There exists no special substring which occurs at least thrice. Hence return -1.

    Example 3:

    >>> maximumLength(s = "abcaba")
    >>> 1
    Explanation: The longest special substring which occurs thrice is "a": substrings "abcaba", "abcaba", and "abcaba".
    It can be shown that the maximum length achievable is 1.
    """


Prompt:
def maximumLength(s: str) -> int:
    """
    You are given a string s that consists of lowercase English letters.
    A string is called special if it is made up of only a single character. For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are special.
    Return the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    >>> maximumLength(s = "aaaa")
    >>> 2
    Explanation: The longest special substring which occurs thrice is "aa": substrings "aaaa", "aaaa", and "aaaa".
    It can be shown that the maximum length achievable is 2.

    Example 2:

    >>> maximumLength(s = "abcdef")
    >>> -1
    Explanation: There exists no special substring which occurs at least thrice. Hence return -1.

    Example 3:

    >>> maximumLength(s = "abcaba")
    >>> 1
    Explanation: The longest special substring which occurs thrice is "a": substrings "abcaba", "abcaba", and "abcaba".
    It can be shown that the maximum length achievable is 1.
    """


Prompt:
from typing import List
def canMakePalindromeQueries(s: str, queries: List[List[int]]) -> List[bool]:
    """
    You are given a 0-indexed string s having an even length n.
    You are also given a 0-indexed 2D integer array, queries, where queries[i] = [ai, bi, ci, di].
    For each query i, you are allowed to perform the following operations:

    Rearrange the characters within the substring s[ai:bi], where 0 <= ai <= bi < n / 2.
    Rearrange the characters within the substring s[ci:di], where n / 2 <= ci <= di < n.

    For each query, your task is to determine whether it is possible to make s a palindrome by performing the operations.
    Each query is answered independently of the others.
    Return a 0-indexed array answer, where answer[i] == true if it is possible to make s a palindrome by performing operations specified by the ith query, and false otherwise.

    A substring is a contiguous sequence of characters within a string.
    s[x:y] represents the substring consisting of characters from the index x to index y in s, both inclusive.

    Example 1:

    >>> canMakePalindromeQueries(s = "abcabc", queries = [[1,1,3,5],[0,2,5,5]])
    >>> [true,true]
    Explanation: In this example, there are two queries:
    In the first query:
    - a0 = 1, b0 = 1, c0 = 3, d0 = 5.
    - So, you are allowed to rearrange s[1:1] => abcabc and s[3:5] => abcabc.
    - To make s a palindrome, s[3:5] can be rearranged to become => abccba.
    - Now, s is a palindrome. So, answer[0] = true.
    In the second query:
    - a1 = 0, b1 = 2, c1 = 5, d1 = 5.
    - So, you are allowed to rearrange s[0:2] => abcabc and s[5:5] => abcabc.
    - To make s a palindrome, s[0:2] can be rearranged to become => cbaabc.
    - Now, s is a palindrome. So, answer[1] = true.

    Example 2:

    >>> canMakePalindromeQueries(s = "abbcdecbba", queries = [[0,2,7,9]])
    >>> [false]
    Explanation: In this example, there is only one query.
    a0 = 0, b0 = 2, c0 = 7, d0 = 9.
    So, you are allowed to rearrange s[0:2] => abbcdecbba and s[7:9] => abbcdecbba.
    It is not possible to make s a palindrome by rearranging these substrings because s[3:6] is not a palindrome.
    So, answer[0] = false.
    Example 3:

    >>> canMakePalindromeQueries(s = "acbcab", queries = [[1,2,4,5]])
    >>> [true]
    Explanation: In this example, there is only one query.
    a0 = 1, b0 = 2, c0 = 4, d0 = 5.
    So, you are allowed to rearrange s[1:2] => acbcab and s[4:5] => acbcab.
    To make s a palindrome s[1:2] can be rearranged to become abccab.
    Then, s[4:5] can be rearranged to become abccba.
    Now, s is a palindrome. So, answer[0] = true.
    """


Prompt:
def selfDivisiblePermutationCount(n: int) -> int:
    """
    Given an integer n, return the number of permutations of the 1-indexed array nums = [1, 2, ..., n], such that it's self-divisible.
    A 1-indexed array a of length n is self-divisible if for every 1 <= i <= n, gcd(a[i], i) == 1.
    A permutation of an array is a rearrangement of the elements of that array, for example here are all of the permutations of the array [1, 2, 3]:

    [1, 2, 3]
    [1, 3, 2]
    [2, 1, 3]
    [2, 3, 1]
    [3, 1, 2]
    [3, 2, 1]

    Example 1:

    >>> selfDivisiblePermutationCount(n = 1)
    >>> 1
    Explanation: The array [1] has only 1 permutation which is self-divisible.

    Example 2:

    >>> selfDivisiblePermutationCount(n = 2)
    >>> 1
    Explanation: The array [1,2] has 2 permutations and only one of them is self-divisible:
    nums = [1,2]: This is not self-divisible since gcd(nums[2], 2) != 1.
    nums = [2,1]: This is self-divisible since gcd(nums[1], 1) == 1 and gcd(nums[2], 2) == 1.

    Example 3:

    >>> selfDivisiblePermutationCount(n = 3)
    >>> 3
    Explanation: The array [1,2,3] has 3 self-divisble permutations: [1,3,2], [3,1,2], [2,3,1].
    It can be shown that the other 3 permutations are not self-divisible. Hence the answer is 3.
    """


Prompt:
from typing import List
def missingInteger(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of integers nums.
    A prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.
    Return the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.

    Example 1:

    >>> missingInteger(nums = [1,2,3,2,5])
    >>> 6
    Explanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.

    Example 2:

    >>> missingInteger(nums = [3,4,5,1,12,14,13])
    >>> 15
    Explanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.
    """


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

    Choose any element of the array and flip a bit in its binary representation. Flipping a bit means changing a 0 to 1 or vice versa.

    Return the minimum number of operations required to make the bitwise XOR of all elements of the final array equal to k.
    Note that you can flip leading zero bits in the binary representation of elements. For example, for the number (101)2 you can flip the fourth bit and obtain (1101)2.

    Example 1:

    >>> minOperations(nums = [2,1,3,4], k = 1)
    >>> 2
    Explanation: We can do the following operations:
    - Choose element 2 which is 3 == (011)2, we flip the first bit and we obtain (010)2 == 2. nums becomes [2,1,2,4].
    - Choose element 0 which is 2 == (010)2, we flip the third bit and we obtain (110)2 = 6. nums becomes [6,1,2,4].
    The XOR of elements of the final array is (6 XOR 1 XOR 2 XOR 4) == 1 == k.
    It can be shown that we cannot make the XOR equal to k in less than 2 operations.

    Example 2:

    >>> minOperations(nums = [2,0,2,0], k = 0)
    >>> 0
    Explanation: The XOR of elements of the array is (2 XOR 0 XOR 2 XOR 0) == 0 == k. So no operation is needed.
    """


Prompt:
def minimumOperationsToMakeEqual(x: int, y: int) -> int:
    """
    You are given two positive integers x and y.
    In one operation, you can do one of the four following operations:

    Divide x by 11 if x is a multiple of 11.
    Divide x by 5 if x is a multiple of 5.
    Decrement x by 1.
    Increment x by 1.

    Return the minimum number of operations required to make  x and y equal.

    Example 1:

    >>> minimumOperationsToMakeEqual(x = 26, y = 1)
    >>> 3
    Explanation: We can make 26 equal to 1 by applying the following operations:
    1. Decrement x by 1
    2. Divide x by 5
    3. Divide x by 5
    It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.

    Example 2:

    >>> minimumOperationsToMakeEqual(x = 54, y = 2)
    >>> 4
    Explanation: We can make 54 equal to 2 by applying the following operations:
    1. Increment x by 1
    2. Divide x by 11
    3. Divide x by 5
    4. Increment x by 1
    It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.

    Example 3:

    >>> minimumOperationsToMakeEqual(x = 25, y = 30)
    >>> 5
    Explanation: We can make 25 equal to 30 by applying the following operations:
    1. Increment x by 1
    2. Increment x by 1
    3. Increment x by 1
    4. Increment x by 1
    5. Increment x by 1
    It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.
    """


Prompt:
def numberOfPowerfulInt(start: int, finish: int, limit: int, s: str) -> int:
    """
    You are given three integers start, finish, and limit. You are also given a 0-indexed string s representing a positive integer.
    A positive integer x is called powerful if it ends with s (in other words, s is a suffix of x) and each digit in x is at most limit.
    Return the total number of powerful integers in the range [start..finish].
    A string x is a suffix of a string y if and only if x is a substring of y that starts from some index (including 0) in y and extends to the index y.length - 1. For example, 25 is a suffix of 5125 whereas 512 is not.

    Example 1:

    >>> numberOfPowerfulInt(start = 1, finish = 6000, limit = 4, s = "124")
    >>> 5
    Explanation: The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit <= 4, and "124" as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.
    It can be shown that there are only 5 powerful integers in this range.

    Example 2:

    >>> numberOfPowerfulInt(start = 15, finish = 215, limit = 6, s = "10")
    >>> 2
    Explanation: The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit <= 6, and "10" as a suffix.
    It can be shown that there are only 2 powerful integers in this range.

    Example 3:

    >>> numberOfPowerfulInt(start = 1000, finish = 2000, limit = 4, s = "3000")
    >>> 0
    Explanation: All integers in the range [1000..2000] are smaller than 3000, hence "3000" cannot be a suffix of any integer in this range.
    """


Prompt:
from typing import List
def areaOfMaxDiagonal(dimensions: List[List[int]]) -> int:
    """
    You are given a 2D 0-indexed integer array dimensions.
    For all indices i, 0 <= i < dimensions.length, dimensions[i][0] represents the length and dimensions[i][1] represents the width of the rectangle i.
    Return the area of the rectangle having the longest diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the maximum area.

    Example 1:

    >>> areaOfMaxDiagonal(dimensions = [[9,3],[8,6]])
    >>> 48
    Explanation:
    For index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈ 9.487.
    For index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10.
    So, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 * 6 = 48.

    Example 2:

    >>> areaOfMaxDiagonal(dimensions = [[3,4],[4,3]])
    >>> 12
    Explanation: Length of diagonal is the same for both which is 5, so maximum area = 12.
    """


Prompt:
def minMovesToCaptureTheQueen(a: int, b: int, c: int, d: int, e: int, f: int) -> int:
    """
    There is a 1-indexed 8 x 8 chessboard containing 3 pieces.
    You are given 6 integers a, b, c, d, e, and f where:

    (a, b) denotes the position of the white rook.
    (c, d) denotes the position of the white bishop.
    (e, f) denotes the position of the black queen.

    Given that you can only move the white pieces, return the minimum number of moves required to capture the black queen.
    Note that:

    Rooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.
    Bishops can move any number of squares diagonally, but cannot jump over other pieces.
    A rook or a bishop can capture the queen if it is located in a square that they can move to.
    The queen does not move.

    Example 1:

    >>> minMovesToCaptureTheQueen(a = 1, b = 1, c = 8, d = 8, e = 2, f = 3)
    >>> 2
    Explanation: We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).
    It is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.

    Example 2:

    >>> minMovesToCaptureTheQueen(a = 5, b = 3, c = 3, d = 4, e = 5, f = 2)
    >>> 1
    Explanation: We can capture the black queen in a single move by doing one of the following:
    - Move the white rook to (5, 2).
    - Move the white bishop to (5, 2).
    """


Prompt:
from typing import List
def maximumSetSize(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of even length n.
    You must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.
    Return the maximum possible size of the set s.

    Example 1:

    >>> maximumSetSize(nums1 = [1,2,1,2], nums2 = [1,1,1,1])
    >>> 2
    Explanation: We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.
    It can be shown that 2 is the maximum possible size of the set s after the removals.

    Example 2:

    >>> maximumSetSize(nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3])
    >>> 5
    Explanation: We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.
    It can be shown that 5 is the maximum possible size of the set s after the removals.

    Example 3:

    >>> maximumSetSize(nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6])
    >>> 6
    Explanation: We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.
    It can be shown that 6 is the maximum possible size of the set s after the removals.
    """


Prompt:
def maxPartitionsAfterOperations(s: str, k: int) -> int:
    """
    You are given a string s and an integer k.
    First, you are allowed to change at most one index in s to another lowercase English letter.
    After that, do the following partitioning operation until s is empty:

    Choose the longest prefix of s containing at most k distinct characters.
    Delete the prefix from s and increase the number of partitions by one. The remaining characters (if any) in s maintain their initial order.

    Return an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.

    Example 1:

    >>> maxPartitionsAfterOperations(s = "accca", k = 2)
    >>> 3
    Explanation:
    The optimal way is to change s[2] to something other than a and c, for example, b. then it becomes "acbca".
    Then we perform the operations:

    The longest prefix containing at most 2 distinct characters is "ac", we remove it and s becomes "bca".
    Now The longest prefix containing at most 2 distinct characters is "bc", so we remove it and s becomes "a".
    Finally, we remove "a" and s becomes empty, so the procedure ends.

    Doing the operations, the string is divided into 3 partitions, so the answer is 3.

    Example 2:

    >>> maxPartitionsAfterOperations(s = "aabaab", k = 3)
    >>> 1
    Explanation:
    Initially s contains 2 distinct characters, so whichever character we change, it will contain at most 3 distinct characters, so the longest prefix with at most 3 distinct characters would always be all of it, therefore the answer is 1.

    Example 3:

    >>> maxPartitionsAfterOperations(s = "xxyz", k = 1)
    >>> 4
    Explanation:
    The optimal way is to change s[0] or s[1] to something other than characters in s, for example, to change s[0] to w.
    Then s becomes "wxyz", which consists of 4 distinct characters, so as k is 1, it will divide into 4 partitions.
    """


Prompt:
from typing import Any, List
def maximumSubtreeSize(edges: List[List[int]], colors: List[int]) -> int:
    """
    You are given a 2D integer array edges representing a tree with n nodes, numbered from 0 to n - 1, rooted at node 0, where edges[i] = [ui, vi] means there is an edge between the nodes vi and ui.
    You are also given a 0-indexed integer array colors of size n, where colors[i] is the color assigned to node i.
    We want to find a node v such that every node in the subtree of v has the same color.
    Return the size of such subtree with the maximum number of nodes possible.

    Example 1:

    >>> maximumSubtreeSize(edges = [[0,1],[0,2],[0,3]], colors = [1,1,2,3])
    >>> 1
    Explanation: Each color is represented as: 1 -> Red, 2 -> Green, 3 -> Blue. We can see that the subtree rooted at node 0 has children with different colors. Any other subtree is of the same color and has a size of 1. Hence, we return 1.

    Example 2:

    >>> maximumSubtreeSize(edges = [[0,1],[0,2],[0,3]], colors = [1,1,1,1])
    >>> 4
    Explanation: The whole tree has the same color, and the subtree rooted at node 0 has the most number of nodes which is 4. Hence, we return 4.

    Example 3:

    >>> maximumSubtreeSize(edges = [[0,1],[0,2],[2,3],[2,4]], colors = [1,2,3,3,3])
    >>> 3
    Explanation: Each color is represented as: 1 -> Red, 2 -> Green, 3 -> Blue. We can see that the subtree rooted at node 0 has children with different colors. Any other subtree is of the same color, but the subtree rooted at node 2 has a size of 3 which is the maximum. Hence, we return 3.
    """


Prompt:
from typing import List
def maxFrequencyElements(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Return the total frequencies of elements in nums such that those elements all have the maximum frequency.
    The frequency of an element is the number of occurrences of that element in the array.

    Example 1:

    >>> maxFrequencyElements(nums = [1,2,2,3,1,4])
    >>> 4
    Explanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.
    So the number of elements in the array with maximum frequency is 4.

    Example 2:

    >>> maxFrequencyElements(nums = [1,2,3,4,5])
    >>> 5
    Explanation: All elements of the array have a frequency of 1 which is the maximum.
    So the number of elements in the array with maximum frequency is 5.
    """


Prompt:
from typing import List
def beautifulIndices(s: str, a: str, b: str, k: int) -> List[int]:
    """
    You are given a 0-indexed string s, a string a, a string b, and an integer k.
    An index i is beautiful if:

    0 <= i <= s.length - a.length
    s[i..(i + a.length - 1)] == a
    There exists an index j such that:

    0 <= j <= s.length - b.length
    s[j..(j + b.length - 1)] == b
    |j - i| <= k

    Return the array that contains beautiful indices in sorted order from smallest to largest.

    Example 1:

    >>> beautifulIndices(s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15)
    >>> [16,33]
    Explanation: There are 2 beautiful indices: [16,33].
    - The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
    - The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15.
    Thus we return [16,33] as the result.

    Example 2:

    >>> beautifulIndices(s = "abcd", a = "a", b = "a", k = 4)
    >>> [0]
    Explanation: There is 1 beautiful index: [0].
    - The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4.
    Thus we return [0] as the result.
    """


Prompt:
def findMaximumNumber(k: int, x: int) -> int:
    """
    You are given an integer k and an integer x. The price of a number num is calculated by the count of set bits at positions x, 2x, 3x, etc., in its binary representation, starting from the least significant bit. The following table contains examples of how price is calculated.

    x
    num
    Binary Representation
    Price

    1
    13
    000001101
    3

    2
    13
    000001101
    1

    2
    233
    011101001
    3

    3
    13
    000001101
    1

    3
    362
    101101010
    2

    The accumulated price of num is the total price of numbers from 1 to num. num is considered cheap if its accumulated price is less than or equal to k.
    Return the greatest cheap number.

    Example 1:

    >>> findMaximumNumber(k = 9, x = 1)
    >>> 6
    Explanation:
    As shown in the table below, 6 is the greatest cheap number.

    x
    num
    Binary Representation
    Price
    Accumulated Price

    1
    1
    001
    1
    1

    1
    2
    010
    1
    2

    1
    3
    011
    2
    4

    1
    4
    100
    1
    5

    1
    5
    101
    2
    7

    1
    6
    110
    2
    9

    1
    7
    111
    3
    12

    Example 2:

    >>> findMaximumNumber(k = 7, x = 2)
    >>> 9
    Explanation:
    As shown in the table below, 9 is the greatest cheap number.

    x
    num
    Binary Representation
    Price
    Accumulated Price

    2
    1
    0001
    0
    0

    2
    2
    0010
    1
    1

    2
    3
    0011
    1
    2

    2
    4
    0100
    0
    2

    2
    5
    0101
    0
    2

    2
    6
    0110
    1
    3

    2
    7
    0111
    1
    4

    2
    8
    1000
    1
    5

    2
    9
    1001
    1
    6

    2
    10
    1010
    2
    8
    """


Prompt:
from typing import List
def beautifulIndices(s: str, a: str, b: str, k: int) -> List[int]:
    """
    You are given a 0-indexed string s, a string a, a string b, and an integer k.
    An index i is beautiful if:

    0 <= i <= s.length - a.length
    s[i..(i + a.length - 1)] == a
    There exists an index j such that:

    0 <= j <= s.length - b.length
    s[j..(j + b.length - 1)] == b
    |j - i| <= k

    Return the array that contains beautiful indices in sorted order from smallest to largest.

    Example 1:

    >>> beautifulIndices(s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15)
    >>> [16,33]
    Explanation: There are 2 beautiful indices: [16,33].
    - The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
    - The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15.
    Thus we return [16,33] as the result.

    Example 2:

    >>> beautifulIndices(s = "abcd", a = "a", b = "a", k = 4)
    >>> [0]
    Explanation: There is 1 beautiful index: [0].
    - The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4.
    Thus we return [0] as the result.
    """


Prompt:
from typing import List
def maxIntersectionCount(y: List[int]) -> int:
    """
    There is a line chart consisting of n points connected by line segments. You are given a 1-indexed integer array y. The kth point has coordinates (k, y[k]). There are no horizontal lines; that is, no two consecutive points have the same y-coordinate.
    We can draw an infinitely long horizontal line. Return the maximum number of points of intersection of the line with the chart.

    Example 1:

    >>> maxIntersectionCount(y = [1,2,1,2,1,3,2])
    >>> 5
    Explanation: As you can see in the image above, the line y = 1.5 has 5 intersections with the chart (in red crosses). You can also see the line y = 2 which intersects the chart in 4 points (in red crosses). It can be shown that there is no horizontal line intersecting the chart at more than 5 points. So the answer would be 5.

    Example 2:

    >>> maxIntersectionCount(y = [2,1,3,4,5])
    >>> 2
    Explanation: As you can see in the image above, the line y = 1.5 has 2 intersections with the chart (in red crosses). You can also see the line y = 2 which intersects the chart in 2 points (in red crosses). It can be shown that there is no horizontal line intersecting the chart at more than 2 points. So the answer would be 2.
    """


Prompt:
from typing import List
def minimumCost(nums: List[int]) -> int:
    """
    You are given an array of integers nums of length n.
    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 3 disjoint contiguous subarrays.
    Return the minimum possible sum of the cost of these subarrays.

    Example 1:

    >>> minimumCost(nums = [1,2,3,12])
    >>> 6
    Explanation: The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6.
    The other possible ways to form 3 subarrays are:
    - [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.
    - [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.

    Example 2:

    >>> minimumCost(nums = [5,4,3])
    >>> 12
    Explanation: The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.
    It can be shown that 12 is the minimum cost achievable.

    Example 3:

    >>> minimumCost(nums = [10,3,1,1])
    >>> 12
    Explanation: The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.
    It can be shown that 12 is the minimum cost achievable.
    """


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