Prompt:
from typing import List
def minimumRelativeLosses(prices: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given an integer array prices, which shows the chocolate prices and a 2D integer array queries, where queries[i] = [ki, mi].
    Alice and Bob went to buy some chocolates, and Alice suggested a way to pay for them, and Bob agreed.
    The terms for each query are as follows:

    If the price of a chocolate is less than or equal to ki, Bob pays for it.
    Otherwise, Bob pays ki of it, and Alice pays the rest.

    Bob wants to select exactly mi chocolates such that his relative loss is minimized, more formally, if, in total, Alice has paid ai and Bob has paid bi, Bob wants to minimize bi - ai.
    Return an integer array ans where ans[i] is Bob's minimum relative loss possible for queries[i].

    Example 1:

    >>> minimumRelativeLosses(prices = [1,9,22,10,19], queries = [[18,4],[5,2]])
    >>> [34,-21]
    Explanation: For the 1st query Bob selects the chocolates with prices [1,9,10,22]. He pays 1 + 9 + 10 + 18 = 38 and Alice pays 0 + 0 + 0 + 4 = 4. So Bob's relative loss is 38 - 4 = 34.
    For the 2nd query Bob selects the chocolates with prices [19,22]. He pays 5 + 5 = 10 and Alice pays 14 + 17 = 31. So Bob's relative loss is 10 - 31 = -21.
    It can be shown that these are the minimum possible relative losses.
    Example 2:

    >>> minimumRelativeLosses(prices = [1,5,4,3,7,11,9], queries = [[5,4],[5,7],[7,3],[4,5]])
    >>> [4,16,7,1]
    Explanation: For the 1st query Bob selects the chocolates with prices [1,3,9,11]. He pays 1 + 3 + 5 + 5 = 14 and Alice pays 0 + 0 + 4 + 6 = 10. So Bob's relative loss is 14 - 10 = 4.
    For the 2nd query Bob has to select all the chocolates. He pays 1 + 5 + 4 + 3 + 5 + 5 + 5 = 28 and Alice pays 0 + 0 + 0 + 0 + 2 + 6 + 4 = 12. So Bob's relative loss is 28 - 12 = 16.
    For the 3rd query Bob selects the chocolates with prices [1,3,11] and he pays 1 + 3 + 7 = 11 and Alice pays 0 + 0 + 4 = 4. So Bob's relative loss is 11 - 4 = 7.
    For the 4th query Bob selects the chocolates with prices [1,3,7,9,11] and he pays 1 + 3 + 4 + 4 + 4 = 16 and Alice pays 0 + 0 + 3 + 5 + 7 = 15. So Bob's relative loss is 16 - 15 = 1.
    It can be shown that these are the minimum possible relative losses.

    Example 3:

    >>> minimumRelativeLosses(prices = [5,6,7], queries = [[10,1],[5,3],[3,3]])
    >>> [5,12,0]
    Explanation: For the 1st query Bob selects the chocolate with price 5 and he pays 5 and Alice pays 0. So Bob's relative loss is 5 - 0 = 5.
    For the 2nd query Bob has to select all the chocolates. He pays 5 + 5 + 5 = 15 and Alice pays 0 + 1 + 2 = 3. So Bob's relative loss is 15 - 3 = 12.
    For the 3rd query Bob has to select all the chocolates. He pays 3 + 3 + 3 = 9 and Alice pays 2 + 3 + 4 = 9. So Bob's relative loss is 9 - 9 = 0.
    It can be shown that these are the minimum possible relative losses.
    """


Prompt:
from typing import List
def countPairs(nums: List[int], target: int) -> int:
    """
    Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.

    Example 1:

    >>> countPairs(nums = [-1,1,2,3,1], target = 2)
    >>> 3
    Explanation: There are 3 pairs of indices that satisfy the conditions in the statement:
    - (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target
    - (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target
    - (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target
    Note that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.

    Example 2:

    >>> countPairs(nums = [-6,2,5,-2,-7,-1,3], target = -2)
    >>> 10
    Explanation: There are 10 pairs of indices that satisfy the conditions in the statement:
    - (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target
    - (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target
    - (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target
    - (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target
    - (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target
    - (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target
    - (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target
    - (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target
    - (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target
    - (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target
    """


Prompt:
def canMakeSubsequence(str1: str, str2: str) -> bool:
    """
    You are given two 0-indexed strings str1 and str2.
    In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.
    Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.
    Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.

    Example 1:

    >>> canMakeSubsequence(str1 = "abc", str2 = "ad")
    >>> true
    Explanation: Select index 2 in str1.
    Increment str1[2] to become 'd'.
    Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
    Example 2:

    >>> canMakeSubsequence(str1 = "zc", str2 = "ad")
    >>> true
    Explanation: Select indices 0 and 1 in str1.
    Increment str1[0] to become 'a'.
    Increment str1[1] to become 'd'.
    Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
    Example 3:

    >>> canMakeSubsequence(str1 = "ab", str2 = "d")
    >>> false
    Explanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.
    Therefore, false is returned.
    """


Prompt:
from typing import List
def minimumOperations(nums: List[int]) -> int:
    """
    You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.

    Example 1:

    >>> minimumOperations(nums = [2,1,3,2,1])
    >>> 3
    Explanation:
    One of the optimal solutions is to remove nums[0], nums[2] and nums[3].

    Example 2:

    >>> minimumOperations(nums = [1,3,2,1,3,3])
    >>> 2
    Explanation:
    One of the optimal solutions is to remove nums[1] and nums[2].

    Example 3:

    >>> minimumOperations(nums = [2,2,2,2,3,3])
    >>> 0
    Explanation:
    nums is already non-decreasing.
    """


Prompt:
def numberOfBeautifulIntegers(low: int, high: int, k: int) -> int:
    """
    You are given positive integers low, high, and k.
    A number is beautiful if it meets both of the following conditions:

    The count of even digits in the number is equal to the count of odd digits.
    The number is divisible by k.

    Return the number of beautiful integers in the range [low, high].

    Example 1:

    >>> numberOfBeautifulIntegers(low = 10, high = 20, k = 3)
    >>> 2
    Explanation: There are 2 beautiful integers in the given range: [12,18].
    - 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
    - 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
    Additionally we can see that:
    - 16 is not beautiful because it is not divisible by k = 3.
    - 15 is not beautiful because it does not contain equal counts even and odd digits.
    It can be shown that there are only 2 beautiful integers in the given range.

    Example 2:

    >>> numberOfBeautifulIntegers(low = 1, high = 10, k = 1)
    >>> 1
    Explanation: There is 1 beautiful integer in the given range: [10].
    - 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.
    It can be shown that there is only 1 beautiful integer in the given range.

    Example 3:

    >>> numberOfBeautifulIntegers(low = 5, high = 5, k = 2)
    >>> 0
    Explanation: There are 0 beautiful integers in the given range.
    - 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.
    """


Prompt:
from typing import List
def isAcronym(words: List[str], s: str) -> bool:
    """
    Given an array of strings words and a string s, determine if s is an acronym of words.
    The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be formed from ["apple", "banana"], but it can't be formed from ["bear", "aardvark"].
    Return true if s is an acronym of words, and false otherwise.

    Example 1:

    >>> isAcronym(words = ["alice","bob","charlie"], s = "abc")
    >>> true
    Explanation: The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym.

    Example 2:

    >>> isAcronym(words = ["an","apple"], s = "a")
    >>> false
    Explanation: The first character in the words "an" and "apple" are 'a' and 'a', respectively.
    The acronym formed by concatenating these characters is "aa".
    Hence, s = "a" is not the acronym.

    Example 3:

    >>> isAcronym(words = ["never","gonna","give","up","on","you"], s = "ngguoy")
    >>> true
    Explanation: By concatenating the first character of the words in the array, we get the string "ngguoy".
    Hence, s = "ngguoy" is the acronym.
    """


Prompt:
def minimumSum(n: int, k: int) -> int:
    """
    You are given two integers, n and k.
    An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.
    Return the minimum possible sum of a k-avoiding array of length n.

    Example 1:

    >>> minimumSum(n = 5, k = 4)
    >>> 18
    Explanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
    It can be proven that there is no k-avoiding array with a sum less than 18.

    Example 2:

    >>> minimumSum(n = 2, k = 6)
    >>> 3
    Explanation: We can construct the array [1,2], which has a sum of 3.
    It can be proven that there is no k-avoiding array with a sum less than 3.
    """


Prompt:
from typing import List
def maximizeTheProfit(n: int, offers: List[List[int]]) -> int:
    """
    You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.
    Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy all the houses from starti to endi for goldi amount of gold.
    As a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.
    Return the maximum amount of gold you can earn.
    Note that different buyers can't buy the same house, and some houses may remain unsold.

    Example 1:

    >>> maximizeTheProfit(n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]])
    >>> 3
    Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
    We sell houses in the range [0,0] to 1st buyer for 1 gold and houses in the range [1,3] to 3rd buyer for 2 golds.
    It can be proven that 3 is the maximum amount of gold we can achieve.

    Example 2:

    >>> maximizeTheProfit(n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]])
    >>> 10
    Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
    We sell houses in the range [0,2] to 2nd buyer for 10 golds.
    It can be proven that 10 is the maximum amount of gold we can achieve.
    """


Prompt:
from typing import List
def longestEqualSubarray(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.
    A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
    Return the length of the longest possible equal subarray after deleting at most k elements from nums.
    A subarray is a contiguous, possibly empty sequence of elements within an array.

    Example 1:

    >>> longestEqualSubarray(nums = [1,3,2,3,1,3], k = 3)
    >>> 3
    Explanation: It's optimal to delete the elements at index 2 and index 4.
    After deleting them, nums becomes equal to [1, 3, 3, 3].
    The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.
    It can be proven that no longer equal subarrays can be created.

    Example 2:

    >>> longestEqualSubarray(nums = [1,1,2,2,1,1], k = 2)
    >>> 4
    Explanation: It's optimal to delete the elements at index 2 and index 3.
    After deleting them, nums becomes equal to [1, 1, 1, 1].
    The array itself is an equal subarray, so the answer is 4.
    It can be proven that no longer equal subarrays can be created.
    """


Prompt:
from typing import List
def maximumLengthOfRanges(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array nums of distinct integers.
    Let us define a 0-indexed array ans of the same length as nums in the following way:

    ans[i] is the maximum length of a subarray nums[l..r], such that the maximum element in that subarray is equal to nums[i].

    Return the array ans.
    Note that a subarray is a contiguous part of the array.

    Example 1:

    >>> maximumLengthOfRanges(nums = [1,5,4,3,6])
    >>> [1,4,2,1,5]
    Explanation: For nums[0] the longest subarray in which 1 is the maximum is nums[0..0] so ans[0] = 1.
    For nums[1] the longest subarray in which 5 is the maximum is nums[0..3] so ans[1] = 4.
    For nums[2] the longest subarray in which 4 is the maximum is nums[2..3] so ans[2] = 2.
    For nums[3] the longest subarray in which 3 is the maximum is nums[3..3] so ans[3] = 1.
    For nums[4] the longest subarray in which 6 is the maximum is nums[0..4] so ans[4] = 5.

    Example 2:

    >>> maximumLengthOfRanges(nums = [1,2,3,4,5])
    >>> [1,2,3,4,5]
    Explanation: For nums[i] the longest subarray in which it's the maximum is nums[0..i] so ans[i] = i + 1.
    """


Prompt:
def furthestDistanceFromOrigin(moves: str) -> int:
    """
    You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.
    In the ith move, you can choose one of the following directions:

    move to the left if moves[i] = 'L' or moves[i] = '_'
    move to the right if moves[i] = 'R' or moves[i] = '_'

    Return the distance from the origin of the furthest point you can get to after n moves.

    Example 1:

    >>> furthestDistanceFromOrigin(moves = "L_RL__R")
    >>> 3
    Explanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".

    Example 2:

    >>> furthestDistanceFromOrigin(moves = "_R__LL_")
    >>> 5
    Explanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".

    Example 3:

    >>> furthestDistanceFromOrigin(moves = "_______")
    >>> 7
    Explanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".
    """


Prompt:
def minimumPossibleSum(n: int, target: int) -> int:
    """
    You are given positive integers n and target.
    An array nums is beautiful if it meets the following conditions:

    nums.length == n.
    nums consists of pairwise distinct positive integers.
    There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.

    Return the minimum possible sum that a beautiful array could have modulo 109 + 7.

    Example 1:

    >>> minimumPossibleSum(n = 2, target = 3)
    >>> 4
    Explanation: We can see that nums = [1,3] is beautiful.
    - The array nums has length n = 2.
    - The array nums consists of pairwise distinct positive integers.
    - There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
    It can be proven that 4 is the minimum possible sum that a beautiful array could have.

    Example 2:

    >>> minimumPossibleSum(n = 3, target = 3)
    >>> 8
    Explanation: We can see that nums = [1,3,4] is beautiful.
    - The array nums has length n = 3.
    - The array nums consists of pairwise distinct positive integers.
    - There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
    It can be proven that 8 is the minimum possible sum that a beautiful array could have.

    Example 3:

    >>> minimumPossibleSum(n = 1, target = 1)
    >>> 1
    Explanation: We can see, that nums = [1] is beautiful.
    """


Prompt:
from typing import List
def minOperations(nums: List[int], target: int) -> int:
    """
    You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.
    In one operation, you must apply the following changes to the array:

    Choose any element of the array nums[i] such that nums[i] > 1.
    Remove nums[i] from the array.
    Add two occurrences of nums[i] / 2 to the end of nums.

    Return the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> minOperations(nums = [1,2,8], target = 7)
    >>> 1
    Explanation: In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].
    At this stage, nums contains the subsequence [1,2,4] which sums up to 7.
    It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.

    Example 2:

    >>> minOperations(nums = [1,32,1,2], target = 12)
    >>> 2
    Explanation: In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].
    In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]
    At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.
    It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.
    Example 3:

    >>> minOperations(nums = [1,32,1], target = 35)
    >>> -1
    Explanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35.
    """


Prompt:
from typing import List
def getMaxFunctionValue(receiver: List[int], k: int) -> int:
    """
    You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.
    You choose the starting player, i. The game proceeds as follows: player i passes the ball to player receiver[i], who then passes it to receiver[receiver[i]], and so on, for k passes in total. The game's score is the sum of the indices of the players who touched the ball, including repetitions, i.e. i + receiver[i] + receiver[receiver[i]] + ... + receiver(k)[i].
    Return the maximum possible score.
    Notes:

    receiver may contain duplicates.
    receiver[i] may be equal to i.

    Example 1:

    >>> getMaxFunctionValue(receiver = [2,0,1], k = 4)
    >>> 6
    Explanation:
    Starting with player i = 2 the initial score is 2:

    Pass
    Sender Index
    Receiver Index
    Score

    1
    2
    1
    3

    2
    1
    0
    3

    3
    0
    2
    5

    4
    2
    1
    6

    Example 2:

    >>> getMaxFunctionValue(receiver = [1,1,1,2,3], k = 3)
    >>> 10
    Explanation:
    Starting with player i = 4 the initial score is 4:

    Pass
    Sender Index
    Receiver Index
    Score

    1
    4
    3
    7

    2
    3
    2
    9

    3
    2
    1
    10
    """


Prompt:
from typing import List
def maximumCoins(heroes: List[int], monsters: List[int], coins: List[int]) -> List[int]:
    """
    There is a battle and n heroes are trying to defeat m monsters. You are given two 1-indexed arrays of positive integers heroes and monsters of length n and m, respectively. heroes[i] is the power of ith hero, and monsters[i] is the power of ith monster.
    The ith hero can defeat the jth monster if monsters[j] <= heroes[i].
    You are also given a 1-indexed array coins of length m consisting of positive integers. coins[i] is the number of coins that each hero earns after defeating the ith monster.
    Return an array ans of length n where ans[i] is the maximum number of coins that the ith hero can collect from this battle.
    Notes

    The health of a hero doesn't get reduced after defeating a monster.
    Multiple heroes can defeat a monster, but each monster can be defeated by a given hero only once.

    Example 1:

    >>> maximumCoins(heroes = [1,4,2], monsters = [1,1,5,2,3], coins = [2,3,4,5,6])
    >>> [5,16,10]
    Explanation: For each hero, we list the index of all the monsters he can defeat:
    1st hero: [1,2] since the power of this hero is 1 and monsters[1], monsters[2] <= 1. So this hero collects coins[1] + coins[2] = 5 coins.
    2nd hero: [1,2,4,5] since the power of this hero is 4 and monsters[1], monsters[2], monsters[4], monsters[5] <= 4. So this hero collects coins[1] + coins[2] + coins[4] + coins[5] = 16 coins.
    3rd hero: [1,2,4] since the power of this hero is 2 and monsters[1], monsters[2], monsters[4] <= 2. So this hero collects coins[1] + coins[2] + coins[4] = 10 coins.
    So the answer would be [5,16,10].
    Example 2:

    >>> maximumCoins(heroes = [5], monsters = [2,3,1,2], coins = [10,6,5,2])
    >>> [23]
    Explanation: This hero can defeat all the monsters since monsters[i] <= 5. So he collects all of the coins: coins[1] + coins[2] + coins[3] + coins[4] = 23, and the answer would be [23].

    Example 3:

    >>> maximumCoins(heroes = [4,4], monsters = [5,7,8], coins = [1,1,1])
    >>> [0,0]
    Explanation: In this example, no hero can defeat a monster. So the answer would be [0,0],
    """


Prompt:
def canBeEqual(s1: str, s2: str) -> bool:
    """
    You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.
    You can apply the following operation on any of the two strings any number of times:

    Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.

    Return true if you can make the strings s1 and s2 equal, and false otherwise.

    Example 1:

    >>> canBeEqual(s1 = "abcd", s2 = "cdab")
    >>> true
    Explanation: We can do the following operations on s1:
    - Choose the indices i = 0, j = 2. The resulting string is s1 = "cbad".
    - Choose the indices i = 1, j = 3. The resulting string is s1 = "cdab" = s2.

    Example 2:

    >>> canBeEqual(s1 = "abcd", s2 = "dacb")
    >>> false
    Explanation: It is not possible to make the two strings equal.
    """


Prompt:
def checkStrings(s1: str, s2: str) -> bool:
    """
    You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.
    You can apply the following operation on any of the two strings any number of times:

    Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.

    Return true if you can make the strings s1 and s2 equal, and false otherwise.

    Example 1:

    >>> checkStrings(s1 = "abcdba", s2 = "cabdab")
    >>> true
    Explanation: We can apply the following operations on s1:
    - Choose the indices i = 0, j = 2. The resulting string is s1 = "cbadba".
    - Choose the indices i = 2, j = 4. The resulting string is s1 = "cbbdaa".
    - Choose the indices i = 1, j = 5. The resulting string is s1 = "cabdab" = s2.

    Example 2:

    >>> checkStrings(s1 = "abe", s2 = "bea")
    >>> false
    Explanation: It is not possible to make the two strings equal.
    """


Prompt:
from typing import List
def maxSum(nums: List[int], m: int, k: int) -> int:
    """
    You are given an integer array nums and two positive integers m and k.
    Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.
    A subarray of nums is almost unique if it contains at least m distinct elements.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> maxSum(nums = [2,6,7,3,1,7], m = 3, k = 4)
    >>> 18
    Explanation: There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.

    Example 2:

    >>> maxSum(nums = [5,9,9,2,4,5,4], m = 1, k = 3)
    >>> 23
    Explanation: There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.

    Example 3:

    >>> maxSum(nums = [1,2,1,2,1,2,1], m = 3, k = 3)
    >>> 0
    Explanation: There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0.
    """


Prompt:
def countKSubsequencesWithMaxBeauty(s: str, k: int) -> int:
    """
    You are given a string s and an integer k.
    A k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.
    Let f(c) denote the number of times the character c occurs in s.
    The beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.
    For example, consider s = "abbbdd" and k = 2:

    f('a') = 1, f('b') = 3, f('d') = 2
    Some k-subsequences of s are:

    "abbbdd" -> "ab" having a beauty of f('a') + f('b') = 4
    "abbbdd" -> "ad" having a beauty of f('a') + f('d') = 3
    "abbbdd" -> "bd" having a beauty of f('b') + f('d') = 5

    Return an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo 109 + 7.
    A subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.
    Notes

    f(c) is the number of times a character c occurs in s, not a k-subsequence.
    Two k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.

    Example 1:

    >>> countKSubsequencesWithMaxBeauty(s = "bcca", k = 2)
    >>> 4
    Explanation: From s we have f('a') = 1, f('b') = 1, and f('c') = 2.
    The k-subsequences of s are:
    bcca having a beauty of f('b') + f('c') = 3
    bcca having a beauty of f('b') + f('c') = 3
    bcca having a beauty of f('b') + f('a') = 2
    bcca having a beauty of f('c') + f('a') = 3
    bcca having a beauty of f('c') + f('a') = 3
    There are 4 k-subsequences that have the maximum beauty, 3.
    Hence, the answer is 4.

    Example 2:

    >>> countKSubsequencesWithMaxBeauty(s = "abbcd", k = 4)
    >>> 2
    Explanation: From s we have f('a') = 1, f('b') = 2, f('c') = 1, and f('d') = 1.
    The k-subsequences of s are:
    abbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5
    abbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5
    There are 2 k-subsequences that have the maximum beauty, 5.
    Hence, the answer is 2.
    """


Prompt:
def countSymmetricIntegers(low: int, high: int) -> int:
    """
    You are given two positive integers low and high.
    An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.
    Return the number of symmetric integers in the range [low, high].

    Example 1:

    >>> countSymmetricIntegers(low = 1, high = 100)
    >>> 9
    Explanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.

    Example 2:

    >>> countSymmetricIntegers(low = 1200, high = 1230)
    >>> 4
    Explanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.
    """


Prompt:
def minimumOperations(num: str) -> int:
    """
    You are given a 0-indexed string num representing a non-negative integer.
    In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.
    Return the minimum number of operations required to make num special.
    An integer x is considered special if it is divisible by 25.

    Example 1:

    >>> minimumOperations(num = "2245047")
    >>> 2
    Explanation: Delete digits num[5] and num[6]. The resulting number is "22450" which is special since it is divisible by 25.
    It can be shown that 2 is the minimum number of operations required to get a special number.
    Example 2:

    >>> minimumOperations(num = "2908305")
    >>> 3
    Explanation: Delete digits num[3], num[4], and num[6]. The resulting number is "2900" which is special since it is divisible by 25.
    It can be shown that 3 is the minimum number of operations required to get a special number.
    Example 3:

    >>> minimumOperations(num = "10")
    >>> 1
    Explanation: Delete digit num[0]. The resulting number is "0" which is special since it is divisible by 25.
    It can be shown that 1 is the minimum number of operations required to get a special number.
    """


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

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

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

    Example 1:

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

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


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

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

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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

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

    Example 2:

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

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


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

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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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

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


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

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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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

    Example 4:

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


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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

    Example 2:

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


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

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

    Example 1:

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

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


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

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

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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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


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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

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

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

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

    Example 1:

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

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

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


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

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

    Example 1:

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

    Example 2:

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


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

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

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

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

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

    Example 1:

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

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

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

    Example 1:

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

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

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

    Return the integer num1 - num2.

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

    Example 2:

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


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

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

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

    Return the array ans.

    Example 1:

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

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

    Example 2:

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

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


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

    Example 1:

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

    Example 2:

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


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

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

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

    Example 1:

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

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

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

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

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

    Example 2:

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


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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

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

    Example 1:

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

    Example 2:

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

    Example 3:

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


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

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

    Return the product matrix of grid.

    Example 1:

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

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