Prompt:
from typing import List
def captureForts(forts: List[int]) -> int:
    """
    You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where:

    -1 represents there is no fort at the ith position.
    0 indicates there is an enemy fort at the ith position.
    1 indicates the fort at the ith the position is under your command.

    Now you have decided to move your army from one of your forts at position i to an empty position j such that:

    0 <= i, j <= n - 1
    The army travels over enemy forts only. Formally, for all k where min(i,j) < k < max(i,j), forts[k] == 0.

    While moving the army, all the enemy forts that come in the way are captured.
    Return the maximum number of enemy forts that can be captured. In case it is impossible to move your army, or you do not have any fort under your command, return 0.

    Example 1:

    >>> captureForts(forts = [1,0,0,-1,0,0,0,0,1])
    >>> 4
    Explanation:
    - Moving the army from position 0 to position 3 captures 2 enemy forts, at 1 and 2.
    - Moving the army from position 8 to position 3 captures 4 enemy forts.
    Since 4 is the maximum number of enemy forts that can be captured, we return 4.

    Example 2:

    >>> captureForts(forts = [0,0,1,-1])
    >>> 0
    Explanation: Since no enemy fort can be captured, 0 is returned.
    """


Prompt:
from typing import List
def topStudents(positive_feedback: List[str], negative_feedback: List[str], report: List[str], student_id: List[int], k: int) -> List[int]:
    """
    You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.
    Initially every student has 0 points. Each positive word in a feedback report increases the points of a student by 3, whereas each negative word decreases the points by 1.
    You are given n feedback reports, represented by a 0-indexed string array report and a 0-indexed integer array student_id, where student_id[i] represents the ID of the student who has received the feedback report report[i]. The ID of each student is unique.
    Given an integer k, return the top k students after ranking them in non-increasing order by their points. In case more than one student has the same points, the one with the lower ID ranks higher.

    Example 1:

    >>> topStudents(positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is studious","the student is smart"], student_id = [1,2], k = 2)
    >>> [1,2]
    Explanation:
    Both the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.

    Example 2:

    >>> topStudents(positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is not studious","the student is smart"], student_id = [1,2], k = 2)
    >>> [2,1]
    Explanation:
    - The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points.
    - The student with ID 2 has 1 positive feedback, so he has 3 points.
    Since student 2 has more points, [2,1] is returned.
    """


Prompt:
def minimizeSet(divisor1: int, divisor2: int, uniqueCnt1: int, uniqueCnt2: int) -> int:
    """
    We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:

    arr1 contains uniqueCnt1 distinct positive integers, each of which is not divisible by divisor1.
    arr2 contains uniqueCnt2 distinct positive integers, each of which is not divisible by divisor2.
    No integer is present in both arr1 and arr2.

    Given divisor1, divisor2, uniqueCnt1, and uniqueCnt2, return the minimum possible maximum integer that can be present in either array.

    Example 1:

    >>> minimizeSet(divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3)
    >>> 4
    Explanation:
    We can distribute the first 4 natural numbers into arr1 and arr2.
    arr1 = [1] and arr2 = [2,3,4].
    We can see that both arrays satisfy all the conditions.
    Since the maximum value is 4, we return it.

    Example 2:

    >>> minimizeSet(divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1)
    >>> 3
    Explanation:
    Here arr1 = [1,2], and arr2 = [3] satisfy all conditions.
    Since the maximum value is 3, we return it.
    Example 3:

    >>> minimizeSet(divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2)
    >>> 15
    Explanation:
    Here, the final possible arrays can be arr1 = [1,3,5,7,9,11,13,15], and arr2 = [2,6].
    It can be shown that it is not possible to obtain a lower maximum satisfying all conditions.
    """


Prompt:
from typing import List
def closestTarget(words: List[str], target: str, startIndex: int) -> int:
    """
    You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning.

    Formally, the next element of words[i] is words[(i + 1) % n] and the previous element of words[i] is words[(i - 1 + n) % n], where n is the length of words.

    Starting from startIndex, you can move to either the next word or the previous word with 1 step at a time.
    Return the shortest distance needed to reach the string target. If the string target does not exist in words, return -1.

    Example 1:

    >>> closestTarget(words = ["hello","i","am","leetcode","hello"], target = "hello", startIndex = 1)
    >>> 1
    Explanation: We start from index 1 and can reach "hello" by
    - moving 3 units to the right to reach index 4.
    - moving 2 units to the left to reach index 4.
    - moving 4 units to the right to reach index 0.
    - moving 1 unit to the left to reach index 0.
    The shortest distance to reach "hello" is 1.

    Example 2:

    >>> closestTarget(words = ["a","b","leetcode"], target = "leetcode", startIndex = 0)
    >>> 1
    Explanation: We start from index 0 and can reach "leetcode" by
    - moving 2 units to the right to reach index 3.
    - moving 1 unit to the left to reach index 3.
    The shortest distance to reach "leetcode" is 1.
    Example 3:

    >>> closestTarget(words = ["i","eat","leetcode"], target = "ate", startIndex = 0)
    >>> -1
    Explanation: Since "ate" does not exist in words, we return -1.
    """


Prompt:
def takeCharacters(s: str, k: int) -> int:
    """
    You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s.
    Return the minimum number of minutes needed for you to take at least k of each character, or return -1 if it is not possible to take k of each character.

    Example 1:

    >>> takeCharacters(s = "aabaaaacaabc", k = 2)
    >>> 8
    Explanation:
    Take three characters from the left of s. You now have two 'a' characters, and one 'b' character.
    Take five characters from the right of s. You now have four 'a' characters, two 'b' characters, and two 'c' characters.
    A total of 3 + 5 = 8 minutes is needed.
    It can be proven that 8 is the minimum number of minutes needed.

    Example 2:

    >>> takeCharacters(s = "a", k = 1)
    >>> -1
    Explanation: It is not possible to take one 'b' or 'c' so return -1.
    """


Prompt:
from typing import List
def maximumTastiness(price: List[int], k: int) -> int:
    """
    You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k.
    The store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket.
    Return the maximum tastiness of a candy basket.

    Example 1:

    >>> maximumTastiness(price = [13,5,1,8,21,2], k = 3)
    >>> 8
    Explanation: Choose the candies with the prices [13,5,21].
    The tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.
    It can be proven that 8 is the maximum tastiness that can be achieved.

    Example 2:

    >>> maximumTastiness(price = [1,3,1], k = 2)
    >>> 2
    Explanation: Choose the candies with the prices [1,3].
    The tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.
    It can be proven that 2 is the maximum tastiness that can be achieved.

    Example 3:

    >>> maximumTastiness(price = [7,7,7,7], k = 2)
    >>> 0
    Explanation: Choosing any two distinct candies from the candies we have will result in a tastiness of 0.
    """


Prompt:
from typing import List
def countPartitions(nums: List[int], k: int) -> int:
    """
    You are given an array nums consisting of positive integers and an integer k.
    Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.
    Return the number of distinct great partitions. Since the answer may be too large, return it modulo 109 + 7.
    Two partitions are considered distinct if some element nums[i] is in different groups in the two partitions.

    Example 1:

    >>> countPartitions(nums = [1,2,3,4], k = 4)
    >>> 6
    Explanation: The great partitions are: ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) and ([4], [1,2,3]).

    Example 2:

    >>> countPartitions(nums = [3,3,3], k = 4)
    >>> 0
    Explanation: There are no great partitions for this array.

    Example 3:

    >>> countPartitions(nums = [6,6], k = 2)
    >>> 2
    Explanation: We can either put nums[0] in the first partition or in the second partition.
    The great partitions will be ([6], [6]) and ([6], [6]).
    """


Prompt:
from typing import List
def kBigIndices(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and a positive integer k.
    We call an index i k-big if the following conditions are satisfied:

    There exist at least k different indices idx1 such that idx1 < i and nums[idx1] < nums[i].
    There exist at least k different indices idx2 such that idx2 > i and nums[idx2] < nums[i].

    Return the number of k-big indices.

    Example 1:

    >>> kBigIndices(nums = [2,3,6,5,2,3], k = 2)
    >>> 2
    Explanation: There are only two 2-big indices in nums:
    - i = 2 --> There are two valid idx1: 0 and 1. There are three valid idx2: 2, 3, and 4.
    - i = 3 --> There are two valid idx1: 0 and 1. There are two valid idx2: 3 and 4.

    Example 2:

    >>> kBigIndices(nums = [1,1,1], k = 3)
    >>> 0
    Explanation: There are no 3-big indices in nums.
    """


Prompt:
def countDigits(num: int) -> int:
    """
    Given an integer num, return the number of digits in num that divide num.
    An integer val divides nums if nums % val == 0.

    Example 1:

    >>> countDigits(num = 7)
    >>> 1
    Explanation: 7 divides itself, hence the answer is 1.

    Example 2:

    >>> countDigits(num = 121)
    >>> 2
    Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.

    Example 3:

    >>> countDigits(num = 1248)
    >>> 4
    Explanation: 1248 is divisible by all of its digits, hence the answer is 4.
    """


Prompt:
from typing import List
def distinctPrimeFactors(nums: List[int]) -> int:
    """
    Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.
    Note that:

    A number greater than 1 is called prime if it is divisible by only 1 and itself.
    An integer val1 is a factor of another integer val2 if val2 / val1 is an integer.

    Example 1:

    >>> distinctPrimeFactors(nums = [2,4,3,7,10,6])
    >>> 4
    Explanation:
    The product of all the elements in nums is: 2 * 4 * 3 * 7 * 10 * 6 = 10080 = 25 * 32 * 5 * 7.
    There are 4 distinct prime factors so we return 4.

    Example 2:

    >>> distinctPrimeFactors(nums = [2,4,8,16])
    >>> 1
    Explanation:
    The product of all the elements in nums is: 2 * 4 * 8 * 16 = 1024 = 210.
    There is 1 distinct prime factor so we return 1.
    """


Prompt:
def minimumPartition(s: str, k: int) -> int:
    """
    You are given a string s consisting of digits from 1 to 9 and an integer k.
    A partition of a string s is called good if:

    Each digit of s is part of exactly one substring.
    The value of each substring is less than or equal to k.

    Return the minimum number of substrings in a good partition of s. If no good partition of s exists, return -1.
    Note that:

    The value of a string is its result when interpreted as an integer. For example, the value of "123" is 123 and the value of "1" is 1.
    A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> minimumPartition(s = "165462", k = 60)
    >>> 4
    Explanation: We can partition the string into substrings "16", "54", "6", and "2". Each substring has a value less than or equal to k = 60.
    It can be shown that we cannot partition the string into less than 4 substrings.

    Example 2:

    >>> minimumPartition(s = "238182", k = 5)
    >>> -1
    Explanation: There is no good partition for this string.
    """


Prompt:
from typing import List
def closestPrimes(left: int, right: int) -> List[int]:
    """
    Given two positive integers left and right, find the two integers num1 and num2 such that:

    left <= num1 < num2 <= right .
    Both num1 and num2 are prime numbers.
    num2 - num1 is the minimum amongst all other pairs satisfying the above conditions.

    Return the positive integer array ans = [num1, num2]. If there are multiple pairs satisfying these conditions, return the one with the smallest num1 value. If no such numbers exist, return [-1, -1].

    Example 1:

    >>> closestPrimes(left = 10, right = 19)
    >>> [11,13]
    Explanation: The prime numbers between 10 and 19 are 11, 13, 17, and 19.
    The closest gap between any pair is 2, which can be achieved by [11,13] or [17,19].
    Since 11 is smaller than 17, we return the first pair.

    Example 2:

    >>> closestPrimes(left = 4, right = 6)
    >>> [-1,-1]
    Explanation: There exists only one prime number in the given range, so the conditions cannot be satisfied.
    """


Prompt:
from typing import Any
def categorizeBox(length: int, width: int, height: int, mass: int) -> str:
    """
    Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.

    The box is "Bulky" if:

    Any of the dimensions of the box is greater or equal to 104.
    Or, the volume of the box is greater or equal to 109.

    If the mass of the box is greater or equal to 100, it is "Heavy".
    If the box is both "Bulky" and "Heavy", then its category is "Both".
    If the box is neither "Bulky" nor "Heavy", then its category is "Neither".
    If the box is "Bulky" but not "Heavy", then its category is "Bulky".
    If the box is "Heavy" but not "Bulky", then its category is "Heavy".

    Note that the volume of the box is the product of its length, width and height.

    Example 1:

    >>> categorizeBox(length = 1000, width = 35, height = 700, mass = 300)
    >>> "Heavy"
    Explanation:
    None of the dimensions of the box is greater or equal to 104.
    Its volume = 24500000 <= 109. So it cannot be categorized as "Bulky".
    However mass >= 100, so the box is "Heavy".
    Since the box is not "Bulky" but "Heavy", we return "Heavy".
    Example 2:

    >>> categorizeBox(length = 200, width = 50, height = 800, mass = 50)
    >>> "Neither"
    Explanation:
    None of the dimensions of the box is greater or equal to 104.
    Its volume = 8 * 106 <= 109. So it cannot be categorized as "Bulky".
    Its mass is also less than 100, so it cannot be categorized as "Heavy" either.
    Since its neither of the two above categories, we return "Neither".
    """


Prompt:
from typing import List
def xorBeauty(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).
    The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.
    Return the xor-beauty of nums.
    Note that:

    val1 | val2 is bitwise OR of val1 and val2.
    val1 & val2 is bitwise AND of val1 and val2.

    Example 1:

    >>> xorBeauty(nums = [1,4])
    >>> 5
    Explanation:
    The triplets and their corresponding effective values are listed below:
    - (0,0,0) with effective value ((1 | 1) & 1) = 1
    - (0,0,1) with effective value ((1 | 1) & 4) = 0
    - (0,1,0) with effective value ((1 | 4) & 1) = 1
    - (0,1,1) with effective value ((1 | 4) & 4) = 4
    - (1,0,0) with effective value ((4 | 1) & 1) = 1
    - (1,0,1) with effective value ((4 | 1) & 4) = 4
    - (1,1,0) with effective value ((4 | 4) & 1) = 0
    - (1,1,1) with effective value ((4 | 4) & 4) = 4
    Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.
    Example 2:

    >>> xorBeauty(nums = [15,45,20,2,34,35,5,44,32,30])
    >>> 34
    Explanation: The xor-beauty of the given array is 34.
    """


Prompt:
from typing import List
def maxPower(stations: List[int], r: int, k: int) -> int:
    """
    You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the ith city.
    Each power station can provide power to every city in a fixed range. In other words, if the range is denoted by r, then a power station at city i can provide power to all cities j such that |i - j| <= r and 0 <= i, j <= n - 1.

    Note that |x| denotes absolute value. For example, |7 - 5| = 2 and |3 - 10| = 7.

    The power of a city is the total number of power stations it is being provided power from.
    The government has sanctioned building k more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.
    Given the two integers r and k, return the maximum possible minimum power of a city, if the additional power stations are built optimally.
    Note that you can build the k power stations in multiple cities.

    Example 1:

    >>> maxPower(stations = [1,2,4,5,0], r = 1, k = 2)
    >>> 5
    Explanation:
    One of the optimal ways is to install both the power stations at city 1.
    So stations will become [1,4,4,5,0].
    - City 0 is provided by 1 + 4 = 5 power stations.
    - City 1 is provided by 1 + 4 + 4 = 9 power stations.
    - City 2 is provided by 4 + 4 + 5 = 13 power stations.
    - City 3 is provided by 5 + 4 = 9 power stations.
    - City 4 is provided by 5 + 0 = 5 power stations.
    So the minimum power of a city is 5.
    Since it is not possible to obtain a larger power, we return 5.

    Example 2:

    >>> maxPower(stations = [4,4,4,4], r = 0, k = 3)
    >>> 4
    Explanation:
    It can be proved that we cannot make the minimum power of a city greater than 4.
    """


Prompt:
from typing import List
def maximumCount(nums: List[int]) -> int:
    """
    Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.

    In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.

    Note that 0 is neither positive nor negative.

    Example 1:

    >>> maximumCount(nums = [-2,-1,-1,1,2,3])
    >>> 3
    Explanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.

    Example 2:

    >>> maximumCount(nums = [-3,-2,-1,0,0,1,2])
    >>> 3
    Explanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.

    Example 3:

    >>> maximumCount(nums = [5,20,66,1314])
    >>> 4
    Explanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4.
    """


Prompt:
from typing import List
def maxKelements(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.
    In one operation:

    choose an index i such that 0 <= i < nums.length,
    increase your score by nums[i], and
    replace nums[i] with ceil(nums[i] / 3).

    Return the maximum possible score you can attain after applying exactly k operations.
    The ceiling function ceil(val) is the least integer greater than or equal to val.

    Example 1:

    >>> maxKelements(nums = [10,10,10,10,10], k = 5)
    >>> 50
    Explanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.

    Example 2:

    >>> maxKelements(nums = [1,10,3,3,3], k = 3)
    >>> 17
    Explanation: You can do the following operations:
    Operation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10.
    Operation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4.
    Operation 3: Select i = 2, so nums becomes [1,2,1,3,3]. Your score increases by 3.
    The final score is 10 + 4 + 3 = 17.
    """


Prompt:
from typing import Any
def isItPossible(word1: str, word2: str) -> bool:
    """
    You are given two 0-indexed strings word1 and word2.
    A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j].
    Return true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one move. Return false otherwise.

    Example 1:

    >>> isItPossible(word1 = "ac", word2 = "b")
    >>> false
    Explanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.

    Example 2:

    >>> isItPossible(word1 = "abcc", word2 = "aab")
    >>> true
    Explanation: We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = "abac" and word2 = "cab", which both have 3 distinct characters.

    Example 3:

    >>> isItPossible(word1 = "abcde", word2 = "fghij")
    >>> true
    Explanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap.
    """


Prompt:
from typing import List
def findCrossingTime(n: int, k: int, time: List[List[int]]) -> int:
    """
    There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [righti, picki, lefti, puti].
    The warehouses are separated by a river and connected by a bridge. Initially, all k workers are waiting on the left side of the bridge. To move the boxes, the ith worker can do the following:

    Cross the bridge to the right side in righti minutes.
    Pick a box from the right warehouse in picki minutes.
    Cross the bridge to the left side in lefti minutes.
    Put the box into the left warehouse in puti minutes.

    The ith worker is less efficient than the jth worker if either condition is met:

    lefti + righti > leftj + rightj
    lefti + righti == leftj + rightj and i > j

    The following rules regulate the movement of the workers through the bridge:

    Only one worker can use the bridge at a time.
    When the bridge is unused prioritize the least efficient worker (who have picked up the box) on the right side to cross. If not, prioritize the least efficient worker on the left side to cross.
    If enough workers have already been dispatched from the left side to pick up all the remaining boxes, no more workers will be sent from the left side.

    Return the elapsed minutes at which the last box reaches the left side of the bridge.

    Example 1:

    >>> findCrossingTime(n = 1, k = 3, time = [[1,1,2,1],[1,1,3,1],[1,1,4,1]])
    >>> 6
    Explanation:

    From 0 to 1 minutes: worker 2 crosses the bridge to the right.
    From 1 to 2 minutes: worker 2 picks up a box from the right warehouse.
    From 2 to 6 minutes: worker 2 crosses the bridge to the left.
    From 6 to 7 minutes: worker 2 puts a box at the left warehouse.
    The whole process ends after 7 minutes. We return 6 because the problem asks for the instance of time at which the last worker reaches the left side of the bridge.

    Example 2:

    >>> findCrossingTime(n = 3, k = 2, time = [[1,5,1,8],[10,10,10,10]])
    >>> 37
    Explanation:

    The last box reaches the left side at 37 seconds. Notice, how we do not put the last boxes down, as that would take more time, and they are already on the left with the workers.
    """


Prompt:
def goodBinaryStrings(minLength: int, maxLength: int, oneGroup: int, zeroGroup: int) -> int:
    """
    You are given four integers minLength, maxLength, oneGroup and zeroGroup.
    A binary string is good if it satisfies the following conditions:

    The length of the string is in the range [minLength, maxLength].
    The size of each block of consecutive 1's is a multiple of oneGroup.

    For example in a binary string 00110111100 sizes of each block of consecutive ones are [2,4].

    The size of each block of consecutive 0's is a multiple of zeroGroup.

    For example, in a binary string 00110111100 sizes of each block of consecutive zeros are [2,1,2].

    Return the number of good binary strings. Since the answer may be too large, return it modulo 109 + 7.
    Note that 0 is considered a multiple of all the numbers.

    Example 1:

    >>> goodBinaryStrings(minLength = 2, maxLength = 3, oneGroup = 1, zeroGroup = 2)
    >>> 5
    Explanation: There are 5 good binary strings in this example: "00", "11", "001", "100", and "111".
    It can be proven that there are only 5 good strings satisfying all conditions.

    Example 2:

    >>> goodBinaryStrings(minLength = 4, maxLength = 4, oneGroup = 4, zeroGroup = 3)
    >>> 1
    Explanation: There is only 1 good binary string in this example: "1111".
    It can be proven that there is only 1 good string satisfying all conditions.
    """


Prompt:
from typing import List
def timeTaken(arrival: List[int], state: List[int]) -> List[int]:
    """
    There are n persons numbered from 0 to n - 1 and a door. Each person can enter or exit through the door once, taking one second.
    You are given a non-decreasing integer array arrival of size n, where arrival[i] is the arrival time of the ith person at the door. You are also given an array state of size n, where state[i] is 0 if person i wants to enter through the door or 1 if they want to exit through the door.
    If two or more persons want to use the door at the same time, they follow the following rules:

    If the door was not used in the previous second, then the person who wants to exit goes first.
    If the door was used in the previous second for entering, the person who wants to enter goes first.
    If the door was used in the previous second for exiting, the person who wants to exit goes first.
    If multiple persons want to go in the same direction, the person with the smallest index goes first.

    Return an array answer of size n where answer[i] is the second at which the ith person crosses the door.
    Note that:

    Only one person can cross the door at each second.
    A person may arrive at the door and wait without entering or exiting to follow the mentioned rules.

    Example 1:

    >>> timeTaken(arrival = [0,1,1,2,4], state = [0,1,0,0,1])
    >>> [0,3,1,2,4]
    Explanation: At each second we have the following:
    - At t = 0: Person 0 is the only one who wants to enter, so they just enter through the door.
    - At t = 1: Person 1 wants to exit, and person 2 wants to enter. Since the door was used the previous second for entering, person 2 enters.
    - At t = 2: Person 1 still wants to exit, and person 3 wants to enter. Since the door was used the previous second for entering, person 3 enters.
    - At t = 3: Person 1 is the only one who wants to exit, so they just exit through the door.
    - At t = 4: Person 4 is the only one who wants to exit, so they just exit through the door.

    Example 2:

    >>> timeTaken(arrival = [0,0,0], state = [1,0,1])
    >>> [0,2,1]
    Explanation: At each second we have the following:
    - At t = 0: Person 1 wants to enter while persons 0 and 2 want to exit. Since the door was not used in the previous second, the persons who want to exit get to go first. Since person 0 has a smaller index, they exit first.
    - At t = 1: Person 1 wants to enter, and person 2 wants to exit. Since the door was used in the previous second for exiting, person 2 exits.
    - At t = 2: Person 1 is the only one who wants to enter, so they just enter through the door.
    """


Prompt:
from typing import List
def differenceOfSum(nums: List[int]) -> int:
    """
    You are given a positive integer array nums.

    The element sum is the sum of all the elements in nums.
    The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.

    Return the absolute difference between the element sum and digit sum of nums.
    Note that the absolute difference between two integers x and y is defined as |x - y|.

    Example 1:

    >>> differenceOfSum(nums = [1,15,6,3])
    >>> 9
    Explanation:
    The element sum of nums is 1 + 15 + 6 + 3 = 25.
    The digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.
    The absolute difference between the element sum and digit sum is |25 - 16| = 9.

    Example 2:

    >>> differenceOfSum(nums = [1,2,3,4])
    >>> 0
    Explanation:
    The element sum of nums is 1 + 2 + 3 + 4 = 10.
    The digit sum of nums is 1 + 2 + 3 + 4 = 10.
    The absolute difference between the element sum and digit sum is |10 - 10| = 0.
    """


Prompt:
from typing import List
def rangeAddQueries(n: int, queries: List[List[int]]) -> List[List[int]]:
    """
    You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.
    You are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, col2i], you should do the following operation:

    Add 1 to every element in the submatrix with the top left corner (row1i, col1i) and the bottom right corner (row2i, col2i). That is, add 1 to mat[x][y] for all row1i <= x <= row2i and col1i <= y <= col2i.

    Return the matrix mat after performing every query.

    Example 1:

    >>> rangeAddQueries(n = 3, queries = [[1,1,2,2],[0,0,1,1]])
    >>> [[1,1,0],[1,2,1],[0,1,1]]
    Explanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.
    - In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).
    - In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).

    Example 2:

    >>> rangeAddQueries(n = 2, queries = [[0,0,1,1]])
    >>> [[1,1],[1,1]]
    Explanation: The diagram above shows the initial matrix and the matrix after the first query.
    - In the first query we add 1 to every element in the matrix.
    """


Prompt:
from typing import List
def countGood(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of good subarrays of nums.
    A subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> countGood(nums = [1,1,1,1,1], k = 10)
    >>> 1
    Explanation: The only good subarray is the array nums itself.

    Example 2:

    >>> countGood(nums = [3,1,4,3,2,2,4], k = 2)
    >>> 4
    Explanation: There are 4 different good subarrays:
    - [3,1,4,3,2,2] that has 2 pairs.
    - [3,1,4,3,2,2,4] that has 3 pairs.
    - [1,4,3,2,2,4] that has 2 pairs.
    - [4,3,2,2,4] that has 2 pairs.
    """


Prompt:
from typing import List
def maxOutput(n: int, edges: List[List[int]], price: List[int]) -> int:
    """
    There exists an undirected and initially unrooted tree with n nodes indexed 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.
    Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.
    The price sum of a given path is the sum of the prices of all nodes lying on that path.
    The tree can be rooted at any node root of your choice. The incurred cost after choosing root is the difference between the maximum and minimum price sum amongst all paths starting at root.
    Return the maximum possible cost amongst all possible root choices.

    Example 1:

    >>> maxOutput(n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5])
    >>> 24
    Explanation: The diagram above denotes the tree after rooting it at node 2. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.
    - The first path contains nodes [2,1,3,4]: the prices are [7,8,6,10], and the sum of the prices is 31.
    - The second path contains the node [2] with the price [7].
    The difference between the maximum and minimum price sum is 24. It can be proved that 24 is the maximum cost.

    Example 2:

    >>> maxOutput(n = 3, edges = [[0,1],[1,2]], price = [1,1,1])
    >>> 2
    Explanation: The diagram above denotes the tree after rooting it at node 0. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.
    - The first path contains nodes [0,1,2]: the prices are [1,1,1], and the sum of the prices is 3.
    - The second path contains node [0] with a price [1].
    The difference between the maximum and minimum price sum is 2. It can be proved that 2 is the maximum cost.
    """


Prompt:
from typing import List
def getCommon(nums1: List[int], nums2: List[int]) -> int:
    """
    Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.
    Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.

    Example 1:

    >>> getCommon(nums1 = [1,2,3], nums2 = [2,4])
    >>> 2
    Explanation: The smallest element common to both arrays is 2, so we return 2.

    Example 2:

    >>> getCommon(nums1 = [1,2,3,6], nums2 = [2,3,4,5])
    >>> 2
    Explanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.
    """


Prompt:
from typing import List
def minOperations(nums1: List[int], nums2: List[int], k: int) -> int:
    """
    You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1:

    Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.

    nums1 is said to be equal to nums2 if for all indices i such that 0 <= i < n, nums1[i] == nums2[i].
    Return the minimum number of operations required to make nums1 equal to nums2. If it is impossible to make them equal, return -1.

    Example 1:

    >>> minOperations(nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3)
    >>> 2
    Explanation: In 2 operations, we can transform nums1 to nums2.
    1st operation: i = 2, j = 0. After applying the operation, nums1 = [1,3,4,4].
    2nd operation: i = 2, j = 3. After applying the operation, nums1 = [1,3,7,1].
    One can prove that it is impossible to make arrays equal in fewer operations.
    Example 2:

    >>> minOperations(nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1)
    >>> -1
    Explanation: It can be proved that it is impossible to make the two arrays equal.
    """


Prompt:
from typing import List
def maxScore(nums1: List[int], nums2: List[int], k: int) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.
    For chosen indices i0, i1, ..., ik - 1, your score is defined as:

    The sum of the selected elements from nums1 multiplied with the minimum of the selected elements from nums2.
    It can defined simply as: (nums1[i0] + nums1[i1] +...+ nums1[ik - 1]) * min(nums2[i0] , nums2[i1], ... ,nums2[ik - 1]).

    Return the maximum possible score.
    A subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1} by deleting some or no elements.

    Example 1:

    >>> maxScore(nums1 = [1,3,3,2], nums2 = [2,1,3,4], k = 3)
    >>> 12
    Explanation:
    The four possible subsequence scores are:
    - We choose the indices 0, 1, and 2 with score = (1+3+3) * min(2,1,3) = 7.
    - We choose the indices 0, 1, and 3 with score = (1+3+2) * min(2,1,4) = 6.
    - We choose the indices 0, 2, and 3 with score = (1+3+2) * min(2,3,4) = 12.
    - We choose the indices 1, 2, and 3 with score = (3+3+2) * min(1,3,4) = 8.
    Therefore, we return the max score, which is 12.

    Example 2:

    >>> maxScore(nums1 = [4,2,3,1,1], nums2 = [7,5,10,9,6], k = 1)
    >>> 30
    Explanation:
    Choosing index 2 is optimal: nums1[2] * nums2[2] = 3 * 10 = 30 is the maximum possible score.
    """


Prompt:
def isReachable(targetX: int, targetY: int) -> bool:
    """
    There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.
    In one step, you can move from point (x, y) to any one of the following points:

    (x, y - x)
    (x - y, y)
    (2 * x, y)
    (x, 2 * y)

    Given two integers targetX and targetY representing the X-coordinate and Y-coordinate of your final position, return true if you can reach the point from (1, 1) using some number of steps, and false otherwise.

    Example 1:

    >>> isReachable(targetX = 6, targetY = 9)
    >>> false
    Explanation: It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.

    Example 2:

    >>> isReachable(targetX = 4, targetY = 7)
    >>> true
    Explanation: You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7).
    """


Prompt:
def alternateDigitSum(n: int) -> int:
    """
    You are given a positive integer n. Each digit of n has a sign according to the following rules:

    The most significant digit is assigned a positive sign.
    Each other digit has an opposite sign to its adjacent digits.

    Return the sum of all digits with their corresponding sign.

    Example 1:

    >>> alternateDigitSum(n = 521)
    >>> 4
    Explanation: (+5) + (-2) + (+1) = 4.

    Example 2:

    >>> alternateDigitSum(n = 111)
    >>> 1
    Explanation: (+1) + (-1) + (+1) = 1.

    Example 3:

    >>> alternateDigitSum(n = 886996)
    >>> 0
    Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.
    """


Prompt:
from typing import List
def sortTheStudents(score: List[List[int]], k: int) -> List[List[int]]:
    """
    There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matrix score contains distinct integers only.
    You are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the kth (0-indexed) exam from the highest to the lowest.
    Return the matrix after sorting it.

    Example 1:

    >>> sortTheStudents(score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2)
    >>> [[7,5,11,2],[10,6,9,1],[4,8,3,15]]
    Explanation: In the above diagram, S denotes the student, while E denotes the exam.
    - The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.
    - The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.
    - The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.

    Example 2:

    >>> sortTheStudents(score = [[3,4],[5,6]], k = 0)
    >>> [[5,6],[3,4]]
    Explanation: In the above diagram, S denotes the student, while E denotes the exam.
    - The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.
    - The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place.
    """


Prompt:
def makeStringsEqual(s: str, target: str) -> bool:
    """
    You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:

    Choose two different indices i and j where 0 <= i, j < n.
    Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).

    For example, if s = "0110", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0] OR s[2] = 0 OR 1 = 1), and s[2] with (s[0] XOR s[2] = 0 XOR 1 = 1), so we will have s = "1110".
    Return true if you can make the string s equal to target, or false otherwise.

    Example 1:

    >>> makeStringsEqual(s = "1010", target = "0110")
    >>> true
    Explanation: We can do the following operations:
    - Choose i = 2 and j = 0. We have now s = "0010".
    - Choose i = 2 and j = 1. We have now s = "0110".
    Since we can make s equal to target, we return true.

    Example 2:

    >>> makeStringsEqual(s = "11", target = "00")
    >>> false
    Explanation: It is not possible to make s equal to target with any number of operations.
    """


Prompt:
from typing import List
def minCost(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    Split the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split.
    Let trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed.

    For example, trimmed([3,1,2,4,3,4]) = [3,4,3,4].

    The importance value of a subarray is k + trimmed(subarray).length.

    For example, if a subarray is [1,2,3,3,3,4,4], then trimmed([1,2,3,3,3,4,4]) = [3,3,3,4,4].The importance value of this subarray will be k + 5.

    Return the minimum possible cost of a split of nums.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> minCost(nums = [1,2,1,2,1,3,3], k = 2)
    >>> 8
    Explanation: We split nums to have two subarrays: [1,2], [1,2,1,3,3].
    The importance value of [1,2] is 2 + (0) = 2.
    The importance value of [1,2,1,3,3] is 2 + (2 + 2) = 6.
    The cost of the split is 2 + 6 = 8. It can be shown that this is the minimum possible cost among all the possible splits.

    Example 2:

    >>> minCost(nums = [1,2,1,2,1], k = 2)
    >>> 6
    Explanation: We split nums to have two subarrays: [1,2], [1,2,1].
    The importance value of [1,2] is 2 + (0) = 2.
    The importance value of [1,2,1] is 2 + (2) = 4.
    The cost of the split is 2 + 4 = 6. It can be shown that this is the minimum possible cost among all the possible splits.

    Example 3:

    >>> minCost(nums = [1,2,1,2,1], k = 5)
    >>> 10
    Explanation: We split nums to have one subarray: [1,2,1,2,1].
    The importance value of [1,2,1,2,1] is 5 + (3 + 2) = 10.
    The cost of the split is 10. It can be shown that this is the minimum possible cost among all the possible splits.
    """


Prompt:
from typing import List
def maxPrice(items: List[List[int]], capacity: int) -> float:
    """
    You are given a 2D integer array items where items[i] = [pricei, weighti] denotes the price and weight of the ith item, respectively.
    You are also given a positive integer capacity.
    Each item can be divided into two items with ratios part1 and part2, where part1 + part2 == 1.

    The weight of the first item is weighti * part1 and the price of the first item is pricei * part1.
    Similarly, the weight of the second item is weighti * part2 and the price of the second item is pricei * part2.

    Return the maximum total price to fill a bag of capacity capacity with given items. If it is impossible to fill a bag return -1. Answers within 10-5 of the actual answer will be considered accepted.

    Example 1:

    >>> maxPrice(items = [[50,1],[10,8]], capacity = 5)
    >>> 55.00000
    Explanation:
    We divide the 2nd item into two parts with part1 = 0.5 and part2 = 0.5.
    The price and weight of the 1st item are 5, 4. And similarly, the price and the weight of the 2nd item are 5, 4.
    The array items after operation becomes [[50,1],[5,4],[5,4]].
    To fill a bag with capacity 5 we take the 1st element with a price of 50 and the 2nd element with a price of 5.
    It can be proved that 55.0 is the maximum total price that we can achieve.

    Example 2:

    >>> maxPrice(items = [[100,30]], capacity = 50)
    >>> -1.00000
    Explanation: It is impossible to fill a bag with the given item.
    """


Prompt:
def distinctIntegers(n: int) -> int:
    """
    You are given a positive integer n, that is initially placed on a board. Every day, for 109 days, you perform the following procedure:

    For each number x present on the board, find all numbers 1 <= i <= n such that x % i == 1.
    Then, place those numbers on the board.

    Return the number of distinct integers present on the board after 109 days have elapsed.
    Note:

    Once a number is placed on the board, it will remain on it until the end.
    % stands for the modulo operation. For example, 14 % 3 is 2.

    Example 1:

    >>> distinctIntegers(n = 5)
    >>> 4
    Explanation: Initially, 5 is present on the board.
    The next day, 2 and 4 will be added since 5 % 2 == 1 and 5 % 4 == 1.
    After that day, 3 will be added to the board because 4 % 3 == 1.
    At the end of a billion days, the distinct numbers on the board will be 2, 3, 4, and 5.

    Example 2:

    >>> distinctIntegers(n = 3)
    >>> 2
    Explanation:
    Since 3 % 2 == 1, 2 will be added to the board.
    After a billion days, the only two distinct numbers on the board are 2 and 3.
    """


Prompt:
from typing import List
def putMarbles(weights: List[int], k: int) -> int:
    """
    You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k.
    Divide the marbles into the k bags according to the following rules:

    No bag is empty.
    If the ith marble and jth marble are in a bag, then all marbles with an index between the ith and jth indices should also be in that same bag.
    If a bag consists of all the marbles with an index from i to j inclusively, then the cost of the bag is weights[i] + weights[j].

    The score after distributing the marbles is the sum of the costs of all the k bags.
    Return the difference between the maximum and minimum scores among marble distributions.

    Example 1:

    >>> putMarbles(weights = [1,3,5,1], k = 2)
    >>> 4
    Explanation:
    The distribution [1],[3,5,1] results in the minimal score of (1+1) + (3+1) = 6.
    The distribution [1,3],[5,1], results in the maximal score of (1+3) + (5+1) = 10.
    Thus, we return their difference 10 - 6 = 4.

    Example 2:

    >>> putMarbles(weights = [1, 3], k = 2)
    >>> 0
    Explanation: The only distribution possible is [1],[3].
    Since both the maximal and minimal score are the same, we return 0.
    """


Prompt:
from typing import List
def countQuadruplets(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.
    A quadruplet (i, j, k, l) is increasing if:

    0 <= i < j < k < l < n, and
    nums[i] < nums[k] < nums[j] < nums[l].

    Example 1:

    >>> countQuadruplets(nums = [1,3,2,4,5])
    >>> 2
    Explanation:
    - When i = 0, j = 1, k = 2, and l = 3, nums[i] < nums[k] < nums[j] < nums[l].
    - When i = 0, j = 1, k = 2, and l = 4, nums[i] < nums[k] < nums[j] < nums[l].
    There are no other quadruplets, so we return 2.

    Example 2:

    >>> countQuadruplets(nums = [1,2,3,4])
    >>> 0
    Explanation: There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0.
    """


Prompt:
from typing import List
def separateDigits(nums: List[int]) -> List[int]:
    """
    Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.
    To separate the digits of an integer is to get all the digits it has in the same order.

    For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].

    Example 1:

    >>> separateDigits(nums = [13,25,83,77])
    >>> [1,3,2,5,8,3,7,7]
    Explanation:
    - The separation of 13 is [1,3].
    - The separation of 25 is [2,5].
    - The separation of 83 is [8,3].
    - The separation of 77 is [7,7].
    answer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.

    Example 2:

    >>> separateDigits(nums = [7,1,3,9])
    >>> [7,1,3,9]
    Explanation: The separation of each integer in nums is itself.
    answer = [7,1,3,9].
    """


Prompt:
from typing import List
def maxCount(banned: List[int], n: int, maxSum: int) -> int:
    """
    You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:

    The chosen integers have to be in the range [1, n].
    Each integer can be chosen at most once.
    The chosen integers should not be in the array banned.
    The sum of the chosen integers should not exceed maxSum.

    Return the maximum number of integers you can choose following the mentioned rules.

    Example 1:

    >>> maxCount(banned = [1,6,5], n = 5, maxSum = 6)
    >>> 2
    Explanation: You can choose the integers 2 and 4.
    2 and 4 are from the range [1, 5], both did not appear in banned, and their sum is 6, which did not exceed maxSum.

    Example 2:

    >>> maxCount(banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1)
    >>> 0
    Explanation: You cannot choose any integer while following the mentioned conditions.

    Example 3:

    >>> maxCount(banned = [11], n = 7, maxSum = 50)
    >>> 7
    Explanation: You can choose the integers 1, 2, 3, 4, 5, 6, and 7.
    They are from the range [1, 7], all did not appear in banned, and their sum is 28, which did not exceed maxSum.
    """


Prompt:
from typing import List
def maximizeWin(prizePositions: List[int], k: int) -> int:
    """
    There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the ith prize. There could be different prizes at the same position on the line. You are also given an integer k.
    You are allowed to select two segments with integer endpoints. The length of each segment must be k. You will collect all prizes whose position falls within at least one of the two selected segments (including the endpoints of the segments). The two selected segments may intersect.

    For example if k = 2, you can choose segments [1, 3] and [2, 4], and you will win any prize i that satisfies 1 <= prizePositions[i] <= 3 or 2 <= prizePositions[i] <= 4.

    Return the maximum number of prizes you can win if you choose the two segments optimally.

    Example 1:

    >>> maximizeWin(prizePositions = [1,1,2,2,3,3,5], k = 2)
    >>> 7
    Explanation: In this example, you can win all 7 prizes by selecting two segments [1, 3] and [3, 5].

    Example 2:

    >>> maximizeWin(prizePositions = [1,2,3,4], k = 0)
    >>> 2
    Explanation: For this example, one choice for the segments is [3, 3] and [4, 4], and you will be able to get 2 prizes.
    """


Prompt:
from typing import List
def isPossibleToCutPath(grid: List[List[int]]) -> bool:
    """
    You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).
    You can flip the value of at most one (possibly none) cell. You cannot flip the cells (0, 0) and (m - 1, n - 1).
    Return true if it is possible to make the matrix disconnect or false otherwise.
    Note that flipping a cell changes its value from 0 to 1 or from 1 to 0.

    Example 1:

    >>> isPossibleToCutPath(grid = [[1,1,1],[1,0,0],[1,1,1]])
    >>> true
    Explanation: We can change the cell shown in the diagram above. There is no path from (0, 0) to (2, 2) in the resulting grid.

    Example 2:

    >>> isPossibleToCutPath(grid = [[1,1,1],[1,0,1],[1,1,1]])
    >>> false
    Explanation: It is not possible to change at most one cell such that there is not path from (0, 0) to (2, 2).
    """


Prompt:
from typing import List
def maxCount(banned: List[int], n: int, maxSum: int) -> int:
    """
    You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:

    The chosen integers have to be in the range [1, n].
    Each integer can be chosen at most once.
    The chosen integers should not be in the array banned.
    The sum of the chosen integers should not exceed maxSum.

    Return the maximum number of integers you can choose following the mentioned rules.

    Example 1:

    >>> maxCount(banned = [1,4,6], n = 6, maxSum = 4)
    >>> 1
    Explanation: You can choose the integer 3.
    3 is in the range [1, 6], and do not appear in banned. The sum of the chosen integers is 3, which does not exceed maxSum.

    Example 2:

    >>> maxCount(banned = [4,3,5,6], n = 7, maxSum = 18)
    >>> 3
    Explanation: You can choose the integers 1, 2, and 7.
    All these integers are in the range [1, 7], all do not appear in banned, and their sum is 10, which does not exceed maxSum.
    """


Prompt:
from typing import List
def pickGifts(gifts: List[int], k: int) -> int:
    """
    You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:

    Choose the pile with the maximum number of gifts.
    If there is more than one pile with the maximum number of gifts, choose any.
    Reduce the number of gifts in the pile to the floor of the square root of the original number of gifts in the pile.

    Return the number of gifts remaining after k seconds.

    Example 1:

    >>> pickGifts(gifts = [25,64,9,4,100], k = 4)
    >>> 29
    Explanation:
    The gifts are taken in the following way:
    - In the first second, the last pile is chosen and 10 gifts are left behind.
    - Then the second pile is chosen and 8 gifts are left behind.
    - After that the first pile is chosen and 5 gifts are left behind.
    - Finally, the last pile is chosen again and 3 gifts are left behind.
    The final remaining gifts are [5,8,9,4,3], so the total number of gifts remaining is 29.

    Example 2:

    >>> pickGifts(gifts = [1,1,1,1], k = 4)
    >>> 4
    Explanation:
    In this case, regardless which pile you choose, you have to leave behind 1 gift in each pile.
    That is, you can't take any pile with you.
    So, the total gifts remaining are 4.
    """


Prompt:
from typing import List
def vowelStrings(words: List[str], queries: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed array of strings words and a 2D array of integers queries.
    Each query queries[i] = [li, ri] asks us to find the number of strings present at the indices ranging from li to ri (both inclusive) of words that start and end with a vowel.
    Return an array ans of size queries.length, where ans[i] is the answer to the ith query.
    Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.

    Example 1:

    >>> vowelStrings(words = ["aba","bcb","ece","aa","e"], queries = [[0,2],[1,4],[1,1]])
    >>> [2,3,0]
    Explanation: The strings starting and ending with a vowel are "aba", "ece", "aa" and "e".
    The answer to the query [0,2] is 2 (strings "aba" and "ece").
    to query [1,4] is 3 (strings "ece", "aa", "e").
    to query [1,1] is 0.
    We return [2,3,0].

    Example 2:

    >>> vowelStrings(words = ["a","e","i"], queries = [[0,2],[0,1],[2,2]])
    >>> [3,2,1]
    Explanation: Every string satisfies the conditions, so we return [3,2,1].
    """


Prompt:
from typing import List
def minCapability(nums: List[int], k: int) -> int:
    """
    There are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the homes, but he refuses to steal from adjacent homes.
    The capability of the robber is the maximum amount of money he steals from one house of all the houses he robbed.
    You are given an integer array nums representing how much money is stashed in each house. More formally, the ith house from the left has nums[i] dollars.
    You are also given an integer k, representing the minimum number of houses the robber will steal from. It is always possible to steal at least k houses.
    Return the minimum capability of the robber out of all the possible ways to steal at least k houses.

    Example 1:

    >>> minCapability(nums = [2,3,5,9], k = 2)
    >>> 5
    Explanation:
    There are three ways to rob at least 2 houses:
    - Rob the houses at indices 0 and 2. Capability is max(nums[0], nums[2]) = 5.
    - Rob the houses at indices 0 and 3. Capability is max(nums[0], nums[3]) = 9.
    - Rob the houses at indices 1 and 3. Capability is max(nums[1], nums[3]) = 9.
    Therefore, we return min(5, 9, 9) = 5.

    Example 2:

    >>> minCapability(nums = [2,7,9,3,1], k = 2)
    >>> 2
    Explanation: There are 7 ways to rob the houses. The way which leads to minimum capability is to rob the house at index 0 and 4. Return max(nums[0], nums[4]) = 2.
    """


Prompt:
from typing import List
def minCost(basket1: List[int], basket2: List[int]) -> int:
    """
    You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can use the following operation as many times as you want:

    Chose two indices i and j, and swap the ith fruit of basket1 with the jth fruit of basket2.
    The cost of the swap is min(basket1[i],basket2[j]).

    Two baskets are considered equal if sorting them according to the fruit cost makes them exactly the same baskets.
    Return the minimum cost to make both the baskets equal or -1 if impossible.

    Example 1:

    >>> minCost(basket1 = [4,2,2,2], basket2 = [1,4,1,2])
    >>> 1
    Explanation: Swap index 1 of basket1 with index 0 of basket2, which has cost 1. Now basket1 = [4,1,2,2] and basket2 = [2,4,1,2]. Rearranging both the arrays makes them equal.

    Example 2:

    >>> minCost(basket1 = [2,3,4,1], basket2 = [3,2,5,1])
    >>> -1
    Explanation: It can be shown that it is impossible to make both the baskets equal.
    """


Prompt:
from typing import List
def findTheArrayConcVal(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    The concatenation of two numbers is the number formed by concatenating their numerals.

    For example, the concatenation of 15, 49 is 1549.

    The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:

    If nums has a size greater than one, add the value of the concatenation of the first and the last element to the concatenation value of nums, and remove those two elements from nums. For example, if the nums was [1, 2, 4, 5, 6], add 16 to the concatenation value.
    If only one element exists in nums, add its value to the concatenation value of nums, then remove it.

    Return the concatenation value of nums.

    Example 1:

    >>> findTheArrayConcVal(nums = [7,52,2,4])
    >>> 596
    Explanation: Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.
     - In the first operation:
    We pick the first element, 7, and the last element, 4.
    Their concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.
    Then we delete them from nums, so nums becomes equal to [52,2].
     - In the second operation:
    We pick the first element, 52, and the last element, 2.
    Their concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.
    Then we delete them from the nums, so nums becomes empty.
    Since the concatenation value is 596 so the answer is 596.

    Example 2:

    >>> findTheArrayConcVal(nums = [5,14,13,8,12])
    >>> 673
    Explanation: Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.
     - In the first operation:
    We pick the first element, 5, and the last element, 12.
    Their concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.
    Then we delete them from the nums, so nums becomes equal to [14,13,8].
     - In the second operation:
    We pick the first element, 14, and the last element, 8.
    Their concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.
    Then we delete them from the nums, so nums becomes equal to [13].
     - In the third operation:
    nums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.
    Then we delete it from nums, so nums become empty.
    Since the concatenation value is 673 so the answer is 673.
    """


Prompt:
from typing import List
def countFairPairs(nums: List[int], lower: int, upper: int) -> int:
    """
    Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.
    A pair (i, j) is fair if:

    0 <= i < j < n, and
    lower <= nums[i] + nums[j] <= upper

    Example 1:

    >>> countFairPairs(nums = [0,1,7,4,4,5], lower = 3, upper = 6)
    >>> 6
    Explanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).

    Example 2:

    >>> countFairPairs(nums = [1,7,9,2,5], lower = 11, upper = 11)
    >>> 1
    Explanation: There is a single fair pair: (2,3).
    """


Prompt:
from typing import List
def substringXorQueries(s: str, queries: List[List[int]]) -> List[List[int]]:
    """
    You are given a binary string s, and a 2D integer array queries where queries[i] = [firsti, secondi].
    For the ith query, find the shortest substring of s whose decimal value, val, yields secondi when bitwise XORed with firsti. In other words, val ^ firsti == secondi.
    The answer to the ith query is the endpoints (0-indexed) of the substring [lefti, righti] or [-1, -1] if no such substring exists. If there are multiple answers, choose the one with the minimum lefti.
    Return an array ans where ans[i] = [lefti, righti] is the answer to the ith query.
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    >>> substringXorQueries(s = "101101", queries = [[0,5],[1,2]])
    >>> [[0,2],[2,3]]
    Explanation: For the first query the substring in range [0,2] is "101" which has a decimal value of 5, and 5 ^ 0 = 5, hence the answer to the first query is [0,2]. In the second query, the substring in range [2,3] is "11", and has a decimal value of 3, and 3 ^ 1 = 2. So, [2,3] is returned for the second query.

    Example 2:

    >>> substringXorQueries(s = "0101", queries = [[12,8]])
    >>> [[-1,-1]]
    Explanation: In this example there is no substring that answers the query, hence [-1,-1] is returned.

    Example 3:

    >>> substringXorQueries(s = "1", queries = [[4,5]])
    >>> [[0,0]]
    Explanation: For this example, the substring in range [0,0] has a decimal value of 1, and 1 ^ 4 = 5. So, the answer is [0,0].
    """


Prompt:
def minimumScore(s: str, t: str) -> int:
    """
    You are given two strings s and t.
    You are allowed to remove any number of characters from the string t.
    The score of the string is 0 if no characters are removed from the string t, otherwise:

    Let left be the minimum index among all removed characters.
    Let right be the maximum index among all removed characters.

    Then the score of the string is right - left + 1.
    Return the minimum possible score to make t a subsequence of s.
    A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

    Example 1:

    >>> minimumScore(s = "abacaba", t = "bzaa")
    >>> 1
    Explanation: In this example, we remove the character "z" at index 1 (0-indexed).
    The string t becomes "baa" which is a subsequence of the string "abacaba" and the score is 1 - 1 + 1 = 1.
    It can be proven that 1 is the minimum score that we can achieve.

    Example 2:

    >>> minimumScore(s = "cde", t = "xyz")
    >>> 3
    Explanation: In this example, we remove characters "x", "y" and "z" at indices 0, 1, and 2 (0-indexed).
    The string t becomes "" which is a subsequence of the string "cde" and the score is 2 - 0 + 1 = 3.
    It can be proven that 3 is the minimum score that we can achieve.
    """


Prompt:
def minMaxDifference(num: int) -> int:
    """
    You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.
    Return the difference between the maximum and minimum values Bob can make by remapping exactly one digit in num.
    Notes:

    When Bob remaps a digit d1 to another digit d2, Bob replaces all occurrences of d1 in num with d2.
    Bob can remap a digit to itself, in which case num does not change.
    Bob can remap different digits for obtaining minimum and maximum values respectively.
    The resulting number after remapping can contain leading zeroes.

    Example 1:

    >>> minMaxDifference(num = 11891)
    >>> 99009
    Explanation:
    To achieve the maximum value, Bob can remap the digit 1 to the digit 9 to yield 99899.
    To achieve the minimum value, Bob can remap the digit 1 to the digit 0, yielding 890.
    The difference between these two numbers is 99009.

    Example 2:

    >>> minMaxDifference(num = 90)
    >>> 99
    Explanation:
    The maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0).
    Thus, we return 99.
    """


Prompt:
from typing import List
def minimizeSum(nums: List[int]) -> int:
    """
    You are given an integer array nums.

    The low score of nums is the minimum absolute difference between any two integers.
    The high score of nums is the maximum absolute difference between any two integers.
    The score of nums is the sum of the high and low scores.

    Return the minimum score after changing two elements of nums.

    Example 1:

    >>> minimizeSum(nums = [1,4,7,8,5])
    >>> 3
    Explanation:

    Change nums[0] and nums[1] to be 6 so that nums becomes [6,6,7,8,5].
    The low score is the minimum absolute difference: |6 - 6| = 0.
    The high score is the maximum absolute difference: |8 - 5| = 3.
    The sum of high and low score is 3.

    Example 2:

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

    Change nums[1] and nums[2] to 1 so that nums becomes [1,1,1].
    The sum of maximum absolute difference and minimum absolute difference is 0.
    """


Prompt:
from typing import List
def minImpossibleOR(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    We say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < ... < indexk < nums.length for which nums[index1] | nums[index2] | ... | nums[indexk] = x. In other words, an integer is expressible if it can be written as the bitwise OR of some subsequence of nums.
    Return the minimum positive non-zero integer that is not expressible from nums.

    Example 1:

    >>> minImpossibleOR(nums = [2,1])
    >>> 4
    Explanation: 1 and 2 are already present in the array. We know that 3 is expressible, since nums[0] | nums[1] = 2 | 1 = 3. Since 4 is not expressible, we return 4.

    Example 2:

    >>> minImpossibleOR(nums = [5,3,2])
    >>> 1
    Explanation: We can show that 1 is the smallest number that is not expressible.
    """


Prompt:
from typing import List
def handleQuery(nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:

    For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nums1 from index l to index r. Both l and r are 0-indexed.
    For a query of type 2, queries[i] = [2, p, 0]. For every index 0 <= i < n, set nums2[i] = nums2[i] + nums1[i] * p.
    For a query of type 3, queries[i] = [3, 0, 0]. Find the sum of the elements in nums2.

    Return an array containing all the answers to the third type queries.

    Example 1:

    >>> handleQuery(nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]])
    >>> [3]
    Explanation: After the first query nums1 becomes [1,1,1]. After the second query, nums2 becomes [1,1,1], so the answer to the third query is 3. Thus, [3] is returned.

    Example 2:

    >>> handleQuery(nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]])
    >>> [5]
    Explanation: After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned.
    """


Prompt:
from typing import List
def mergeArrays(nums1: List[List[int]], nums2: List[List[int]]) -> List[List[int]]:
    """
    You are given two 2D integer arrays nums1 and nums2.

    nums1[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.
    nums2[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.

    Each array contains unique ids and is sorted in ascending order by id.
    Merge the two arrays into one array that is sorted in ascending order by id, respecting the following conditions:

    Only ids that appear in at least one of the two arrays should be included in the resulting array.
    Each id should be included only once and its value should be the sum of the values of this id in the two arrays. If the id does not exist in one of the two arrays, then assume its value in that array to be 0.

    Return the resulting array. The returned array must be sorted in ascending order by id.

    Example 1:

    >>> mergeArrays(nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]])
    >>> [[1,6],[2,3],[3,2],[4,6]]
    Explanation: The resulting array contains the following:
    - id = 1, the value of this id is 2 + 4 = 6.
    - id = 2, the value of this id is 3.
    - id = 3, the value of this id is 2.
    - id = 4, the value of this id is 5 + 1 = 6.

    Example 2:

    >>> mergeArrays(nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]])
    >>> [[1,3],[2,4],[3,6],[4,3],[5,5]]
    Explanation: There are no common ids, so we just include each id with its value in the resulting list.
    """


Prompt:
def minOperations(n: int) -> int:
    """
    You are given a positive integer n, you can do the following operation any number of times:

    Add or subtract a power of 2 from n.

    Return the minimum number of operations to make n equal to 0.
    A number x is power of 2 if x == 2i where i >= 0.

    Example 1:

    >>> minOperations(n = 39)
    >>> 3
    Explanation: We can do the following operations:
    - Add 20 = 1 to n, so now n = 40.
    - Subtract 23 = 8 from n, so now n = 32.
    - Subtract 25 = 32 from n, so now n = 0.
    It can be shown that 3 is the minimum number of operations we need to make n equal to 0.

    Example 2:

    >>> minOperations(n = 54)
    >>> 3
    Explanation: We can do the following operations:
    - Add 21 = 2 to n, so now n = 56.
    - Add 23 = 8 to n, so now n = 64.
    - Subtract 26 = 64 from n, so now n = 0.
    So the minimum number of operations is 3.
    """


Prompt:
from typing import List
def squareFreeSubsets(nums: List[int]) -> int:
    """
    You are given a positive integer 0-indexed array nums.
    A subset of the array nums is square-free if the product of its elements is a square-free integer.
    A square-free integer is an integer that is divisible by no square number other than 1.
    Return the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 109 + 7.
    A non-empty subset of nums is an array that can be obtained by deleting some (possibly none but not all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

    Example 1:

    >>> squareFreeSubsets(nums = [3,4,4,5])
    >>> 3
    Explanation: There are 3 square-free subsets in this example:
    - The subset consisting of the 0th element [3]. The product of its elements is 3, which is a square-free integer.
    - The subset consisting of the 3rd element [5]. The product of its elements is 5, which is a square-free integer.
    - The subset consisting of 0th and 3rd elements [3,5]. The product of its elements is 15, which is a square-free integer.
    It can be proven that there are no more than 3 square-free subsets in the given array.
    Example 2:

    >>> squareFreeSubsets(nums = [1])
    >>> 1
    Explanation: There is 1 square-free subset in this example:
    - The subset consisting of the 0th element [1]. The product of its elements is 1, which is a square-free integer.
    It can be proven that there is no more than 1 square-free subset in the given array.
    """


Prompt:
from typing import List
def findTheString(lcp: List[List[int]]) -> str:
    """
    We define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that:

    lcp[i][j] is equal to the length of the longest common prefix between the substrings word[i,n-1] and word[j,n-1].

    Given an n x n matrix lcp, return the alphabetically smallest string word that corresponds to lcp. If there is no such string, return an empty string.
    A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, "aabd" is lexicographically smaller than "aaca" because the first position they differ is at the third letter, and 'b' comes before 'c'.

    Example 1:

    >>> findTheString(lcp = [[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]])
    >>> "abab"
    Explanation: lcp corresponds to any 4 letter string with two alternating letters. The lexicographically smallest of them is "abab".

    Example 2:

    >>> findTheString(lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]])
    >>> "aaaa"
    Explanation: lcp corresponds to any 4 letter string with a single distinct letter. The lexicographically smallest of them is "aaaa".

    Example 3:

    >>> findTheString(lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]])
    >>> ""
    Explanation: lcp[3][3] cannot be equal to 3 since word[3,...,3] consists of only a single letter; Thus, no answer exists.
    """


Prompt:
from typing import List
def leftRightDifference(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums of size n.
    Define two arrays leftSum and rightSum where:

    leftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.
    rightSum[i] is the sum of elements to the right of the index i in the array nums. If there is no such element, rightSum[i] = 0.

    Return an integer array answer of size n where answer[i] = |leftSum[i] - rightSum[i]|.

    Example 1:

    >>> leftRightDifference(nums = [10,4,8,3])
    >>> [15,1,11,22]
    Explanation: The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0].
    The array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].

    Example 2:

    >>> leftRightDifference(nums = [1])
    >>> [0]
    Explanation: The array leftSum is [0] and the array rightSum is [0].
    The array answer is [|0 - 0|] = [0].
    """


Prompt:
from typing import List
def divisibilityArray(word: str, m: int) -> List[int]:
    """
    You are given a 0-indexed string word of length n consisting of digits, and a positive integer m.
    The divisibility array div of word is an integer array of length n such that:

    div[i] = 1 if the numeric value of word[0,...,i] is divisible by m, or
    div[i] = 0 otherwise.

    Return the divisibility array of word.

    Example 1:

    >>> divisibilityArray(word = "998244353", m = 3)
    >>> [1,1,0,0,0,1,1,0,0]
    Explanation: There are only 4 prefixes that are divisible by 3: "9", "99", "998244", and "9982443".

    Example 2:

    >>> divisibilityArray(word = "1010", m = 10)
    >>> [0,1,0,1]
    Explanation: There are only 2 prefixes that are divisible by 10: "10", and "1010".
    """


Prompt:
from typing import List
def maxNumOfMarkedIndices(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums.
    Initially, all of the indices are unmarked. You are allowed to make this operation any number of times:

    Pick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark i and j.

    Return the maximum possible number of marked indices in nums using the above operation any number of times.

    Example 1:

    >>> maxNumOfMarkedIndices(nums = [3,5,2,4])
    >>> 2
    Explanation: In the first operation: pick i = 2 and j = 1, the operation is allowed because 2 * nums[2] <= nums[1]. Then mark index 2 and 1.
    It can be shown that there's no other valid operation so the answer is 2.

    Example 2:

    >>> maxNumOfMarkedIndices(nums = [9,2,5,4])
    >>> 4
    Explanation: In the first operation: pick i = 3 and j = 0, the operation is allowed because 2 * nums[3] <= nums[0]. Then mark index 3 and 0.
    In the second operation: pick i = 1 and j = 2, the operation is allowed because 2 * nums[1] <= nums[2]. Then mark index 1 and 2.
    Since there is no other operation, the answer is 4.

    Example 3:

    >>> maxNumOfMarkedIndices(nums = [7,6,8])
    >>> 0
    Explanation: There is no valid operation to do, so the answer is 0.
    """


Prompt:
from typing import List
def minimumTime(grid: List[List[int]]) -> int:
    """
    You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which means you can visit the cell (row, col) only when the time you visit it is greater than or equal to grid[row][col].
    You are standing in the top-left cell of the matrix in the 0th second, and you must move to any adjacent cell in the four directions: up, down, left, and right. Each move you make takes 1 second.
    Return the minimum time required in which you can visit the bottom-right cell of the matrix. If you cannot visit the bottom-right cell, then return -1.

    Example 1:

    >>> minimumTime(grid = [[0,1,3,2],[5,1,2,5],[4,3,8,6]])
    >>> 7
    Explanation: One of the paths that we can take is the following:
    - at t = 0, we are on the cell (0,0).
    - at t = 1, we move to the cell (0,1). It is possible because grid[0][1] <= 1.
    - at t = 2, we move to the cell (1,1). It is possible because grid[1][1] <= 2.
    - at t = 3, we move to the cell (1,2). It is possible because grid[1][2] <= 3.
    - at t = 4, we move to the cell (1,1). It is possible because grid[1][1] <= 4.
    - at t = 5, we move to the cell (1,2). It is possible because grid[1][2] <= 5.
    - at t = 6, we move to the cell (1,3). It is possible because grid[1][3] <= 6.
    - at t = 7, we move to the cell (2,3). It is possible because grid[2][3] <= 7.
    The final time is 7. It can be shown that it is the minimum time possible.

    Example 2:

    >>> minimumTime(grid = [[0,2,4],[3,2,1],[1,0,4]])
    >>> -1
    Explanation: There is no path from the top left to the bottom-right cell.
    """


Prompt:
def splitNum(num: int) -> int:
    """
    Given a positive integer num, split it into two non-negative integers num1 and num2 such that:

    The concatenation of num1 and num2 is a permutation of num.

    In other words, the sum of the number of occurrences of each digit in num1 and num2 is equal to the number of occurrences of that digit in num.

    num1 and num2 can contain leading zeros.

    Return the minimum possible sum of num1 and num2.
    Notes:

    It is guaranteed that num does not contain any leading zeros.
    The order of occurrence of the digits in num1 and num2 may differ from the order of occurrence of num.

    Example 1:

    >>> splitNum(num = 4325)
    >>> 59
    Explanation: We can split 4325 so that num1 is 24 and num2 is 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.

    Example 2:

    >>> splitNum(num = 687)
    >>> 75
    Explanation: We can split 687 so that num1 is 68 and num2 is 7, which would give an optimal sum of 75.
    """


Prompt:
def coloredCells(n: int) -> int:
    """
    There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:

    At the first minute, color any arbitrary unit cell blue.
    Every minute thereafter, color blue every uncolored cell that touches a blue cell.

    Below is a pictorial representation of the state of the grid after minutes 1, 2, and 3.

    Return the number of colored cells at the end of n minutes.

    Example 1:

    >>> coloredCells(n = 1)
    >>> 1
    Explanation: After 1 minute, there is only 1 blue cell, so we return 1.

    Example 2:

    >>> coloredCells(n = 2)
    >>> 5
    Explanation: After 2 minutes, there are 4 colored cells on the boundary and 1 in the center, so we return 5.
    """


Prompt:
from typing import List
def rootCount(edges: List[List[int]], guesses: List[List[int]], k: int) -> int:
    """
    Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as 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.
    Alice wants Bob to find the root of the tree. She allows Bob to make several guesses about her tree. In one guess, he does the following:

    Chooses two distinct integers u and v such that there exists an edge [u, v] in the tree.
    He tells Alice that u is the parent of v in the tree.

    Bob's guesses are represented by a 2D integer array guesses where guesses[j] = [uj, vj] indicates Bob guessed uj to be the parent of vj.
    Alice being lazy, does not reply to each of Bob's guesses, but just says that at least k of his guesses are true.
    Given the 2D integer arrays edges, guesses and the integer k, return the number of possible nodes that can be the root of Alice's tree. If there is no such tree, return 0.

    Example 1:

    >>> rootCount(edges = [[0,1],[1,2],[1,3],[4,2]], guesses = [[1,3],[0,1],[1,0],[2,4]], k = 3)
    >>> 3
    Explanation:
    Root = 0, correct guesses = [1,3], [0,1], [2,4]
    Root = 1, correct guesses = [1,3], [1,0], [2,4]
    Root = 2, correct guesses = [1,3], [1,0], [2,4]
    Root = 3, correct guesses = [1,0], [2,4]
    Root = 4, correct guesses = [1,3], [1,0]
    Considering 0, 1, or 2 as root node leads to 3 correct guesses.

    Example 2:

    >>> rootCount(edges = [[0,1],[1,2],[2,3],[3,4]], guesses = [[1,0],[3,4],[2,1],[3,2]], k = 1)
    >>> 5
    Explanation:
    Root = 0, correct guesses = [3,4]
    Root = 1, correct guesses = [1,0], [3,4]
    Root = 2, correct guesses = [1,0], [2,1], [3,4]
    Root = 3, correct guesses = [1,0], [2,1], [3,2], [3,4]
    Root = 4, correct guesses = [1,0], [2,1], [3,2]
    Considering any node as root will give at least 1 correct guess.
    """


Prompt:
def passThePillow(n: int, time: int) -> int:
    """
    There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.

    For example, once the pillow reaches the nth person they pass it to the n - 1th person, then to the n - 2th person and so on.

    Given the two positive integers n and time, return the index of the person holding the pillow after time seconds.

    Example 1:

    >>> passThePillow(n = 4, time = 5)
    >>> 2
    Explanation: People pass the pillow in the following way: 1 -> 2 -> 3 -> 4 -> 3 -> 2.
    After five seconds, the 2nd person is holding the pillow.

    Example 2:

    >>> passThePillow(n = 3, time = 2)
    >>> 3
    Explanation: People pass the pillow in the following way: 1 -> 2 -> 3.
    After two seconds, the 3rd person is holding the pillow.
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def kthLargestLevelSum(root: Optional[TreeNode], k: int) -> int:
"""
You are given the root of a binary tree and a positive integer k.
The level sum in the tree is the sum of the values of the nodes that are on the same level.
Return the kth largest level sum in the tree (not necessarily distinct). If there are fewer than k levels in the tree, return -1.
Note that two nodes are on the same level if they have the same distance from the root.

Example 1:

>>> kthLargestLevelSum(root = [5,8,9,2,1,3,7,4,6], k = 2)
>>> 13
Explanation: The level sums are the following:
- Level 1: 5.
- Level 2: 8 + 9 = 17.
- Level 3: 2 + 1 + 3 + 7 = 13.
- Level 4: 4 + 6 = 10.
The 2nd largest level sum is 13.

Example 2:

>>> kthLargestLevelSum(root = [1,2,null,3], k = 1)
>>> 3
Explanation: The largest level sum is 3.
"""


Prompt:
from typing import List
def findValidSplit(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of length n.
    A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.

    For example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are coprime, while a split at the index i = 1 is not valid because 6 and 3 are not coprime. A split at the index i = 2 is not valid because i == n - 1.

    Return the smallest index i at which the array can be split validly or -1 if there is no such split.
    Two values val1 and val2 are coprime if gcd(val1, val2) == 1 where gcd(val1, val2) is the greatest common divisor of val1 and val2.

    Example 1:

    >>> findValidSplit(nums = [4,7,8,15,3,5])
    >>> 2
    Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.
    The only valid split is at index 2.

    Example 2:

    >>> findValidSplit(nums = [4,7,15,8,3,5])
    >>> -1
    Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.
    There is no valid split.
    """


Prompt:
from typing import List
def waysToReachTarget(target: int, types: List[List[int]]) -> int:
    """
    There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the ith type, and each one of them is worth marksi points.

    Return the number of ways you can earn exactly target points in the exam. Since the answer may be too large, return it modulo 109 + 7.
    Note that questions of the same type are indistinguishable.

    For example, if there are 3 questions of the same type, then solving the 1st and 2nd questions is the same as solving the 1st and 3rd questions, or the 2nd and 3rd questions.

    Example 1:

    >>> waysToReachTarget(target = 6, types = [[6,1],[3,2],[2,3]])
    >>> 7
    Explanation: You can earn 6 points in one of the seven ways:
    - Solve 6 questions of the 0th type: 1 + 1 + 1 + 1 + 1 + 1 = 6
    - Solve 4 questions of the 0th type and 1 question of the 1st type: 1 + 1 + 1 + 1 + 2 = 6
    - Solve 2 questions of the 0th type and 2 questions of the 1st type: 1 + 1 + 2 + 2 = 6
    - Solve 3 questions of the 0th type and 1 question of the 2nd type: 1 + 1 + 1 + 3 = 6
    - Solve 1 question of the 0th type, 1 question of the 1st type and 1 question of the 2nd type: 1 + 2 + 3 = 6
    - Solve 3 questions of the 1st type: 2 + 2 + 2 = 6
    - Solve 2 questions of the 2nd type: 3 + 3 = 6

    Example 2:

    >>> waysToReachTarget(target = 5, types = [[50,1],[50,2],[50,5]])
    >>> 4
    Explanation: You can earn 5 points in one of the four ways:
    - Solve 5 questions of the 0th type: 1 + 1 + 1 + 1 + 1 = 5
    - Solve 3 questions of the 0th type and 1 question of the 1st type: 1 + 1 + 1 + 2 = 5
    - Solve 1 questions of the 0th type and 2 questions of the 1st type: 1 + 2 + 2 = 5
    - Solve 1 question of the 2nd type: 5

    Example 3:

    >>> waysToReachTarget(target = 18, types = [[6,1],[3,2],[2,3]])
    >>> 1
    Explanation: You can only earn 18 points by answering all questions.
    """


Prompt:
from typing import List
def vowelStrings(words: List[str], left: int, right: int) -> int:
    """
    You are given a 0-indexed array of string words and two integers left and right.
    A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.
    Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].

    Example 1:

    >>> vowelStrings(words = ["are","amy","u"], left = 0, right = 2)
    >>> 2
    Explanation:
    - "are" is a vowel string because it starts with 'a' and ends with 'e'.
    - "amy" is not a vowel string because it does not end with a vowel.
    - "u" is a vowel string because it starts with 'u' and ends with 'u'.
    The number of vowel strings in the mentioned range is 2.

    Example 2:

    >>> vowelStrings(words = ["hey","aeo","mu","ooo","artro"], left = 1, right = 4)
    >>> 3
    Explanation:
    - "aeo" is a vowel string because it starts with 'a' and ends with 'o'.
    - "mu" is not a vowel string because it does not start with a vowel.
    - "ooo" is a vowel string because it starts with 'o' and ends with 'o'.
    - "artro" is a vowel string because it starts with 'a' and ends with 'o'.
    The number of vowel strings in the mentioned range is 3.
    """


Prompt:
from typing import Any, List
def maxScore(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).
    Let prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of nums is the number of positive integers in the array prefix.
    Return the maximum score you can achieve.

    Example 1:

    >>> maxScore(nums = [2,-1,0,1,-3,3,-3])
    >>> 6
    Explanation: We can rearrange the array into nums = [2,3,1,-1,-3,0,-3].
    prefix = [2,5,6,5,2,2,-1], so the score is 6.
    It can be shown that 6 is the maximum score we can obtain.

    Example 2:

    >>> maxScore(nums = [-2,-3,0])
    >>> 0
    Explanation: Any rearrangement of the array will result in a score of 0.
    """


Prompt:
from typing import List
def beautifulSubarrays(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. In one operation, you can:

    Choose two different indices i and j such that 0 <= i, j < nums.length.
    Choose a non-negative integer k such that the kth bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.
    Subtract 2k from nums[i] and nums[j].

    A subarray is beautiful if it is possible to make all of its elements equal to 0 after applying the above operation any number of times.
    Return the number of beautiful subarrays in the array nums.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> beautifulSubarrays(nums = [4,3,1,2,4])
    >>> 2
    Explanation: There are 2 beautiful subarrays in nums: [4,3,1,2,4] and [4,3,1,2,4].
    - We can make all elements in the subarray [3,1,2] equal to 0 in the following way:
      - Choose [3, 1, 2] and k = 1. Subtract 21 from both numbers. The subarray becomes [1, 1, 0].
      - Choose [1, 1, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 0, 0].
    - We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:
      - Choose [4, 3, 1, 2, 4] and k = 2. Subtract 22 from both numbers. The subarray becomes [0, 3, 1, 2, 0].
      - Choose [0, 3, 1, 2, 0] and k = 0. Subtract 20 from both numbers. The subarray becomes [0, 2, 0, 2, 0].
      - Choose [0, 2, 0, 2, 0] and k = 1. Subtract 21 from both numbers. The subarray becomes [0, 0, 0, 0, 0].

    Example 2:

    >>> beautifulSubarrays(nums = [1,10,4])
    >>> 0
    Explanation: There are no beautiful subarrays in nums.
    """


Prompt:
from typing import List
def findMinimumTime(tasks: List[List[int]]) -> int:
    """
    There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the ith task should run for a total of durationi seconds (not necessarily continuous) within the inclusive time range [starti, endi].
    You may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.
    Return the minimum time during which the computer should be turned on to complete all tasks.

    Example 1:

    >>> findMinimumTime(tasks = [[2,3,1],[4,5,1],[1,5,2]])
    >>> 2
    Explanation:
    - The first task can be run in the inclusive time range [2, 2].
    - The second task can be run in the inclusive time range [5, 5].
    - The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].
    The computer will be on for a total of 2 seconds.

    Example 2:

    >>> findMinimumTime(tasks = [[1,3,2],[2,5,3],[5,6,2]])
    >>> 4
    Explanation:
    - The first task can be run in the inclusive time range [2, 3].
    - The second task can be run in the inclusive time ranges [2, 3] and [5, 5].
    - The third task can be run in the two inclusive time range [5, 6].
    The computer will be on for a total of 4 seconds.
    """


Prompt:
def distMoney(money: int, children: int) -> int:
    """
    You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.
    You have to distribute the money according to the following rules:

    All money must be distributed.
    Everyone must receive at least 1 dollar.
    Nobody receives 4 dollars.

    Return the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money, return -1.

    Example 1:

    >>> distMoney(money = 20, children = 3)
    >>> 1
    Explanation:
    The maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:
    - 8 dollars to the first child.
    - 9 dollars to the second child.
    - 3 dollars to the third child.
    It can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.

    Example 2:

    >>> distMoney(money = 16, children = 2)
    >>> 2
    Explanation: Each child can be given 8 dollars.
    """


Prompt:
from typing import List
def maximizeGreatness(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.
    We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].
    Return the maximum possible greatness you can achieve after permuting nums.

    Example 1:

    >>> maximizeGreatness(nums = [1,3,5,2,1,3,1])
    >>> 4
    Explanation: One of the optimal rearrangements is perm = [2,5,1,3,3,1,1].
    At indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.
    Example 2:

    >>> maximizeGreatness(nums = [1,2,3,4])
    >>> 3
    Explanation: We can prove the optimal perm is [2,3,4,1].
    At indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3.
    """


Prompt:
from typing import List
def findScore(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Starting with score = 0, apply the following algorithm:

    Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.
    Add the value of the chosen integer to score.
    Mark the chosen element and its two adjacent elements if they exist.
    Repeat until all the array elements are marked.

    Return the score you get after applying the above algorithm.

    Example 1:

    >>> findScore(nums = [2,1,3,4,5,2])
    >>> 7
    Explanation: We mark the elements as follows:
    - 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].
    - 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].
    - 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].
    Our score is 1 + 2 + 4 = 7.

    Example 2:

    >>> findScore(nums = [2,3,5,1,3,2])
    >>> 5
    Explanation: We mark the elements as follows:
    - 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].
    - 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].
    - 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].
    Our score is 1 + 2 + 2 = 5.
    """